You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2017/05/08 09:42:25 UTC
tomee git commit: adding a sample using tomcat-users for ejbd
authentication
Repository: tomee
Updated Branches:
refs/heads/master d39434836 -> 5d04bc4ce
adding a sample using tomcat-users for ejbd authentication
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/5d04bc4c
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/5d04bc4c
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/5d04bc4c
Branch: refs/heads/master
Commit: 5d04bc4ce874bdfe71c2344430450c403049f63d
Parents: d394348
Author: rmannibucau <rm...@apache.org>
Authored: Mon May 8 11:42:14 2017 +0200
Committer: rmannibucau <rm...@apache.org>
Committed: Mon May 8 11:42:14 2017 +0200
----------------------------------------------------------------------
examples/pom.xml | 1 +
examples/simple-remote-tomcatusers/pom.xml | 108 +++++++++++++++++++
.../src/main/java/org/superbiz/Contract.java | 24 +++++
.../main/java/org/superbiz/ContractImpl.java | 32 ++++++
.../src/test/conf/tomcat-users.xml | 23 ++++
.../test/java/org/superbiz/ContractTest.java | 92 ++++++++++++++++
.../src/test/resources/arquillian.xml | 42 ++++++++
pom.xml | 2 +-
8 files changed, 323 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/5d04bc4c/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index db89317..7029fb3 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -129,6 +129,7 @@
<module>simple-mdb-and-cdi</module>
<module>simple-mdb</module>
<module>simple-mdb-with-descriptor</module>
+ <module>simple-remote-tomcatusers</module>
<module>simple-rest</module>
<module>simple-singleton</module>
<module>simple-stateful</module>
http://git-wip-us.apache.org/repos/asf/tomee/blob/5d04bc4c/examples/simple-remote-tomcatusers/pom.xml
----------------------------------------------------------------------
diff --git a/examples/simple-remote-tomcatusers/pom.xml b/examples/simple-remote-tomcatusers/pom.xml
new file mode 100644
index 0000000..07f943e
--- /dev/null
+++ b/examples/simple-remote-tomcatusers/pom.xml
@@ -0,0 +1,108 @@
+<?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.
+-->
+
+<!-- $Rev$ $Date$ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.superbiz</groupId>
+ <artifactId>simple-remote-tomcatusers</artifactId>
+ <packaging>jar</packaging>
+ <version>1.1.0-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: Simple Remote tomcat-users.xml</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.5.1</version>
+ <configuration>
+ <source>1.7</source>
+ <target>1.7</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>apache-m2-snapshot</id>
+ <name>Apache Snapshot Repository</name>
+ <url>https://repository.apache.org/content/groups/snapshots</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tomee</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>7.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ <version>1.1.13.Final</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomee</groupId>
+ <artifactId>arquillian-tomee-remote</artifactId>
+ <version>7.0.4-SNAPSHOT</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <!--
+ This section allows you to configure where to publish libraries for sharing.
+ It is not required and may be deleted. For more information see:
+ http://maven.apache.org/plugins/maven-deploy-plugin/
+ -->
+ <distributionManagement>
+ <repository>
+ <id>localhost</id>
+ <url>file://${basedir}/target/repo/</url>
+ </repository>
+ <snapshotRepository>
+ <id>localhost</id>
+ <url>file://${basedir}/target/snapshot-repo/</url>
+ </snapshotRepository>
+ </distributionManagement>
+</project>
http://git-wip-us.apache.org/repos/asf/tomee/blob/5d04bc4c/examples/simple-remote-tomcatusers/src/main/java/org/superbiz/Contract.java
----------------------------------------------------------------------
diff --git a/examples/simple-remote-tomcatusers/src/main/java/org/superbiz/Contract.java b/examples/simple-remote-tomcatusers/src/main/java/org/superbiz/Contract.java
new file mode 100644
index 0000000..0efe2b9
--- /dev/null
+++ b/examples/simple-remote-tomcatusers/src/main/java/org/superbiz/Contract.java
@@ -0,0 +1,24 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.superbiz;
+
+import javax.ejb.Remote;
+
+@Remote
+public interface Contract {
+ String hi();
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/5d04bc4c/examples/simple-remote-tomcatusers/src/main/java/org/superbiz/ContractImpl.java
----------------------------------------------------------------------
diff --git a/examples/simple-remote-tomcatusers/src/main/java/org/superbiz/ContractImpl.java b/examples/simple-remote-tomcatusers/src/main/java/org/superbiz/ContractImpl.java
new file mode 100644
index 0000000..1e50dee
--- /dev/null
+++ b/examples/simple-remote-tomcatusers/src/main/java/org/superbiz/ContractImpl.java
@@ -0,0 +1,32 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.superbiz;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.ConcurrencyManagement;
+import javax.ejb.ConcurrencyManagementType;
+import javax.ejb.Singleton;
+
+@Singleton
+@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
+public class ContractImpl implements Contract {
+ @Override
+ @RolesAllowed("test")
+ public String hi() {
+ return "hi";
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/5d04bc4c/examples/simple-remote-tomcatusers/src/test/conf/tomcat-users.xml
----------------------------------------------------------------------
diff --git a/examples/simple-remote-tomcatusers/src/test/conf/tomcat-users.xml b/examples/simple-remote-tomcatusers/src/test/conf/tomcat-users.xml
new file mode 100644
index 0000000..edd63f7
--- /dev/null
+++ b/examples/simple-remote-tomcatusers/src/test/conf/tomcat-users.xml
@@ -0,0 +1,23 @@
+<?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 xmlns="http://tomcat.apache.org/xml"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
+ version="1.0">
+ <user username="tomcat" password="users" roles="test" />
+</tomcat-users>
http://git-wip-us.apache.org/repos/asf/tomee/blob/5d04bc4c/examples/simple-remote-tomcatusers/src/test/java/org/superbiz/ContractTest.java
----------------------------------------------------------------------
diff --git a/examples/simple-remote-tomcatusers/src/test/java/org/superbiz/ContractTest.java b/examples/simple-remote-tomcatusers/src/test/java/org/superbiz/ContractTest.java
new file mode 100644
index 0000000..3451329
--- /dev/null
+++ b/examples/simple-remote-tomcatusers/src/test/java/org/superbiz/ContractTest.java
@@ -0,0 +1,92 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.superbiz;
+
+import org.apache.openejb.client.RemoteInitialContextFactory;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.EJBAccessException;
+import javax.naming.AuthenticationException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.net.URL;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+@RunWith(Arquillian.class)
+public class ContractTest {
+ @Deployment(testable = false)
+ public static Archive<?> app() {
+ return ShrinkWrap.create(WebArchive.class, "test.war")
+ .addClasses(Contract.class, ContractImpl.class);
+ }
+
+ @ArquillianResource
+ private URL base;
+
+ @Test
+ public void valid() throws NamingException {
+ assertEquals("hi", hi(new Properties() {{
+ setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ setProperty(Context.PROVIDER_URL, String.format("http://localhost:%s/tomee/ejb", base.getPort()));
+ setProperty(Context.SECURITY_PRINCIPAL, "tomcat");
+ setProperty(Context.SECURITY_CREDENTIALS, "users");
+ }}));
+ }
+
+ @Test
+ public void invalid() throws NamingException {
+ try {
+ hi(new Properties() {{
+ setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ setProperty(Context.PROVIDER_URL, String.format("http://localhost:%s/tomee/ejb", base.getPort()));
+ setProperty(Context.SECURITY_PRINCIPAL, "tomcat");
+ setProperty(Context.SECURITY_CREDENTIALS, "wrong");
+ }});
+ fail();
+ } catch (final AuthenticationException ae) {
+ // ok
+ }
+ }
+
+ @Test
+ public void missingCredentials() throws NamingException {
+ try {
+ hi(new Properties() {{
+ setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ setProperty(Context.PROVIDER_URL, String.format("http://localhost:%s/tomee/ejb", base.getPort()));
+ }});
+ fail();
+ } catch (final EJBAccessException eae) {
+ // no-op
+ }
+ }
+
+ private String hi(final Properties clientConfig) throws NamingException {
+ return Contract.class.cast(new InitialContext(clientConfig).lookup("java:global/test/ContractImpl!org.superbiz.Contract")).hi();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/5d04bc4c/examples/simple-remote-tomcatusers/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/examples/simple-remote-tomcatusers/src/test/resources/arquillian.xml b/examples/simple-remote-tomcatusers/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..baf3286
--- /dev/null
+++ b/examples/simple-remote-tomcatusers/src/test/resources/arquillian.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+-->
+<arquillian xmlns="http://jboss.org/schema/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://jboss.org/schema/arquillian
+ http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+ <container qualifier="tomee" default="true">
+ <configuration>
+ <property name="httpPort">-1</property>
+ <property name="stopPort">-1</property>
+ <property name="ajpPort">-1</property>
+ <property name="dir">target/test/tomee</property>
+ <property name="appWorkingDir">target/test/app</property>
+ <property name="conf">src/test/conf</property>
+ <property name="properties">
+ # arquillian adapter automatically activate ejbd for its own need, standalone instances can need customization like:
+ # tomee.remote.support=true
+ # tomee.serialization.class.whitelist =
+ # tomee.serialization.class.blacklist = org.codehaus.groovy.runtime.,org.apache.commons.collections.functors.,org.apache.xalan,java.lang.Process
+ </property>
+ </configuration>
+ </container>
+
+</arquillian>
http://git-wip-us.apache.org/repos/asf/tomee/blob/5d04bc4c/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 1949ee4..4eeccef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -331,7 +331,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.19.1</version>
+ <version>2.21-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>