Repository: tomee Updated Branches: refs/heads/tomee-1.7.x 1d1d7d00a -> c9075f34f
TOMEE-1487 implement an CDI event based realm Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/c9075f34 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/c9075f34 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/c9075f34 Branch: refs/heads/tomee-1.7.x Commit: c9075f34ffe3026545d29e5eb2f4a32903abb574 Parents: 1d1d7d0 Author: Jean-Louis Monteiro <[email protected]> Authored: Thu Jan 8 15:19:41 2015 +0100 Committer: Jean-Louis Monteiro <[email protected]> Committed: Thu Jan 8 15:27:19 2015 +0100 ---------------------------------------------------------------------- .../arquillian-tomee-webprofile-tests/pom.xml | 12 ++ .../tests/realm/CdiEventRealmIntegTest.java | 124 +++++++++++++++ .../tests/realm/CdiEventRealmTest.java | 159 +++++++++++++++++++ .../tomee/catalina/realm/CdiEventRealm.java | 151 ++++++++++++++++++ .../realm/event/BaseAuthenticationEvent.java | 32 ++++ .../realm/event/DigestAuthenticationEvent.java | 74 +++++++++ .../event/FindSecurityConstraintsEvent.java | 64 ++++++++ .../realm/event/GssAuthenticationEvent.java | 38 +++++ .../realm/event/SslAuthenticationEvent.java | 32 ++++ .../event/UserPasswordAuthenticationEvent.java | 37 +++++ 10 files changed, 723 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/c9075f34/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/pom.xml ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/pom.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/pom.xml index c28f952..c47e955 100644 --- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/pom.xml +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/pom.xml @@ -35,6 +35,18 @@ <groupId>org.apache.commons</groupId> <version>${commons-lang3.version}</version> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <version>1.9.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxrs</artifactId> + <version>${cxf.version}</version> + <scope>test</scope> + </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/tomee/blob/c9075f34/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/realm/CdiEventRealmIntegTest.java ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/realm/CdiEventRealmIntegTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/realm/CdiEventRealmIntegTest.java new file mode 100644 index 0000000..136caba --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/realm/CdiEventRealmIntegTest.java @@ -0,0 +1,124 @@ +/** + * 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.realm; + +import jdk.nashorn.internal.ir.annotations.Ignore; +import org.apache.catalina.authenticator.BasicAuthenticator; +import org.apache.catalina.realm.GenericPrincipal; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.tomee.catalina.realm.CdiEventRealm; +import org.apache.tomee.catalina.realm.event.UserPasswordAuthenticationEvent; +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.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.annotation.security.RolesAllowed; +import javax.ejb.Singleton; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; +import java.net.URL; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + +@RunWith(Arquillian.class) +@Ignore +public class CdiEventRealmIntegTest { + @Deployment(testable = false) + public static Archive<?> war() { + return ShrinkWrap.create(WebArchive.class, "realm-test.war") + .addClasses(MultiAuthenticator.class, MyService.class) + .addAsWebResource(EmptyAsset.INSTANCE, "beans.xml") + .addAsManifestResource(new StringAsset("<Context preemptiveAuthentication=\"true\" antiJARLocking=\"true\">\n" + + "<Valve className=\"" + BasicAuthenticator.class.getName() + "\" />\n" + + "<Realm className=\"" + CdiEventRealm.class.getName() + "\" />\n" + + "</Context>"), "context.xml"); + } + + @ArquillianResource + private URL webapp; + + @Test + public void success() { + final String val = WebClient.create(webapp.toExternalForm(), "admin", "secret", null) + .path("/test").get(String.class); + + assertEquals("ok", val); + } + + @Test + public void notAuthorized() { + final Response val = WebClient.create(webapp.toExternalForm(), "user", "secret", null) + .path("/test").get(); + + assertEquals(403, val.getStatus()); + } + + @Test + public void notAuthenticated() { + final Response val = WebClient.create(webapp.toExternalForm(), "admin", "bla bla", null) + .path("/test").get(); + + assertEquals(401, val.getStatus()); + } + + + @Path("/test") + @Singleton + public static class MyService { + @Inject + private MultiAuthenticator authenticator; + + @GET + @RolesAllowed("admin") + public String hello() { + return authenticator.isStacked() ? "ok" : "ko"; + } + } + + @RequestScoped + public static class MultiAuthenticator { + private boolean stacked = false; + + public void authenticate(@Observes final UserPasswordAuthenticationEvent event) { + if (!"secret".equals(event.getCredential())) { + return; // not authenticated + } + event.setPrincipal(new GenericPrincipal(event.getUsername(), "", Arrays.asList(event.getUsername()))); + } + + public void stacked(@Observes final UserPasswordAuthenticationEvent event) { + stacked = true; + } + + public boolean isStacked() { + return stacked; + } + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c9075f34/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/realm/CdiEventRealmTest.java ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/realm/CdiEventRealmTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/realm/CdiEventRealmTest.java new file mode 100644 index 0000000..eaae48d --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/realm/CdiEventRealmTest.java @@ -0,0 +1,159 @@ +/** + * 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.realm; + +import org.apache.catalina.Context; +import org.apache.catalina.connector.Request; +import org.apache.catalina.deploy.SecurityCollection; +import org.apache.catalina.deploy.SecurityConstraint; +import org.apache.catalina.realm.GenericPrincipal; +import org.apache.openejb.jee.WebApp; +import org.apache.openejb.junit.ApplicationComposer; +import org.apache.openejb.testing.Classes; +import org.apache.openejb.testing.Module; +import org.apache.tomee.catalina.realm.CdiEventRealm; +import org.apache.tomee.catalina.realm.event.DigestAuthenticationEvent; +import org.apache.tomee.catalina.realm.event.FindSecurityConstraintsEvent; +import org.apache.tomee.catalina.realm.event.GssAuthenticationEvent; +import org.apache.tomee.catalina.realm.event.SslAuthenticationEvent; +import org.apache.tomee.catalina.realm.event.UserPasswordAuthenticationEvent; +import org.ietf.jgss.GSSContext; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.enterprise.event.Observes; +import java.security.Principal; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(ApplicationComposer.class) +public class CdiEventRealmTest { + + @Module + @Classes(cdi = true, innerClassesAsBean = true) + public WebApp app() { + return new WebApp(); + } + + @Test + public void userPassword() { + final GenericPrincipal gp = getGenericPrincipal(new CdiEventRealm().authenticate("john", "secret")); + assertEquals("john", gp.getName()); + assertEquals("", gp.getPassword()); + assertEquals(1, gp.getRoles().length); + assertEquals("admin", gp.getRoles()[0]); + } + + @Test + public void digest() { + final GenericPrincipal gp = getGenericPrincipal(new CdiEventRealm().authenticate("ryan", "md5", "nonce", "nc", "cnonce", "qop", "realm", "md5a2")); + final String[] actual = gp.getRoles(); + final String[] expected = new String[]{ "ryan", "md5", "nonce", "nc", "cnonce", "qop", "realm", "md5a2" }; + + Arrays.sort(actual); + Arrays.sort(expected); + + assertArrayEquals(actual, expected); + } + + @Test + public void gss() { + final GenericPrincipal gp = getGenericPrincipal(new CdiEventRealm().authenticate(mock(GSSContext.class), false)); + assertEquals("gss", gp.getName()); + assertEquals("", gp.getPassword()); + assertEquals(1, gp.getRoles().length); + assertEquals("dummy", gp.getRoles()[0]); + } + + @Test + public void ssl() { + X509Certificate cert = mock(X509Certificate.class); + GenericPrincipal expected = new GenericPrincipal("john", "doe", Arrays.asList("test")); + when(cert.getSubjectDN()).thenReturn(expected); + final GenericPrincipal gp = getGenericPrincipal(new CdiEventRealm().authenticate(new X509Certificate[]{ cert })); + assertEquals(expected, gp); + assertEquals("john", gp.getName()); + assertEquals("doe", gp.getPassword()); + assertEquals(1, gp.getRoles().length); + assertEquals("test", gp.getRoles()[0]); + } + + @Test + public void find() { + final SecurityConstraint[] securityConstraints = new CdiEventRealm().findSecurityConstraints(mock(Request.class), mock(Context.class)); + assertEquals(1, securityConstraints.length); + final SecurityConstraint c = securityConstraints[0]; + assertEquals("CONFIDENTIAL", c.getUserConstraint()); + assertEquals(2, c.findAuthRoles().length); + assertEquals(1, c.findCollections().length); + SecurityCollection sc = c.findCollections()[0]; + assertTrue(sc.findPattern("/*")); + } + + private GenericPrincipal getGenericPrincipal(Principal principal) { + assertNotNull(principal); + assertTrue(GenericPrincipal.class.isInstance(principal)); + return GenericPrincipal.class.cast(principal); + } + + public static class MultiAuthenticator { + + public void authenticate(@Observes final UserPasswordAuthenticationEvent event) { + assertEquals("john", event.getUsername()); + assertEquals("secret", event.getCredential()); + event.setPrincipal(new GenericPrincipal(event.getUsername(), "", Arrays.asList("admin"))); + } + + public void authenticate(@Observes final DigestAuthenticationEvent event) { + final List<String> roles = new ArrayList<String>(); + roles.add(event.getCnonce()); + roles.add(event.getDigest()); + roles.add(event.getMd5a2()); + roles.add(event.getNc()); + roles.add(event.getNonce()); + roles.add(event.getQop()); + roles.add(event.getRealm()); + roles.add(event.getUsername()); + event.setPrincipal(new GenericPrincipal(event.getUsername(), "", roles)); + } + + public void authenticate(@Observes final GssAuthenticationEvent event) { + assertNotNull(event.getGssContext()); + event.setPrincipal(new GenericPrincipal("gss", "", Arrays.asList("dummy"))); + } + + public void authenticate(@Observes final SslAuthenticationEvent event) { + event.setPrincipal(event.getCerts()[0].getSubjectDN()); + } + + public void findSecurityConstraints(@Observes FindSecurityConstraintsEvent event) { + event.addRoles("admin", "user"); + event.setUserConstraint("CONFIDENTIAL"); + } + + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c9075f34/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/CdiEventRealm.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/CdiEventRealm.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/CdiEventRealm.java new file mode 100644 index 0000000..ab76781 --- /dev/null +++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/CdiEventRealm.java @@ -0,0 +1,151 @@ +/* + * 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.tomee.catalina.realm; + +import org.apache.catalina.Context; +import org.apache.catalina.connector.Request; +import org.apache.catalina.deploy.SecurityCollection; +import org.apache.catalina.deploy.SecurityConstraint; +import org.apache.catalina.realm.RealmBase; +import org.apache.tomee.catalina.realm.event.DigestAuthenticationEvent; +import org.apache.tomee.catalina.realm.event.FindSecurityConstraintsEvent; +import org.apache.tomee.catalina.realm.event.GssAuthenticationEvent; +import org.apache.tomee.catalina.realm.event.SslAuthenticationEvent; +import org.apache.tomee.catalina.realm.event.UserPasswordAuthenticationEvent; +import org.apache.webbeans.config.WebBeansContext; +import org.ietf.jgss.GSSContext; + +import javax.enterprise.inject.spi.BeanManager; +import java.security.Principal; +import java.security.cert.X509Certificate; + +/** + * This simple CDI based realm gives the ability to send events a webapp can react to in order to authenticate the user. + * + * There is one different event per credential types to make it easier to implement. + */ +public class CdiEventRealm extends RealmBase { + + @Override + public Principal authenticate(final String username, final String credentials) { + if (beanManager() == null) { + return null; + } + + final UserPasswordAuthenticationEvent event = new UserPasswordAuthenticationEvent(username, credentials); + beanManager().fireEvent(event); + return event.getPrincipal(); + } + + @Override + public Principal authenticate(final String username, final String digest, final String nonce, final String nc, + final String cnonce, final String qop, final String realm, final String md5a2) { + if (beanManager() == null) { + return null; + } + + final DigestAuthenticationEvent event = new DigestAuthenticationEvent(username, digest, nonce, nc, + cnonce, qop, realm, md5a2); + beanManager().fireEvent(event); + return event.getPrincipal(); + } + + @Override + public Principal authenticate(final GSSContext gssContext, final boolean storeCreds) { + if (beanManager() == null) { + return null; + } + + final GssAuthenticationEvent event = new GssAuthenticationEvent(gssContext, storeCreds); + beanManager().fireEvent(event); + return event.getPrincipal(); + } + + @Override + public Principal authenticate(final X509Certificate[] certs) { + if (beanManager() == null) { + return null; + } + + final SslAuthenticationEvent event = new SslAuthenticationEvent(certs); + beanManager().fireEvent(event); + return event.getPrincipal(); + } + + @Override + public void backgroundProcess() { + // no-op for now + } + + @Override + public SecurityConstraint[] findSecurityConstraints(final Request request, final Context context) { + final SecurityConstraint[] sc = super.findSecurityConstraints(request, context); + + if (beanManager() == null) { + return sc; + } + + final FindSecurityConstraintsEvent event = new FindSecurityConstraintsEvent(request.getRequest(), context.getPath()); + beanManager().fireEvent(event); + + if (!event.getRoles().isEmpty()) { + final SecurityConstraint s = new SecurityConstraint(); + final SecurityCollection collection = new SecurityCollection(); + + collection.addPattern("/*"); // only for the current request + collection.addMethod(request.getMethod()); + s.addCollection(collection); + + if (event.getUserConstraint() != null) { + s.setUserConstraint(event.getUserConstraint()); + } + + for(final String r: event.getRoles()) { + s.addAuthRole(r); + } + + return new SecurityConstraint[] { s }; + } + + return sc; + } + + @Override + protected String getName() { + return "CdiEventRealm"; + } + + @Override + protected String getPassword(final String username) { + // must never happen cause we overridden all authenticate() mthd + throw new UnsupportedOperationException(); + } + + @Override + protected Principal getPrincipal(final String username) { + // must never happen cause we overridden all authenticate() mthd + throw new UnsupportedOperationException(); + } + + private BeanManager beanManager() { + final WebBeansContext webBeansContext = WebBeansContext.currentInstance(); + if (webBeansContext == null) { + return null; // too early to have a cdi bean + } + return webBeansContext.getBeanManagerImpl(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c9075f34/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/BaseAuthenticationEvent.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/BaseAuthenticationEvent.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/BaseAuthenticationEvent.java new file mode 100644 index 0000000..d191b63 --- /dev/null +++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/BaseAuthenticationEvent.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.apache.tomee.catalina.realm.event; + +import java.security.Principal; + +public abstract class BaseAuthenticationEvent { + + private Principal principal; + + public Principal getPrincipal() { + return principal; + } + + public void setPrincipal(Principal principal) { + this.principal = principal; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c9075f34/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/DigestAuthenticationEvent.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/DigestAuthenticationEvent.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/DigestAuthenticationEvent.java new file mode 100644 index 0000000..4a71825 --- /dev/null +++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/DigestAuthenticationEvent.java @@ -0,0 +1,74 @@ +/* + * 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.tomee.catalina.realm.event; + +public class DigestAuthenticationEvent extends BaseAuthenticationEvent { + + private final String username; + private final String digest; + private final String nonce; + private final String nc; + private final String cnonce; + private final String qop; + private final String realm; + private final String md5a2; + + public DigestAuthenticationEvent(final String username, final String digest, final String nonce, final String nc, + final String cnonce, final String qop, final String realm, final String md5a2) { + + this.username = username; + this.digest = digest; + this.nonce = nonce; + this.nc = nc; + this.cnonce = cnonce; + this.qop = qop; + this.realm = realm; + this.md5a2 = md5a2; + } + + public String getUsername() { + return username; + } + + public String getDigest() { + return digest; + } + + public String getNonce() { + return nonce; + } + + public String getNc() { + return nc; + } + + public String getCnonce() { + return cnonce; + } + + public String getQop() { + return qop; + } + + public String getRealm() { + return realm; + } + + public String getMd5a2() { + return md5a2; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c9075f34/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/FindSecurityConstraintsEvent.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/FindSecurityConstraintsEvent.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/FindSecurityConstraintsEvent.java new file mode 100644 index 0000000..c8a482e --- /dev/null +++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/FindSecurityConstraintsEvent.java @@ -0,0 +1,64 @@ +/* + * 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.tomee.catalina.realm.event; + +import javax.servlet.ServletRequest; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class FindSecurityConstraintsEvent { + + private final ServletRequest request; + private final String context; + + private final List<String> roles = new ArrayList<String>(); + private String userConstraint; + + public FindSecurityConstraintsEvent(final ServletRequest request, final String context) { + this.request = request; + this.context = context; + } + + public ServletRequest getRequest() { + return request; + } + + public String getContext() { + return context; + } + + public List<String> getRoles() { + return roles; + } + + public FindSecurityConstraintsEvent addRoles(final String... roles) { + this.roles.addAll(Arrays.asList(roles)); + return this; + } + + public void setUserConstraint(String userConstraint) { + if (this.userConstraint != null && !this.userConstraint.equals(userConstraint)) { + throw new IllegalStateException("User constraint already set to > " + this.userConstraint); + } + this.userConstraint = userConstraint; + } + + public String getUserConstraint() { + return userConstraint; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c9075f34/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/GssAuthenticationEvent.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/GssAuthenticationEvent.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/GssAuthenticationEvent.java new file mode 100644 index 0000000..61d6085 --- /dev/null +++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/GssAuthenticationEvent.java @@ -0,0 +1,38 @@ +/* + * 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.tomee.catalina.realm.event; + +import org.ietf.jgss.GSSContext; + +public class GssAuthenticationEvent extends BaseAuthenticationEvent { + + private final GSSContext gssContext; + private final boolean storeCreds; + + public GssAuthenticationEvent(final GSSContext gssContext, final boolean storeCreds) { + this.gssContext = gssContext; + this.storeCreds = storeCreds; + } + + public GSSContext getGssContext() { + return gssContext; + } + + public boolean isStoreCreds() { + return storeCreds; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c9075f34/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/SslAuthenticationEvent.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/SslAuthenticationEvent.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/SslAuthenticationEvent.java new file mode 100644 index 0000000..f3a9553 --- /dev/null +++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/SslAuthenticationEvent.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.apache.tomee.catalina.realm.event; + +import java.security.cert.X509Certificate; + +public class SslAuthenticationEvent extends BaseAuthenticationEvent { + + private final X509Certificate[] certs; + + public SslAuthenticationEvent(final X509Certificate[] certs) { + this.certs = certs; + } + + public X509Certificate[] getCerts() { + return certs; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c9075f34/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/UserPasswordAuthenticationEvent.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/UserPasswordAuthenticationEvent.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/UserPasswordAuthenticationEvent.java new file mode 100644 index 0000000..e33a0b2 --- /dev/null +++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/realm/event/UserPasswordAuthenticationEvent.java @@ -0,0 +1,37 @@ +/* + * 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.tomee.catalina.realm.event; + +public class UserPasswordAuthenticationEvent extends BaseAuthenticationEvent { + + private final String username; + private final String credential; + + + public UserPasswordAuthenticationEvent(final String username, final String credential) { + this.username = username; + this.credential = credential; + } + + public String getUsername() { + return username; + } + + public String getCredential() { + return credential; + } +}
