Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 61B0E18930 for ; Thu, 25 Feb 2016 17:40:24 +0000 (UTC) Received: (qmail 7133 invoked by uid 500); 25 Feb 2016 17:40:24 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 6937 invoked by uid 500); 25 Feb 2016 17:40:24 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 6920 invoked by uid 99); 25 Feb 2016 17:40:24 -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; Thu, 25 Feb 2016 17:40:24 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DD23EE8F30; Thu, 25 Feb 2016 17:40:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@cxf.apache.org Date: Thu, 25 Feb 2016 17:40:24 -0000 Message-Id: <9e9e9b095a6e469988b7532cc7d3815f@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/3] cxf-fediz git commit: Minor changes Minor changes Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/ed9727cc Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/ed9727cc Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/ed9727cc Branch: refs/heads/master Commit: ed9727cc34a57974a9ef3f5533c1e076d150b7d2 Parents: 423f68f Author: Colm O hEigeartaigh Authored: Thu Feb 25 16:32:33 2016 +0000 Committer: Colm O hEigeartaigh Committed: Thu Feb 25 16:32:33 2016 +0000 ---------------------------------------------------------------------- systests/federation/oidc/pom.xml | 8 -- .../fediz/oidc/idp/example/BasicAuthFilter.java | 82 ++------------------ .../src/main/webapp/secure/test.html | 25 ------ .../src/main/webapp/secure/test.html | 25 ------ 4 files changed, 7 insertions(+), 133 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/ed9727cc/systests/federation/oidc/pom.xml ---------------------------------------------------------------------- diff --git a/systests/federation/oidc/pom.xml b/systests/federation/oidc/pom.xml index 7ff6bd8..aadb529 100644 --- a/systests/federation/oidc/pom.xml +++ b/systests/federation/oidc/pom.xml @@ -178,14 +178,6 @@ true target/tomcat/rp/webapps/simpleWebapp - - org.apache.cxf.fediz.systests.webapps - fediz-systests-webapps-simple - ${project.version} - war - true - target/tomcat/rp/webapps/simpleWebapp2 - true true http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/ed9727cc/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/BasicAuthFilter.java ---------------------------------------------------------------------- diff --git a/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/BasicAuthFilter.java b/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/BasicAuthFilter.java index 6c64fbe..a85c8c9 100644 --- a/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/BasicAuthFilter.java +++ b/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/BasicAuthFilter.java @@ -19,38 +19,22 @@ package org.apache.cxf.fediz.oidc.idp.example; import java.io.IOException; -import java.security.Principal; -import javax.security.auth.callback.CallbackHandler; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.core.Response; -import org.w3c.dom.Document; import org.apache.cxf.configuration.security.AuthorizationPolicy; -import org.apache.cxf.helpers.DOMUtils; +import org.apache.cxf.jaxrs.utils.ExceptionUtils; import org.apache.cxf.jaxrs.utils.JAXRSUtils; import org.apache.cxf.message.Message; -import org.apache.cxf.security.SecurityContext; -import org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl; -import org.apache.wss4j.dom.WSConstants; -import org.apache.wss4j.dom.engine.WSSConfig; -import org.apache.wss4j.dom.handler.RequestData; -import org.apache.wss4j.dom.message.token.UsernameToken; -import org.apache.wss4j.dom.validate.Credential; -import org.apache.wss4j.dom.validate.UsernameTokenValidator; +import org.apache.cxf.rt.security.saml.interceptor.WSS4JBasicAuthValidator; /** - * A simple filter to validate a Basic Auth username/password via a CallbackHandler + * Extends the WSS4J validator as a JAX-RS request filter */ -public class BasicAuthFilter implements ContainerRequestFilter { - - static { - WSSConfig.init(); - } +public class BasicAuthFilter extends WSS4JBasicAuthValidator implements ContainerRequestFilter { - private CallbackHandler callbackHandler; - public void filter(ContainerRequestContext requestContext) throws IOException { Message message = JAXRSUtils.getCurrentMessage(); AuthorizationPolicy policy = message.get(AuthorizationPolicy.class); @@ -58,65 +42,13 @@ public class BasicAuthFilter implements ContainerRequestFilter { if (policy == null || policy.getUserName() == null || policy.getPassword() == null) { requestContext.abortWith( Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build()); - return; } try { - UsernameToken token = convertPolicyToToken(policy); - Credential credential = new Credential(); - credential.setUsernametoken(token); - - RequestData data = new RequestData(); - data.setMsgContext(message); - data.setCallbackHandler(callbackHandler); - UsernameTokenValidator validator = new UsernameTokenValidator(); - credential = validator.validate(credential, data); - - // Create a Principal/SecurityContext - Principal p = null; - if (credential != null && credential.getPrincipal() != null) { - p = credential.getPrincipal(); - } else { - p = new WSUsernameTokenPrincipalImpl(policy.getUserName(), false); - ((WSUsernameTokenPrincipalImpl)p).setPassword(policy.getPassword()); - } - message.put(SecurityContext.class, createSecurityContext(p)); + super.validate(message); } catch (Exception ex) { - requestContext.abortWith( - Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build()); + throw ExceptionUtils.toInternalServerErrorException(ex, null); } } - protected UsernameToken convertPolicyToToken(AuthorizationPolicy policy) - throws Exception { - - Document doc = DOMUtils.createDocument(); - UsernameToken token = new UsernameToken(false, doc, - WSConstants.PASSWORD_TEXT); - token.setName(policy.getUserName()); - token.setPassword(policy.getPassword()); - return token; - } - - protected SecurityContext createSecurityContext(final Principal p) { - return new SecurityContext() { - - public Principal getUserPrincipal() { - return p; - } - - public boolean isUserInRole(String arg0) { - return false; - } - }; - } - - public CallbackHandler getCallbackHandler() { - return callbackHandler; - } - - public void setCallbackHandler(CallbackHandler callbackHandler) { - this.callbackHandler = callbackHandler; - } - -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/ed9727cc/systests/federation/oidcIdpWebapp/src/main/webapp/secure/test.html ---------------------------------------------------------------------- diff --git a/systests/federation/oidcIdpWebapp/src/main/webapp/secure/test.html b/systests/federation/oidcIdpWebapp/src/main/webapp/secure/test.html deleted file mode 100644 index 9cf7366..0000000 --- a/systests/federation/oidcIdpWebapp/src/main/webapp/secure/test.html +++ /dev/null @@ -1,25 +0,0 @@ - - -WS Federation Tomcat Examples - - - -

-

Secure Test

-

- http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/ed9727cc/systests/federation/samlIdpWebapp/src/main/webapp/secure/test.html ---------------------------------------------------------------------- diff --git a/systests/federation/samlIdpWebapp/src/main/webapp/secure/test.html b/systests/federation/samlIdpWebapp/src/main/webapp/secure/test.html deleted file mode 100644 index 9cf7366..0000000 --- a/systests/federation/samlIdpWebapp/src/main/webapp/secure/test.html +++ /dev/null @@ -1,25 +0,0 @@ - - -WS Federation Tomcat Examples - - - -

-

Secure Test

-

-