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 2018/12/31 17:20:07 UTC

[1/2] tomee git commit: adding README.adoc for simple-remote-tomcatusers.

Repository: tomee
Updated Branches:
  refs/heads/master acd4afb8c -> ec3555af8


adding README.adoc for simple-remote-tomcatusers.

Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/93d0b383
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/93d0b383
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/93d0b383

Branch: refs/heads/master
Commit: 93d0b383ad46cb0daf48fe4f28e43dc6536e6a42
Parents: 85d7dbb
Author: Puneeth PS <pu...@gmail.com>
Authored: Sat Dec 29 00:04:39 2018 +0530
Committer: GitHub <no...@github.com>
Committed: Sat Dec 29 00:04:39 2018 +0530

----------------------------------------------------------------------
 examples/simple-remote-tomcatusers/README.adoc | 106 ++++++++++++++++++++
 1 file changed, 106 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/93d0b383/examples/simple-remote-tomcatusers/README.adoc
----------------------------------------------------------------------
diff --git a/examples/simple-remote-tomcatusers/README.adoc b/examples/simple-remote-tomcatusers/README.adoc
new file mode 100644
index 0000000..2f65df7
--- /dev/null
+++ b/examples/simple-remote-tomcatusers/README.adoc
@@ -0,0 +1,106 @@
+index-group=Unrevised
+type=page
+status=published
+
+= Simple Remote Tomcatusers
+
+This is an example on how to use JNDI with security restrictions in TomEE.
+
+
+== Contract
+
+In our example Contract is an interface annotated with @Remote which indicates that all methods of this interface can be accessed by client code.
+[source,java]
+----
+
+	@Remote
+	public interface Contract {
+	    String hi();
+	}
+----
+== ContractImpl
+
+ContractImpl is a concrete implementation of the Contract interface restricting access to the hi method for users with role test. 
+
+[source,java]
+----
+public class ContractImpl implements Contract {
+    @Override
+    @RolesAllowed("test")
+    public String hi() {
+        return "hi";
+    }
+}
+----
+
+== ContractTest
+
+In this class we test the correctness of our application with Arquillian by creating a war with Contract and ContractImpl classes and deploying to 
+an embedded TomEE server with the war name test.war. In arquillian.xml we specify that arquillian pick tomcat-users.xml from src/test/conf folder.
+In tomcat-users.xml there is a single user with username "tomcat", password="users" and  role "test".
+
+To test we lookup for the ContractImpl and call the hi method using different usernames and passwords.
+ 
+
+[source,java]
+----
+@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();
+    }
+} 
+----
+
+== Run the application:
+
+    mvn install 
+    
+All test cases will pass.    
\ No newline at end of file


[2/2] tomee git commit: Merge branch 'master' of github.com:puneethps/tomee

Posted by jg...@apache.org.
Merge branch 'master' of github.com:puneethps/tomee


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/ec3555af
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/ec3555af
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/ec3555af

Branch: refs/heads/master
Commit: ec3555af8f2d669344bee34f333bfa2246b3e886
Parents: acd4afb 93d0b38
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Mon Dec 31 17:19:47 2018 +0000
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Mon Dec 31 17:19:47 2018 +0000

----------------------------------------------------------------------
 examples/simple-remote-tomcatusers/README.adoc | 106 ++++++++++++++++++++
 1 file changed, 106 insertions(+)
----------------------------------------------------------------------