diff options
author | Angel Avila | 2015-03-19 21:41:20 +0000 |
---|---|---|
committer | Angel Avila | 2015-03-19 21:41:20 +0000 |
commit | a27232fef83da17dab042d101efcf5f2d5f52859 (patch) | |
tree | 51695070608f78c6c5224c3162552d92ec2a10d4 /plugins/org.eclipse.osee.jaxrs.server | |
parent | e964ad8eaf2706ee3436f6d76c58ec51741eba20 (diff) | |
download | org.eclipse.osee-a27232fef83da17dab042d101efcf5f2d5f52859.tar.gz org.eclipse.osee-a27232fef83da17dab042d101efcf5f2d5f52859.tar.xz org.eclipse.osee-a27232fef83da17dab042d101efcf5f2d5f52859.zip |
feature[ats_ATS179688]: Provide Anonymous Principal through JAX-RS
Change-Id: I7f0fd465e59a723b188641c7443a15c680c1d13f
Signed-off-by: Angel Avila <angel.avila2@boeing.com>
Diffstat (limited to 'plugins/org.eclipse.osee.jaxrs.server')
10 files changed, 108 insertions, 11 deletions
diff --git a/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.anonymous.principal.request.filter.xml b/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.anonymous.principal.request.filter.xml new file mode 100644 index 00000000000..c23ee1debf2 --- /dev/null +++ b/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.anonymous.principal.request.filter.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"> + <implementation class="org.eclipse.osee.jaxrs.server.internal.security.AnonymousPrincipalRequestFilter"/> + <service> + <provide interface="javax.ws.rs.container.ContainerRequestFilter"/> + <provide interface="java.lang.Object"/> + </service> + <reference bind="setJaxRsAuthenticator" cardinality="1..1" interface="org.eclipse.osee.jaxrs.server.security.JaxRsAuthenticator" name="JaxRsAuthenticator" policy="static"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.osee.principal.context.provider.xml b/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.osee.principal.context.provider.xml new file mode 100644 index 00000000000..bc7b554f9ba --- /dev/null +++ b/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.osee.principal.context.provider.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"> + <implementation class="org.eclipse.osee.jaxrs.server.internal.security.OseePrincipalContextProvider"/> + <service> + <provide interface="java.lang.Object"/> + <provide interface="org.apache.cxf.jaxrs.ext.ContextProvider"/> + </service> +</scr:component> diff --git a/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.providers.manager.xml b/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.providers.manager.xml index 6c972d64577..6c54fd05926 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.providers.manager.xml +++ b/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.providers.manager.xml @@ -2,5 +2,5 @@ <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" configuration-policy="optional" deactivate="stop" enabled="true" immediate="true" modified="update"> <implementation class="org.eclipse.osee.jaxrs.server.internal.JaxRsProvidersManager" /> <reference bind="setJaxRsApplicationRegistry" cardinality="1..1" interface="org.eclipse.osee.jaxrs.server.internal.applications.JaxRsApplicationRegistry" name="JaxRsApplicationRegistry" policy="static" unbind="unsetJaxRsApplicationRegistry"/> - <reference bind="addService" cardinality="1..n" interface="java.lang.Object" name="Provider" policy="dynamic" target="(&(objectClass=javax.ws.rs.*))" unbind="removeService"/> + <reference bind="addService" cardinality="1..n" interface="java.lang.Object" name="Provider" policy="dynamic" target="(|(objectClass=javax.ws.rs.*)(objectClass=org.apache.cxf.jaxrs.*))" unbind="removeService"/> </scr:component> diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/AnonymousPrincipalRequestFilter.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/AnonymousPrincipalRequestFilter.java new file mode 100644 index 00000000000..7da97043f99 --- /dev/null +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/AnonymousPrincipalRequestFilter.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.jaxrs.server.internal.security; + +import java.security.Principal; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.container.PreMatching; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.ext.Provider; +import org.apache.cxf.jaxrs.ext.MessageContext; +import org.apache.cxf.jaxrs.ext.MessageContextImpl; +import org.apache.cxf.phase.PhaseInterceptorChain; +import org.eclipse.osee.framework.jdk.core.type.OseePrincipal; +import org.eclipse.osee.jaxrs.server.internal.security.oauth2.OAuthUtil; +import org.eclipse.osee.jaxrs.server.security.JaxRsAuthenticator; + +/** + * @author Roberto E. Escobar + */ +@Provider +@PreMatching +public class AnonymousPrincipalRequestFilter implements ContainerRequestFilter { + + private JaxRsAuthenticator authenticator; + + public void setJaxRsAuthenticator(JaxRsAuthenticator authenticator) { + this.authenticator = authenticator; + } + + @Override + public void filter(ContainerRequestContext requestContext) { + SecurityContext sc = requestContext.getSecurityContext(); + Principal principal = sc.getUserPrincipal(); + if (principal == null) { + OseePrincipal anonymousPrincipal = authenticator.getAnonymousPrincipal(); + if (anonymousPrincipal != null) { + org.apache.cxf.security.SecurityContext securityContext = OAuthUtil.newSecurityContext(anonymousPrincipal); + MessageContext mc = getMessageContext(); + OAuthUtil.saveSecurityContext(mc, securityContext); + } + } + } + + public MessageContext getMessageContext() { + return new MessageContextImpl(PhaseInterceptorChain.getCurrentMessage()); + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/OseePrincipalContextProvider.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/OseePrincipalContextProvider.java index 5bb8f57e8f2..4dc283c4060 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/OseePrincipalContextProvider.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/OseePrincipalContextProvider.java @@ -8,7 +8,7 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.jaxrs.server.internal.security.oauth2; +package org.eclipse.osee.jaxrs.server.internal.security; import java.security.Principal; import javax.ws.rs.ext.Provider; @@ -35,4 +35,5 @@ public class OseePrincipalContextProvider implements ContextProvider<OseePrincip } return toReturn; } + }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/OAuthUtil.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/OAuthUtil.java index 4a7aac7f0cf..78648aa87a2 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/OAuthUtil.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/OAuthUtil.java @@ -26,6 +26,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.UriBuilder; import org.apache.cxf.common.util.Base64Utility; +import org.apache.cxf.jaxrs.ext.MessageContext; import org.apache.cxf.jaxrs.impl.HttpHeadersImpl; import org.apache.cxf.jaxrs.utils.HttpUtils; import org.apache.cxf.message.Message; @@ -154,6 +155,7 @@ public final class OAuthUtil { private static final String SUBJECT_EMAIL = "email"; private static final String SUBJECT_IS_ACTIVE = "is.active"; private static final String SUBJECT_IS_AUTHENTICATED = "is.authenticated"; + private static final String SUBJECT_OSEE_GUID = "osee.guid"; public static UserSubject newUserSubject(OseePrincipal subject) { List<String> roles = new ArrayList<String>(); @@ -171,6 +173,7 @@ public final class OAuthUtil { properties.put(SUBJECT_EMAIL, subject.getEmailAddress()); properties.put(SUBJECT_IS_ACTIVE, Boolean.toString(subject.isActive())); properties.put(SUBJECT_IS_AUTHENTICATED, Boolean.toString(subject.isAuthenticated())); + properties.put(SUBJECT_OSEE_GUID, subject.getOseeGuid()); data.setProperties(properties); return data; } @@ -216,6 +219,13 @@ public final class OAuthUtil { return new UserSubject(name, roleNames); } + public static void saveSecurityContext(MessageContext mc, SecurityContext securityContext) { + if (securityContext != null) { + mc.put(SecurityContext.class, securityContext); + mc.put(SecurityContext.class.getName(), securityContext); + } + } + private static final class UserSubjectWrapper extends BaseIdentity<Long> implements OseePrincipal { private final UserSubject subject; @@ -275,6 +285,11 @@ public final class OAuthUtil { private String get(String key, String defaultValue) { return getProperty(getProperties(), key, defaultValue); } + + @Override + public String getOseeGuid() { + return getProperty(getProperties(), SUBJECT_OSEE_GUID, "N/A"); + } } } diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/adapters/SubjectProviderImpl.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/adapters/SubjectProviderImpl.java index f4c1b06413b..e8d55464b6b 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/adapters/SubjectProviderImpl.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/adapters/SubjectProviderImpl.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.osee.jaxrs.server.internal.security.oauth2.provider.adapters; +import static org.eclipse.osee.jaxrs.server.internal.security.oauth2.OAuthUtil.saveSecurityContext; import java.util.UUID; import javax.servlet.http.HttpSession; import javax.ws.rs.core.MultivaluedMap; @@ -168,13 +169,6 @@ public class SubjectProviderImpl implements SubjectProvider { return securityContext; } - private void saveSecurityContext(MessageContext mc, SecurityContext securityContext) { - if (securityContext != null) { - mc.put(SecurityContext.class, securityContext); - mc.put(SecurityContext.class.getName(), securityContext); - } - } - @Override public UserSubject getSubjectById(long subjectId) { MessageContext mc = new MessageContextImpl(PhaseInterceptorChain.getCurrentMessage()); diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/OseePrincipalImpl.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/OseePrincipalImpl.java index 52a0d0285c5..37a09558d8c 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/OseePrincipalImpl.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/OseePrincipalImpl.java @@ -14,6 +14,7 @@ import java.util.Map; import java.util.Set; import org.eclipse.osee.framework.jdk.core.type.BaseIdentity; import org.eclipse.osee.framework.jdk.core.type.OseePrincipal; +import org.eclipse.osee.framework.jdk.core.util.Strings; /** * @author Roberto E. Escobar @@ -87,4 +88,16 @@ public class OseePrincipalImpl extends BaseIdentity<Long> implements OseePrincip public Map<String, String> getProperties() { return props; } + + @Override + public String getOseeGuid() { + String toReturn = "N/A"; + if (props != null) { + String value = props.get("osee.guid"); + if (Strings.isValid(value)) { + toReturn = value; + } + } + return toReturn; + } } diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsAuthenticator.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsAuthenticator.java index 7f3d80defcb..ec5254ffa9a 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsAuthenticator.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsAuthenticator.java @@ -19,4 +19,6 @@ public interface JaxRsAuthenticator { OseePrincipal authenticate(String scheme, String username, String password); + OseePrincipal getAnonymousPrincipal(); + }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuth.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuth.java index 5c3ed62a41f..6f9bc71e643 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuth.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuth.java @@ -15,7 +15,6 @@ import java.util.List; import org.apache.cxf.rs.security.oauth2.provider.OAuthContextProvider; import org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider; import org.eclipse.osee.jaxrs.server.internal.security.oauth2.OseeOAuthContextProvider; -import org.eclipse.osee.jaxrs.server.internal.security.oauth2.OseePrincipalContextProvider; import org.eclipse.osee.jaxrs.server.internal.security.oauth2.provider.writers.OAuthErrorHtmlWriter; /** @@ -36,7 +35,6 @@ public final class JaxRsOAuth { List<Object> providers = new ArrayList<Object>(); providers.add(new OAuthJSONProvider()); providers.add(new OAuthContextProvider()); - providers.add(new OseePrincipalContextProvider()); providers.add(new OseeOAuthContextProvider()); providers.add(new OAuthErrorHtmlWriter()); OAUTH_PROVIDERS = providers; |