Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C8682200C6E for ; Mon, 8 May 2017 11:42:27 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C6EC8160B99; Mon, 8 May 2017 09:42:27 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9AF40160BA5 for ; Mon, 8 May 2017 11:42:26 +0200 (CEST) Received: (qmail 42739 invoked by uid 500); 8 May 2017 09:42:25 -0000 Mailing-List: contact commits-help@tomee.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tomee.apache.org Delivered-To: mailing list commits@tomee.apache.org Received: (qmail 42730 invoked by uid 99); 8 May 2017 09:42:25 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 May 2017 09:42:25 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8CA3EDFBAB; Mon, 8 May 2017 09:42:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rmannibucau@apache.org To: commits@tomee.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: tomee git commit: adding a sample using tomcat-users for ejbd authentication Date: Mon, 8 May 2017 09:42:25 +0000 (UTC) archived-at: Mon, 08 May 2017 09:42:28 -0000 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 Authored: Mon May 8 11:42:14 2017 +0200 Committer: rmannibucau 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 @@ simple-mdb-and-cdi simple-mdb simple-mdb-with-descriptor + simple-remote-tomcatusers simple-rest simple-singleton simple-stateful 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 @@ + + + + + + + 4.0.0 + + org.superbiz + simple-remote-tomcatusers + jar + 1.1.0-SNAPSHOT + OpenEJB :: Examples :: Simple Remote tomcat-users.xml + + + UTF-8 + + + + install + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.7 + 1.7 + + + + + + + + apache-m2-snapshot + Apache Snapshot Repository + https://repository.apache.org/content/groups/snapshots + + + + + + org.apache.tomee + javaee-api + 7.0 + provided + + + + junit + junit + 4.12 + test + + + org.jboss.arquillian.junit + arquillian-junit-container + 1.1.13.Final + test + + + org.apache.tomee + arquillian-tomee-remote + 7.0.4-SNAPSHOT + test + + + org.jboss.shrinkwrap + shrinkwrap-impl-base + + + + + + + + + localhost + file://${basedir}/target/repo/ + + + localhost + file://${basedir}/target/snapshot-repo/ + + + 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 + *

+ * 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.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 + *

+ * 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.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 @@ + + + + + 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 + *

+ * 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.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 @@ + + + + + + + -1 + -1 + -1 + target/test/tomee + target/test/app + src/test/conf + + # 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 + + + + + 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 @@ org.apache.maven.plugins maven-surefire-plugin - 2.19.1 + 2.21-SNAPSHOT org.apache.maven.plugins