You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2014/10/06 16:57:34 UTC

git commit: Also ask the STS for Claims in wsclientWebapp

Repository: cxf-fediz
Updated Branches:
  refs/heads/master ffa599bc7 -> 2808dff33


Also ask the STS for Claims in wsclientWebapp


Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/2808dff3
Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/2808dff3
Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/2808dff3

Branch: refs/heads/master
Commit: 2808dff33c3205d2229be30ac976560be8847261
Parents: ffa599b
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Mon Oct 6 15:57:19 2014 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Mon Oct 6 15:57:19 2014 +0100

----------------------------------------------------------------------
 .../fediz/example/ClaimsCallbackHandler.java    | 68 ++++++++++++++++++++
 .../main/webapp/WEB-INF/applicationContext.xml  |  4 ++
 2 files changed, 72 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/2808dff3/examples/wsclientWebapp/webapp/src/main/java/org/apache/cxf/fediz/example/ClaimsCallbackHandler.java
----------------------------------------------------------------------
diff --git a/examples/wsclientWebapp/webapp/src/main/java/org/apache/cxf/fediz/example/ClaimsCallbackHandler.java b/examples/wsclientWebapp/webapp/src/main/java/org/apache/cxf/fediz/example/ClaimsCallbackHandler.java
new file mode 100644
index 0000000..d999968
--- /dev/null
+++ b/examples/wsclientWebapp/webapp/src/main/java/org/apache/cxf/fediz/example/ClaimsCallbackHandler.java
@@ -0,0 +1,68 @@
+/**
+ * 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.cxf.fediz.example;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.security.trust.claims.ClaimsCallback;
+
+/**
+ * This CallbackHandler implementation creates a Claims Element for a "role" ClaimType and
+ * stores it on the ClaimsCallback object.
+ */
+public class ClaimsCallbackHandler implements CallbackHandler {
+    
+    public void handle(Callback[] callbacks)
+        throws IOException, UnsupportedCallbackException {
+        for (int i = 0; i < callbacks.length; i++) {
+            if (callbacks[i] instanceof ClaimsCallback) {
+                ClaimsCallback callback = (ClaimsCallback) callbacks[i];
+                callback.setClaims(createClaims());
+                
+            } else {
+                throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
+            }
+        }
+    }
+    
+    /**
+     * Create a Claims Element for a "role"
+     */
+    private Element createClaims() {
+        Document doc = DOMUtils.createDocument();
+        Element claimsElement = 
+            doc.createElementNS("http://docs.oasis-open.org/ws-sx/ws-trust/200512", "Claims");
+        claimsElement.setAttributeNS(null, "Dialect", "http://schemas.xmlsoap.org/ws/2005/05/identity");
+        Element claimType = 
+            doc.createElementNS("http://schemas.xmlsoap.org/ws/2005/05/identity", "ClaimType");
+        claimType.setAttributeNS(null, "Uri", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role");
+        claimsElement.appendChild(claimType);
+        return claimsElement;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/2808dff3/examples/wsclientWebapp/webapp/src/main/webapp/WEB-INF/applicationContext.xml
----------------------------------------------------------------------
diff --git a/examples/wsclientWebapp/webapp/src/main/webapp/WEB-INF/applicationContext.xml b/examples/wsclientWebapp/webapp/src/main/webapp/WEB-INF/applicationContext.xml
index 59c8f8d..0268075 100644
--- a/examples/wsclientWebapp/webapp/src/main/webapp/WEB-INF/applicationContext.xml
+++ b/examples/wsclientWebapp/webapp/src/main/webapp/WEB-INF/applicationContext.xml
@@ -32,6 +32,9 @@
     <bean id="delegationCallbackHandler"
         class="org.apache.cxf.fediz.cxf.web.ThreadLocalCallbackHandler" />
 
+    <bean id="roleClaimsCallbackHandler"
+        class="org.apache.cxf.fediz.example.ClaimsCallbackHandler" />
+
     <jaxws:client id="HelloServiceClient" serviceName="svc:GreeterService"
         xmlns:svc="http://apache.org/hello_world_soap_http"
         serviceClass="org.apache.hello_world_soap_http.Greeter"
@@ -54,6 +57,7 @@
 
                         </map>
                     </property>
+                    <property name="claimsCallbackHandler" ref="roleClaimsCallbackHandler"/>
                 </bean>
             </entry>
             <entry key="ws-security.cache.issued.token.in.endpoint"