cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [2/3] cxf-fediz git commit: Minor changes
Date Thu, 25 Feb 2016 17:40:24 GMT
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 <coheigea@apache.org>
Authored: Thu Feb 25 16:32:33 2016 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
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 @@
                                     <overWrite>true</overWrite>
                                     <outputDirectory>target/tomcat/rp/webapps/simpleWebapp</outputDirectory>
                                 </artifactItem>
-                                <artifactItem>
-                                    <groupId>org.apache.cxf.fediz.systests.webapps</groupId>
-                                    <artifactId>fediz-systests-webapps-simple</artifactId>
-                                    <version>${project.version}</version>
-                                    <type>war</type>
-                                    <overWrite>true</overWrite>
-                                    <outputDirectory>target/tomcat/rp/webapps/simpleWebapp2</outputDirectory>
-                                </artifactItem>
                             </artifactItems>
                             <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
                             <overWriteSnapshots>true</overWriteSnapshots>

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 @@
-<!--
-  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.
--->
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<HTML><HEAD><TITLE>WS Federation Tomcat Examples</TITLE>
-<META http-equiv=Content-Type content="text/html">
-</HEAD>
-<BODY>
-<P>
-<H3>Secure Test</H3>
-<P></P>
-</BODY></HTML>

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 @@
-<!--
-  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.
--->
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<HTML><HEAD><TITLE>WS Federation Tomcat Examples</TITLE>
-<META http-equiv=Content-Type content="text/html">
-</HEAD>
-<BODY>
-<P>
-<H3>Secure Test</H3>
-<P></P>
-</BODY></HTML>


Mime
View raw message