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 2011/02/23 11:54:15 UTC

svn commit: r1073693 - /cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java

Author: coheigea
Date: Wed Feb 23 10:54:14 2011
New Revision: 1073693

URL: http://svn.apache.org/viewvc?rev=1073693&view=rev
Log:
[CXF-3348] - Applied patch, thanks
 - I made some minor changes, in that the TokenType from the Template element gets priority over the set TokenType.

Modified:
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java?rev=1073693&r1=1073692&r2=1073693&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java Wed Feb 23 10:54:14 2011
@@ -145,6 +145,7 @@ public class STSClient implements Config
     int ttl = 300;
     
     Object actAs;
+    String tokenType;
 
     Map<String, Object> ctx = new HashMap<String, Object>();
     
@@ -292,7 +293,11 @@ public class STSClient implements Config
     public int getKeySize() {
         return keySize;
     }
-    
+
+    public void setTokenType(String tokenType) {
+        this.tokenType = tokenType;
+    }
+
     /**
      * Indicate whether to use the signer's public X509 certificate for the subject confirmation key info 
      * when creating a RequestsSecurityToken message. If the property is set to 'false', only the public key 
@@ -423,7 +428,7 @@ public class STSClient implements Config
         boolean wroteKeySize = false;
         
         String keyType = null;
-        String tokenType = null;
+        String sptt = null;
         
         if (template != null) {
             if (this.useSecondaryParameters()) {
@@ -439,7 +444,7 @@ public class STSClient implements Config
                     wroteKeySize = true;
                     keySize = Integer.parseInt(DOMUtils.getContent(tl));
                 } else if ("TokenType".equals(tl.getLocalName())) {
-                    tokenType = DOMUtils.getContent(tl);
+                    sptt = DOMUtils.getContent(tl);
                 }
                 tl = DOMUtils.getNextElement(tl);
             }
@@ -451,6 +456,9 @@ public class STSClient implements Config
 
         addRequestType(requestType, writer);
         addAppliesTo(writer, appliesTo);
+        if (sptt == null) {
+            addTokenType(writer);
+        }
         keyType = writeKeyType(writer, keyType);
 
         byte[] requestorEntropy = null;
@@ -488,8 +496,12 @@ public class STSClient implements Config
         if (cert != null) {
             token.setX509Certificate(cert, crypto);
         }
-        if (tokenType != null) {
-            token.setTokenType(tokenType);
+        if (token.getTokenType() == null) {
+            if (sptt != null) {
+                token.setTokenType(sptt);
+            } else if (tokenType != null) {
+                token.setTokenType(tokenType);
+            }
         }
         return token;
     }
@@ -809,7 +821,15 @@ public class STSClient implements Config
             writer.writeEndElement();
         }
     }
-    
+
+    private void addTokenType(XMLStreamWriter writer) throws XMLStreamException {
+        if (tokenType != null) {
+            writer.writeStartElement("wst", "TokenType", namespace);
+            writer.writeCharacters(tokenType);
+            writer.writeEndElement();
+        }
+    }
+
     private void addActAs(W3CDOMStreamWriter writer) throws Exception {
         if (this.actAs != null) {
             final boolean isString = this.actAs instanceof String;
@@ -855,6 +875,7 @@ public class STSClient implements Config
         Element rpt = null;
         Element lte = null;
         Element entropy = null;
+        String tt = null;
 
         while (el != null) {
             String ln = el.getLocalName();
@@ -871,6 +892,8 @@ public class STSClient implements Config
                     rpt = el;
                 } else if ("Entropy".equals(ln)) {
                     entropy = el;
+                } else if ("TokenType".equals(ln)) {
+                    tt = DOMUtils.getContent(el);
                 }
             }
             el = DOMUtils.getNextElement(el);
@@ -884,6 +907,7 @@ public class STSClient implements Config
         token.setAttachedReference(rar);
         token.setUnattachedReference(rur);
         token.setIssuerAddress(location);
+        token.setTokenType(tt);
 
         byte[] secret = null;