You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2016/11/28 23:22:29 UTC
[08/14] tomee git commit: Add test for authorization header usage.
Fix bug where username being used instead of credential
Add test for authorization header usage. Fix bug where username being used instead of credential
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/3d2b2451
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/3d2b2451
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/3d2b2451
Branch: refs/heads/tomee-1.7.x
Commit: 3d2b24512e24c1a8aef6c2763f08a33d73bf446d
Parents: 7b41ae5
Author: Jonathan Gallimore <jg...@Jons-MacBook-Pro.local>
Authored: Mon Nov 7 00:27:45 2016 +0000
Committer: Jonathan Gallimore <jg...@Jons-MacBook-Pro.local>
Committed: Mon Nov 7 00:27:45 2016 +0000
----------------------------------------------------------------------
.../arquillian/tests/security/BusinessBean.java | 48 +++++++++
.../tests/security/BusinessRemote.java | 27 +++++
.../TomEEEjbServletAuthorizationHeaderTest.java | 101 +++++++++++++++++++
.../src/test/resources/arquillian.xml | 6 ++
.../src/test/tomee/conf/tomcat-users.xml | 30 ++++++
.../apache/openejb/client/ServerMetaData.java | 2 +-
6 files changed, 213 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java
new file mode 100644
index 0000000..5a101bf
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.security;
+
+import javax.annotation.Resource;
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.SessionContext;
+import javax.ejb.Singleton;
+import java.security.Principal;
+
+@Singleton
+@Lock(LockType.READ)
+public class BusinessBean implements BusinessRemote {
+
+ @Resource
+ private SessionContext ctx;
+
+ @Override
+ public String echo(final String input) {
+ return input;
+ }
+
+ @Override
+ public String getPrincipal() {
+ Principal callerPrincipal = ctx.getCallerPrincipal();
+ if (callerPrincipal == null) {
+ return "null";
+ }
+
+ return callerPrincipal.getName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java
new file mode 100644
index 0000000..e81f634
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.security;
+
+import javax.ejb.Remote;
+
+@Remote
+public interface BusinessRemote {
+
+ String echo(String input);
+
+ String getPrincipal();
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
new file mode 100644
index 0000000..a42b1c0
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.security;
+
+import org.apache.openejb.arquillian.tests.TestRun;
+import org.apache.openejb.arquillian.tests.TestSetup;
+import org.apache.openejb.client.RemoteInitialContextFactory;
+import org.apache.openejb.server.httpd.ServerServlet;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
+
+
+@RunWith(Arquillian.class)
+@RunAsClient
+public class TomEEEjbServletAuthorizationHeaderTest extends TestSetup {
+
+ public static final String TEST_NAME = TomEEEjbServletAuthorizationHeaderTest.class.getSimpleName();
+
+ @ArquillianResource
+ private URL url;
+
+ @Test
+ public void testAuthenticate() throws Exception {
+ final String ejbUrl = this.url.toExternalForm() + "ejb";
+
+ final Properties p = new Properties();
+ p.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ p.setProperty(Context.PROVIDER_URL, ejbUrl);
+ p.setProperty(Context.SECURITY_PRINCIPAL, "tomee");
+ p.setProperty(Context.SECURITY_CREDENTIALS, "password");
+ final InitialContext context = new InitialContext(p);
+
+ final BusinessRemote bean = (BusinessRemote) context.lookup("global/TomEEEjbServletAuthorizationHeaderTest/BusinessBean!org.apache.openejb.arquillian.tests.security.BusinessRemote");
+ Assert.assertEquals("test", bean.echo("test"));
+ }
+
+ @Deployment(testable = false)
+ public static WebArchive getArchive() {
+ return new TomEEEjbServletAuthorizationHeaderTest().createDeployment(TestRun.class, BusinessBean.class);
+ }
+
+ @Override
+ protected void decorateDescriptor(WebAppDescriptor descriptor) {
+ descriptor
+ .createServlet()
+ .servletName("ServerServlet")
+ .servletClass(ServerServlet.class.getName()).up()
+ .createServletMapping()
+ .servletName("ServerServlet")
+ .urlPattern("/ejb").up()
+ .createSecurityConstraint()
+ .getOrCreateWebResourceCollection()
+ .webResourceName("all")
+ .urlPattern("/*").up()
+ .getOrCreateAuthConstraint()
+ .roleName("tomee-admin")
+ .up().up()
+ .createLoginConfig()
+ .authMethod("BASIC");
+ }
+
+ public static void main(String[] args) throws Exception {
+ final Properties properties = new Properties();
+ properties.setProperty("tomee", "password");
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+ properties.store(os, "");
+
+ System.out.print(new String(os.toByteArray(), StandardCharsets.UTF_8));
+ }
+}
+
+
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
index 8cbddb4..70bb894 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
@@ -33,6 +33,12 @@
openejb.ear.use-as-webcontext-base=true
embedded = true
</property>
+ <property name="users">
+ tomee=password
+ </property>
+ <property name="roles">
+ tomee=tomee-admin
+ </property>
</configuration>
</container>
<container qualifier="tomee-remote">
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/tomee/conf/tomcat-users.xml
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/tomee/conf/tomcat-users.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/tomee/conf/tomcat-users.xml
new file mode 100644
index 0000000..88c6f81
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/tomee/conf/tomcat-users.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+--><tomcat-users>
+ <!--
+ NOTE: By default, no user is included in the "manager-gui" role required
+ to operate the "/manager/html" web application. If you wish to use this app,
+ you must define such a user - the username and password are arbitrary.
+ -->
+ <!--
+ NOTE: The sample user and role entries below are wrapped in a comment
+ and thus are ignored when reading this file. Do not forget to remove
+ <!.. ..> that surrounds them.
+ -->
+ <role rolename="tomee-admin"/>
+ <user username="tomee" password="password" roles="tomee-admin"/>
+</tomcat-users>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
index f913ca4..6f69994 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
@@ -51,7 +51,7 @@ public class ServerMetaData implements Externalizable {
locationList.add(uri);
}
locations = locationList.toArray(new URI[server.locations.length]);
- location = addUserToURI(securityPrincipal, securityPrincipal, server.location);
+ location = addUserToURI(securityPrincipal, securityCredentials, server.location);
this.metaData = server.metaData;
}