You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2012/01/30 18:22:40 UTC

svn commit: r1237808 [2/3] - in /webservices/wss4j/branches/swssf/streaming-ws-security/src: main/java/org/swssf/wss/impl/saml/ main/java/org/swssf/wss/impl/saml/bean/ main/java/org/swssf/wss/impl/saml/builder/ test/java/org/swssf/wss/test/ test/java/o...

Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML1ComponentBuilder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML1ComponentBuilder.java?rev=1237808&r1=1237807&r2=1237808&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML1ComponentBuilder.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML1ComponentBuilder.java Mon Jan 30 17:22:39 2012
@@ -23,16 +23,44 @@ import org.joda.time.DateTime;
 import org.opensaml.Configuration;
 import org.opensaml.common.SAMLObjectBuilder;
 import org.opensaml.common.SAMLVersion;
-import org.opensaml.saml1.core.*;
+
+import org.opensaml.saml1.core.Action;
+import org.opensaml.saml1.core.Assertion;
+import org.opensaml.saml1.core.Attribute;
+import org.opensaml.saml1.core.AttributeStatement;
+import org.opensaml.saml1.core.AttributeValue;
+import org.opensaml.saml1.core.Audience;
+import org.opensaml.saml1.core.AudienceRestrictionCondition;
+import org.opensaml.saml1.core.AuthenticationStatement;
+import org.opensaml.saml1.core.AuthorizationDecisionStatement;
+import org.opensaml.saml1.core.Conditions;
+import org.opensaml.saml1.core.ConfirmationMethod;
+import org.opensaml.saml1.core.DecisionTypeEnumeration;
+import org.opensaml.saml1.core.Evidence;
+import org.opensaml.saml1.core.NameIdentifier;
+import org.opensaml.saml1.core.Subject;
+import org.opensaml.saml1.core.SubjectConfirmation;
+import org.opensaml.saml1.core.SubjectLocality;
+
+import org.opensaml.xml.XMLObject;
 import org.opensaml.xml.XMLObjectBuilderFactory;
 import org.opensaml.xml.schema.XSString;
 import org.opensaml.xml.schema.impl.XSStringBuilder;
 import org.opensaml.xml.security.x509.BasicX509Credential;
 import org.opensaml.xml.security.x509.X509KeyInfoGeneratorFactory;
 import org.opensaml.xml.signature.KeyInfo;
+
 import org.swssf.wss.ext.WSSecurityException;
 import org.swssf.wss.impl.saml.OpenSAMLUtil;
-import org.swssf.wss.impl.saml.bean.*;
+import org.swssf.wss.impl.saml.bean.ActionBean;
+import org.swssf.wss.impl.saml.bean.AttributeBean;
+import org.swssf.wss.impl.saml.bean.AttributeStatementBean;
+import org.swssf.wss.impl.saml.bean.AuthDecisionStatementBean;
+import org.swssf.wss.impl.saml.bean.AuthenticationStatementBean;
+import org.swssf.wss.impl.saml.bean.ConditionsBean;
+import org.swssf.wss.impl.saml.bean.KeyInfoBean;
+import org.swssf.wss.impl.saml.bean.SubjectBean;
+import org.swssf.wss.impl.saml.bean.SubjectLocalityBean;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -45,35 +73,41 @@ import java.util.UUID;
  * Created on May 18, 2009
  */
 public class SAML1ComponentBuilder {
-
+    
     private static SAMLObjectBuilder<Assertion> assertionV1Builder;
-
+    
     private static SAMLObjectBuilder<Conditions> conditionsV1Builder;
-
+    
+    private static SAMLObjectBuilder<AudienceRestrictionCondition> audienceRestrictionV1Builder;
+    
+    private static SAMLObjectBuilder<Audience> audienceV1Builder;
+    
     private static SAMLObjectBuilder<AuthenticationStatement> authenticationStatementV1Builder;
-
+    
     private static SAMLObjectBuilder<Subject> subjectV1Builder;
-
+    
     private static SAMLObjectBuilder<NameIdentifier> nameIdentifierV1Builder;
-
-    private static SAMLObjectBuilder<SubjectConfirmation>
-            subjectConfirmationV1Builder;
-
+    
+    private static SAMLObjectBuilder<SubjectConfirmation> 
+        subjectConfirmationV1Builder;
+    
     private static SAMLObjectBuilder<ConfirmationMethod> confirmationMethodV1Builder;
-
-    private static SAMLObjectBuilder<AttributeStatement>
-            attributeStatementV1Builder;
-
+    
+    private static SAMLObjectBuilder<AttributeStatement> 
+        attributeStatementV1Builder;
+    
     private static SAMLObjectBuilder<Attribute> attributeV1Builder;
-
+    
     private static XSStringBuilder stringBuilder;
-
-    private static SAMLObjectBuilder<AuthorizationDecisionStatement>
-            authorizationDecisionStatementV1Builder;
-
+    
+    private static SAMLObjectBuilder<AuthorizationDecisionStatement> 
+        authorizationDecisionStatementV1Builder;
+    
     private static SAMLObjectBuilder<Action> actionElementV1Builder;
-
+    
     private static XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
+    
+    private static SAMLObjectBuilder<SubjectLocality> subjectLocalityBuilder;
 
     /**
      * Create a new SAML 1.1 assertion
@@ -84,24 +118,24 @@ public class SAML1ComponentBuilder {
     @SuppressWarnings("unchecked")
     public static Assertion createSamlv1Assertion(String issuer) {
         if (assertionV1Builder == null) {
-            assertionV1Builder = (SAMLObjectBuilder<Assertion>)
-                    builderFactory.getBuilder(Assertion.DEFAULT_ELEMENT_NAME);
+            assertionV1Builder = (SAMLObjectBuilder<Assertion>) 
+                builderFactory.getBuilder(Assertion.DEFAULT_ELEMENT_NAME);
             if (assertionV1Builder == null) {
                 throw new IllegalStateException(
-                        "OpenSaml engine not initialized. Please make sure to initialize the OpenSaml "
-                                + "engine prior using it"
+                    "OpenSaml engine not initialized. Please make sure to initialize the OpenSaml "
+                    + "engine prior using it"
                 );
             }
         }
-        Assertion assertion =
-                assertionV1Builder.buildObject(
-                        Assertion.DEFAULT_ELEMENT_NAME,
-                        Assertion.TYPE_NAME
-                );
+        Assertion assertion = 
+            assertionV1Builder.buildObject(
+                Assertion.DEFAULT_ELEMENT_NAME, 
+                Assertion.TYPE_NAME
+            );
         assertion.setVersion(SAMLVersion.VERSION_11);
         assertion.setIssuer(issuer);
         assertion.setIssueInstant(new DateTime()); // now
-        assertion.setID(UUID.randomUUID().toString());
+        assertion.setID("_" + UUID.randomUUID().toString());
         return assertion;
     }
 
@@ -113,40 +147,40 @@ public class SAML1ComponentBuilder {
      * @return A Saml 1.1 subject
      */
     @SuppressWarnings("unchecked")
-    public static Subject createSaml1v1Subject(SubjectBean subjectBean)
-            throws org.opensaml.xml.security.SecurityException, WSSecurityException {
+    public static Subject createSaml1v1Subject(SubjectBean subjectBean) 
+        throws org.opensaml.xml.security.SecurityException, WSSecurityException {
         if (subjectV1Builder == null) {
-            subjectV1Builder = (SAMLObjectBuilder<Subject>)
-                    builderFactory.getBuilder(Subject.DEFAULT_ELEMENT_NAME);
+            subjectV1Builder = (SAMLObjectBuilder<Subject>) 
+                builderFactory.getBuilder(Subject.DEFAULT_ELEMENT_NAME);
         }
         if (nameIdentifierV1Builder == null) {
             nameIdentifierV1Builder = (SAMLObjectBuilder<NameIdentifier>)
-                    builderFactory.getBuilder(NameIdentifier.DEFAULT_ELEMENT_NAME);
+                builderFactory.getBuilder(NameIdentifier.DEFAULT_ELEMENT_NAME);
         }
         if (subjectConfirmationV1Builder == null) {
             subjectConfirmationV1Builder = (SAMLObjectBuilder<SubjectConfirmation>)
-                    builderFactory.getBuilder(SubjectConfirmation.DEFAULT_ELEMENT_NAME);
-
+                builderFactory.getBuilder(SubjectConfirmation.DEFAULT_ELEMENT_NAME);
+            
         }
         if (confirmationMethodV1Builder == null) {
             confirmationMethodV1Builder = (SAMLObjectBuilder<ConfirmationMethod>)
-                    builderFactory.getBuilder(ConfirmationMethod.DEFAULT_ELEMENT_NAME);
+                builderFactory.getBuilder(ConfirmationMethod.DEFAULT_ELEMENT_NAME);
         }
-
+        
         Subject subject = subjectV1Builder.buildObject();
         NameIdentifier nameIdentifier = nameIdentifierV1Builder.buildObject();
         SubjectConfirmation subjectConfirmation = subjectConfirmationV1Builder.buildObject();
         ConfirmationMethod confirmationMethod = confirmationMethodV1Builder.buildObject();
-
+        
         nameIdentifier.setNameQualifier(subjectBean.getSubjectNameQualifier());
         nameIdentifier.setNameIdentifier(subjectBean.getSubjectName());
-        nameIdentifier.setFormat(SAML1Constants.NAMEID_FORMAT_UNSPECIFIED);
+        nameIdentifier.setFormat(subjectBean.getSubjectNameIDFormat());
         String confirmationMethodStr = subjectBean.getSubjectConfirmationMethod();
-
+        
         if (confirmationMethodStr == null) {
             confirmationMethodStr = SAML1Constants.CONF_SENDER_VOUCHES;
         }
-
+        
         confirmationMethod.setConfirmationMethod(confirmationMethodStr);
         subjectConfirmation.getConfirmationMethods().add(confirmationMethod);
         if (subjectBean.getKeyInfo() != null) {
@@ -155,22 +189,20 @@ public class SAML1ComponentBuilder {
         }
         subject.setNameIdentifier(nameIdentifier);
         subject.setSubjectConfirmation(subjectConfirmation);
-
+        
         return subject;
     }
-
+    
     /**
      * Create an Opensaml KeyInfo object from the parameters
-     *
      * @param keyInfo the KeyInfo bean from which to extract security credentials
      * @return the KeyInfo object
      * @throws org.opensaml.xml.security.SecurityException
-     *
      */
-    public static KeyInfo createKeyInfo(KeyInfoBean keyInfo)
-            throws org.opensaml.xml.security.SecurityException, WSSecurityException {
+    public static KeyInfo createKeyInfo(KeyInfoBean keyInfo) 
+        throws org.opensaml.xml.security.SecurityException, WSSecurityException {
         if (keyInfo.getElement() != null) {
-            return (KeyInfo) OpenSAMLUtil.fromDom(keyInfo.getElement());
+            return (KeyInfo)OpenSAMLUtil.fromDom(keyInfo.getElement());
         } else {
             // Set the certificate or public key
             BasicX509Credential keyInfoCredential = new BasicX509Credential();
@@ -179,7 +211,7 @@ public class SAML1ComponentBuilder {
             } else if (keyInfo.getPublicKey() != null) {
                 keyInfoCredential.setPublicKey(keyInfo.getPublicKey());
             }
-
+            
             // Configure how to emit the certificate
             X509KeyInfoGeneratorFactory kiFactory = new X509KeyInfoGeneratorFactory();
             KeyInfoBean.CERT_IDENTIFIER certIdentifier = keyInfo.getCertIdentifer();
@@ -209,27 +241,27 @@ public class SAML1ComponentBuilder {
     @SuppressWarnings("unchecked")
     public static Conditions createSamlv1Conditions(ConditionsBean conditionsBean) {
         if (conditionsV1Builder == null) {
-            conditionsV1Builder = (SAMLObjectBuilder<Conditions>)
-                    builderFactory.getBuilder(Conditions.DEFAULT_ELEMENT_NAME);
-
+            conditionsV1Builder = (SAMLObjectBuilder<Conditions>) 
+                builderFactory.getBuilder(Conditions.DEFAULT_ELEMENT_NAME);
+            
         }
-        Conditions conditions = conditionsV1Builder.buildObject(Conditions.TYPE_NAME);
-
+        Conditions conditions = conditionsV1Builder.buildObject();
+        
         if (conditionsBean == null) {
             DateTime newNotBefore = new DateTime();
             conditions.setNotBefore(newNotBefore);
             conditions.setNotOnOrAfter(newNotBefore.plusMinutes(5));
             return conditions;
         }
-
+        
         int tokenPeriodMinutes = conditionsBean.getTokenPeriodMinutes();
         DateTime notBefore = conditionsBean.getNotBefore();
         DateTime notAfter = conditionsBean.getNotAfter();
-
+        
         if (notBefore != null && notAfter != null) {
             if (notBefore.isAfter(notAfter)) {
                 throw new IllegalStateException(
-                        "The value of notBefore may not be after the value of notAfter"
+                    "The value of notBefore may not be after the value of notAfter"
                 );
             }
             conditions.setNotBefore(notBefore);
@@ -237,10 +269,46 @@ public class SAML1ComponentBuilder {
         } else {
             DateTime newNotBefore = new DateTime();
             conditions.setNotBefore(newNotBefore);
+            if (tokenPeriodMinutes <= 0) {
+                tokenPeriodMinutes = 5;
+            }
             conditions.setNotOnOrAfter(newNotBefore.plusMinutes(tokenPeriodMinutes));
         }
+        
+        if (conditionsBean.getAudienceURI() != null) {
+            AudienceRestrictionCondition audienceRestriction = 
+                createSamlv1AudienceRestriction(conditionsBean.getAudienceURI());
+            conditions.getAudienceRestrictionConditions().add(audienceRestriction);
+        }
+        
         return conditions;
     }
+    
+    /**
+     * Create an AudienceRestrictionCondition object
+     *
+     * @param audienceURI of type String
+     * @return an AudienceRestrictionCondition object
+     */
+    @SuppressWarnings("unchecked")
+    public static AudienceRestrictionCondition 
+    createSamlv1AudienceRestriction(String audienceURI) {
+        if (audienceRestrictionV1Builder == null) {
+            audienceRestrictionV1Builder = (SAMLObjectBuilder<AudienceRestrictionCondition>) 
+                builderFactory.getBuilder(AudienceRestrictionCondition.DEFAULT_ELEMENT_NAME);
+        }
+        if (audienceV1Builder == null) {
+            audienceV1Builder = (SAMLObjectBuilder<Audience>) 
+                builderFactory.getBuilder(Audience.DEFAULT_ELEMENT_NAME);
+        }
+       
+        AudienceRestrictionCondition audienceRestriction = 
+            audienceRestrictionV1Builder.buildObject();
+        Audience audience = audienceV1Builder.buildObject();
+        audience.setUri(audienceURI);
+        audienceRestriction.getAudiences().add(audience);
+        return audienceRestriction;
+    }
 
     /**
      * Create SAML 1.1 authentication statement(s)
@@ -250,38 +318,52 @@ public class SAML1ComponentBuilder {
      */
     @SuppressWarnings("unchecked")
     public static List<AuthenticationStatement> createSamlv1AuthenticationStatement(
-            List<AuthenticationStatementBean> authBeans
+        List<AuthenticationStatementBean> authBeans
     ) throws org.opensaml.xml.security.SecurityException, WSSecurityException {
-        List<AuthenticationStatement> authenticationStatements =
-                new ArrayList<AuthenticationStatement>();
-
+        List<AuthenticationStatement> authenticationStatements = 
+            new ArrayList<AuthenticationStatement>();
+        
         if (authenticationStatementV1Builder == null) {
-            authenticationStatementV1Builder = (SAMLObjectBuilder<AuthenticationStatement>)
-                    builderFactory.getBuilder(AuthenticationStatement.DEFAULT_ELEMENT_NAME);
+            authenticationStatementV1Builder = (SAMLObjectBuilder<AuthenticationStatement>) 
+                builderFactory.getBuilder(AuthenticationStatement.DEFAULT_ELEMENT_NAME);
+        }
+        if (subjectLocalityBuilder == null) {
+            subjectLocalityBuilder = (SAMLObjectBuilder<SubjectLocality>) 
+                builderFactory.getBuilder(SubjectLocality.DEFAULT_ELEMENT_NAME);
         }
 
         if (authBeans != null && authBeans.size() > 0) {
             for (AuthenticationStatementBean statementBean : authBeans) {
-                AuthenticationStatement authenticationStatement =
-                        authenticationStatementV1Builder.buildObject(
-                                AuthenticationStatement.DEFAULT_ELEMENT_NAME,
-                                AuthenticationStatement.TYPE_NAME
-                        );
-                Subject authSubject =
-                        SAML1ComponentBuilder.createSaml1v1Subject(statementBean.getSubject());
+                AuthenticationStatement authenticationStatement = 
+                    authenticationStatementV1Builder.buildObject(
+                        AuthenticationStatement.DEFAULT_ELEMENT_NAME, 
+                        AuthenticationStatement.TYPE_NAME
+                    );
+                Subject authSubject = 
+                    SAML1ComponentBuilder.createSaml1v1Subject(statementBean.getSubject());
                 authenticationStatement.setSubject(authSubject);
 
                 if (statementBean.getAuthenticationInstant() != null) {
                     authenticationStatement.setAuthenticationInstant(
-                            statementBean.getAuthenticationInstant()
+                        statementBean.getAuthenticationInstant()
                     );
                 } else {
                     authenticationStatement.setAuthenticationInstant(new DateTime());
                 }
 
                 authenticationStatement.setAuthenticationMethod(
-                        transformAuthenticationMethod(statementBean.getAuthenticationMethod())
+                    transformAuthenticationMethod(statementBean.getAuthenticationMethod())
                 );
+                
+                SubjectLocalityBean subjectLocalityBean = statementBean.getSubjectLocality();
+                if (subjectLocalityBean != null) {
+                    SubjectLocality subjectLocality = subjectLocalityBuilder.buildObject();
+                    subjectLocality.setDNSAddress(subjectLocalityBean.getDnsAddress());
+                    subjectLocality.setIPAddress(subjectLocalityBean.getIpAddress());
+
+                    authenticationStatement.setSubjectLocality(subjectLocality);
+                }
+                
                 authenticationStatements.add(authenticationStatement);
             }
         }
@@ -290,7 +372,7 @@ public class SAML1ComponentBuilder {
     }
 
     /**
-     * Method transformAuthenticationMethod transforms the user-supplied authentication method
+     * Method transformAuthenticationMethod transforms the user-supplied authentication method 
      * value into one of the supported specification-compliant values.
      * NOTE: Only "Password" is supported at this time.
      *
@@ -315,11 +397,11 @@ public class SAML1ComponentBuilder {
      */
     @SuppressWarnings("unchecked")
     public static List<AttributeStatement> createSamlv1AttributeStatement(
-            List<AttributeStatementBean> attributeData
+        List<AttributeStatementBean> attributeData
     ) throws org.opensaml.xml.security.SecurityException, WSSecurityException {
         if (attributeStatementV1Builder == null) {
-            attributeStatementV1Builder = (SAMLObjectBuilder<AttributeStatement>)
-                    builderFactory.getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME);
+            attributeStatementV1Builder = (SAMLObjectBuilder<AttributeStatement>) 
+                builderFactory.getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME);
         }
 
         List<AttributeStatement> attributeStatements = new ArrayList<AttributeStatement>();
@@ -328,17 +410,22 @@ public class SAML1ComponentBuilder {
             for (AttributeStatementBean statementBean : attributeData) {
                 // Create the attribute statementBean and set the subject
                 AttributeStatement attributeStatement = attributeStatementV1Builder.buildObject();
-                Subject attributeSubject =
-                        SAML1ComponentBuilder.createSaml1v1Subject(statementBean.getSubject());
+                Subject attributeSubject = 
+                    SAML1ComponentBuilder.createSaml1v1Subject(statementBean.getSubject());
                 attributeStatement.setSubject(attributeSubject);
                 // Add the individual attributes
                 for (AttributeBean values : statementBean.getSamlAttributes()) {
-                    Attribute samlAttribute =
-                            createSamlv1Attribute(
-                                    values.getSimpleName(),
-                                    values.getQualifiedName(),
-                                    values.getAttributeValues()
-                            );
+                    List<?> attributeValues = values.getAttributeValues();
+                    if (attributeValues == null || attributeValues.isEmpty()) {
+                        attributeValues = values.getCustomAttributeValues();
+                    }
+                    
+                    Attribute samlAttribute = 
+                        createSamlv1Attribute(
+                            values.getSimpleName(),
+                            values.getQualifiedName(), 
+                            attributeValues
+                        );
                     attributeStatement.getAttributes().add(samlAttribute);
                 }
                 // Add the completed attribute statementBean to the collection
@@ -353,33 +440,37 @@ public class SAML1ComponentBuilder {
      * Create a SAML 1.1 attribute
      *
      * @param attributeName the Attribute Name
-     * @param attributeUrn  the Attribute Qualified Name
-     * @param values        the Attribute Values
+     * @param attributeUrn the Attribute Qualified Name
+     * @param values the Attribute Values
      * @return a SAML 1.1 attribute
      */
     @SuppressWarnings("unchecked")
     public static Attribute createSamlv1Attribute(
-            String attributeName,
-            String attributeUrn,
-            List<String> values
+        String attributeName, 
+        String attributeUrn,
+        List<?> values
     ) {
         if (attributeV1Builder == null) {
-            attributeV1Builder = (SAMLObjectBuilder<Attribute>)
-                    builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
+            attributeV1Builder = (SAMLObjectBuilder<Attribute>) 
+                builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
         }
         if (stringBuilder == null) {
-            stringBuilder = (XSStringBuilder) builderFactory.getBuilder(XSString.TYPE_NAME);
+            stringBuilder = (XSStringBuilder)builderFactory.getBuilder(XSString.TYPE_NAME);
         }
 
         Attribute attribute = attributeV1Builder.buildObject();
         attribute.setAttributeName(attributeName);
         attribute.setAttributeNamespace(attributeUrn);
-
-        for (String value : values) {
-            XSString attribute1 =
+        
+        for (Object value : values) {
+            if (value instanceof String) {
+                XSString attribute1 = 
                     stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
-            attribute1.setValue(value);
-            attribute.getAttributeValues().add(attribute1);
+                attribute1.setValue((String)value);
+                attribute.getAttributeValues().add(attribute1);
+            } else if (value instanceof XMLObject) {
+                attribute.getAttributeValues().add((XMLObject)value);
+            }
         }
 
         return attribute;
@@ -388,27 +479,28 @@ public class SAML1ComponentBuilder {
     /**
      * Create SAML 1.1 Authorization Decision Statement(s)
      *
-     * @param decisionData of type List<AuthDecisionStatementBean>
+     * @param decisionData        of type List<AuthDecisionStatementBean>
      * @return a list of SAML 1.1 Authorization Decision Statement(s)
      */
     @SuppressWarnings("unchecked")
     public static List<AuthorizationDecisionStatement> createSamlv1AuthorizationDecisionStatement(
-            List<AuthDecisionStatementBean> decisionData)
-            throws org.opensaml.xml.security.SecurityException, WSSecurityException {
-        List<AuthorizationDecisionStatement> authDecisionStatements = new ArrayList();
+            List<AuthDecisionStatementBean> decisionData) 
+        throws org.opensaml.xml.security.SecurityException, WSSecurityException {
+        List<AuthorizationDecisionStatement> authDecisionStatements = 
+                new ArrayList<AuthorizationDecisionStatement>();
         if (authorizationDecisionStatementV1Builder == null) {
-            authorizationDecisionStatementV1Builder =
-                    (SAMLObjectBuilder<AuthorizationDecisionStatement>)
-                            builderFactory.getBuilder(AuthorizationDecisionStatement.DEFAULT_ELEMENT_NAME);
-
+            authorizationDecisionStatementV1Builder = 
+                (SAMLObjectBuilder<AuthorizationDecisionStatement>) 
+                    builderFactory.getBuilder(AuthorizationDecisionStatement.DEFAULT_ELEMENT_NAME);
+            
         }
 
         if (decisionData != null && decisionData.size() > 0) {
             for (AuthDecisionStatementBean decisionStatementBean : decisionData) {
-                AuthorizationDecisionStatement authDecision =
-                        authorizationDecisionStatementV1Builder.buildObject();
-                Subject authDecisionSubject =
-                        SAML1ComponentBuilder.createSaml1v1Subject(decisionStatementBean.getSubject());
+                AuthorizationDecisionStatement authDecision = 
+                    authorizationDecisionStatementV1Builder.buildObject();
+                Subject authDecisionSubject = 
+                    SAML1ComponentBuilder.createSaml1v1Subject(decisionStatementBean.getSubject());
                 authDecision.setSubject(authDecisionSubject);
 
                 authDecision.setResource(decisionStatementBean.getResource());
@@ -418,6 +510,11 @@ public class SAML1ComponentBuilder {
                     Action actionElement = createSamlv1Action(actionBean);
                     authDecision.getActions().add(actionElement);
                 }
+                
+                if (decisionStatementBean.getEvidence() instanceof Evidence) {                                    
+                    authDecision.setEvidence((Evidence)decisionStatementBean.getEvidence());
+                }
+                
                 authDecisionStatements.add(authDecision);
             }
         }
@@ -435,7 +532,7 @@ public class SAML1ComponentBuilder {
     public static Action createSamlv1Action(ActionBean actionBean) {
         if (actionElementV1Builder == null) {
             actionElementV1Builder = (SAMLObjectBuilder<Action>)
-                    builderFactory.getBuilder(Action.DEFAULT_ELEMENT_NAME);
+                builderFactory.getBuilder(Action.DEFAULT_ELEMENT_NAME);
         }
 
         Action actionElement = actionElementV1Builder.buildObject();
@@ -452,7 +549,7 @@ public class SAML1ComponentBuilder {
      * @return DecisionTypeEnumeration
      */
     private static DecisionTypeEnumeration transformDecisionType(
-            AuthDecisionStatementBean.Decision decision
+        AuthDecisionStatementBean.Decision decision
     ) {
         DecisionTypeEnumeration decisionTypeEnum = DecisionTypeEnumeration.DENY;
         if (decision.equals(AuthDecisionStatementBean.Decision.PERMIT)) {

Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML1Constants.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML1Constants.java?rev=1237808&r1=1237807&r2=1237808&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML1Constants.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML1Constants.java Mon Jan 30 17:22:39 2012
@@ -27,54 +27,54 @@ package org.swssf.wss.impl.saml.builder;
  * Created on May 18, 2009
  */
 public class SAML1Constants {
-
+    
     //
     // NAME ID FORMAT
     //
-
-    public static final String NAMEID_FORMAT_UNSPECIFIED =
-            "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified";
-
-    public static final String NAMEID_FORMAT_EMAIL_ADDRESS =
-            "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress";
-
-    public static final String NAMEID_FORMAT_X509_SUBJECT_NAME =
-            "urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName";
-
-    public static final String NAMEID_FORMAT_WINDOWS_DQN =
-            "urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName";
+    
+    public static final String NAMEID_FORMAT_UNSPECIFIED = 
+        "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified";
+    
+    public static final String NAMEID_FORMAT_EMAIL_ADDRESS = 
+        "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress";
+    
+    public static final String NAMEID_FORMAT_X509_SUBJECT_NAME = 
+        "urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName";
+    
+    public static final String NAMEID_FORMAT_WINDOWS_DQN = 
+        "urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName";
 
     //
     // SUBJECT CONFIRMATION
     // 
-
+    
     /**
      * Assertion Bearer Confirmation Method Identifier
      */
-    public final static String CONF_BEARER =
-            "urn:oasis:names:tc:SAML:1.0:cm:bearer";
+    public final static String CONF_BEARER = 
+        "urn:oasis:names:tc:SAML:1.0:cm:bearer";
 
     /**
      * Holder of Key Confirmation Method Identifier
      */
-    public final static String CONF_HOLDER_KEY =
-            "urn:oasis:names:tc:SAML:1.0:cm:holder-of-key";
+    public final static String CONF_HOLDER_KEY = 
+        "urn:oasis:names:tc:SAML:1.0:cm:holder-of-key";
 
     /**
      * Sender Vouches Confirmation Method Identifier
      */
-    public final static String CONF_SENDER_VOUCHES =
-            "urn:oasis:names:tc:SAML:1.0:cm:sender-vouches";
+    public final static String CONF_SENDER_VOUCHES = 
+        "urn:oasis:names:tc:SAML:1.0:cm:sender-vouches";
 
     //
     // AUTH METHOD
     //
-
+    
     /**
      * The authentication was performed by means of a password.
      */
-    public static final String AUTH_METHOD_PASSWORD =
-            "urn:oasis:names:tc:SAML:1.0:am:password";
+    public static final String AUTH_METHOD_PASSWORD = 
+        "urn:oasis:names:tc:SAML:1.0:am:password";
 
     /**
      * The authentication was performed by means of the Kerberos protocol [RFC 1510],
@@ -83,7 +83,7 @@ public class SAML1Constants {
     public static final String AUTH_METHOD_KERBEROS = "urn:ietf:rfc:1510";
 
     /**
-     * The authentication was performed by means of Secure Remote Password protocol as specified in
+     * The authentication was performed by means of Secure Remote Password protocol as specified in 
      * [RFC 2945].
      */
     public static final String AUTH_METHOD_SRP = "urn:ietf:rfc:2945";
@@ -91,11 +91,11 @@ public class SAML1Constants {
     /**
      * The authentication was performed by means of an unspecified hardware token.
      */
-    public static final String AUTH_METHOD_HARDWARE_TOKEN =
-            "urn:oasis:names:tc:SAML:1.0:am:HardwareToken";
+    public static final String AUTH_METHOD_HARDWARE_TOKEN = 
+        "urn:oasis:names:tc:SAML:1.0:am:HardwareToken";
 
     /**
-     * The authentication was performed using either the SSL or TLS protocol with certificate
+     * The authentication was performed using either the SSL or TLS protocol with certificate 
      * based client authentication. TLS is described in [RFC 2246].
      */
     public static final String AUTH_METHOD_TLS_CLIENT = "urn:ietf:rfc:2246";
@@ -105,32 +105,32 @@ public class SAML1Constants {
      * means of an X.509 PKI [X.500][PKIX]. It may have been one of the mechanisms for which a more
      * specific identifier has been defined.
      */
-    public static final String AUTH_METHOD_X509 =
-            "urn:oasis:names:tc:SAML:1.0:am:X509-PKI";
+    public static final String AUTH_METHOD_X509 = 
+        "urn:oasis:names:tc:SAML:1.0:am:X509-PKI";
 
     /**
-     * The authentication was performed by some (unspecified) mechanism on a key authenticated by
-     * means of a PGP web of trust [PGP]. It may have been one of the mechanisms for which a more
+     * The authentication was performed by some (unspecified) mechanism on a key authenticated by 
+     * means of a PGP web of trust [PGP]. It may have been one of the mechanisms for which a more 
      * specific identifier has been defined.
      */
-    public static final String AUTH_METHOD_PGP =
-            "urn:oasis:names:tc:SAML:1.0:am:PGP";
+    public static final String AUTH_METHOD_PGP = 
+        "urn:oasis:names:tc:SAML:1.0:am:PGP";
 
     /**
-     * The authentication was performed by some (unspecified) mechanism on a key authenticated by
-     * means of a SPKI PKI [SPKI]. It may have been one of the mechanisms for which a more specific
+     * The authentication was performed by some (unspecified) mechanism on a key authenticated by 
+     * means of a SPKI PKI [SPKI]. It may have been one of the mechanisms for which a more specific 
      * identifier has been defined.
      */
-    public static final String AUTH_METHOD_SPKI =
-            "urn:oasis:names:tc:SAML:1.0:am:SPKI";
+    public static final String AUTH_METHOD_SPKI = 
+        "urn:oasis:names:tc:SAML:1.0:am:SPKI";
 
     /**
-     * The authentication was performed by some (unspecified) mechanism on a key authenticated by
+     * The authentication was performed by some (unspecified) mechanism on a key authenticated by 
      * means of a XKMS trust service [XKMS]. It may have been one of the mechanisms for which a more
      * specific identifier has been defined.
      */
-    public static final String AUTH_METHOD_XKMS =
-            "urn:oasis:names:tc:SAML:1.0:am:XKMS";
+    public static final String AUTH_METHOD_XKMS = 
+        "urn:oasis:names:tc:SAML:1.0:am:XKMS";
 
     /**
      * The authentication was performed by means of an XML digital signature [RFC 3075].
@@ -140,6 +140,6 @@ public class SAML1Constants {
     /**
      * The authentication was performed by an unspecified means.
      */
-    public static final String AUTH_METHOD_UNSPECIFIED =
-            "urn:oasis:names:tc:SAML:1.0:am:unspecified";
+    public static final String AUTH_METHOD_UNSPECIFIED = 
+        "urn:oasis:names:tc:SAML:1.0:am:unspecified";
 }

Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML2ComponentBuilder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML2ComponentBuilder.java?rev=1237808&r1=1237807&r2=1237808&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML2ComponentBuilder.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML2ComponentBuilder.java Mon Jan 30 17:22:39 2012
@@ -23,13 +23,45 @@ import org.joda.time.DateTime;
 import org.opensaml.Configuration;
 import org.opensaml.common.SAMLObjectBuilder;
 import org.opensaml.common.SAMLVersion;
-import org.opensaml.saml2.core.*;
+
+import org.opensaml.saml2.core.Action;
+import org.opensaml.saml2.core.Assertion;
+import org.opensaml.saml2.core.Attribute;
+import org.opensaml.saml2.core.AttributeStatement;
+import org.opensaml.saml2.core.AttributeValue;
+import org.opensaml.saml2.core.Audience;
+import org.opensaml.saml2.core.AudienceRestriction;
+import org.opensaml.saml2.core.AuthnContext;
+import org.opensaml.saml2.core.AuthnContextClassRef;
+import org.opensaml.saml2.core.AuthnStatement;
+import org.opensaml.saml2.core.AuthzDecisionStatement;
+import org.opensaml.saml2.core.Conditions;
+import org.opensaml.saml2.core.DecisionTypeEnumeration;
+import org.opensaml.saml2.core.Evidence;
+import org.opensaml.saml2.core.Issuer;
+import org.opensaml.saml2.core.KeyInfoConfirmationDataType;
+import org.opensaml.saml2.core.NameID;
+import org.opensaml.saml2.core.Subject;
+import org.opensaml.saml2.core.SubjectConfirmation;
+import org.opensaml.saml2.core.SubjectConfirmationData;
+import org.opensaml.saml2.core.SubjectLocality;
+
+import org.opensaml.xml.XMLObject;
 import org.opensaml.xml.XMLObjectBuilderFactory;
 import org.opensaml.xml.schema.XSString;
 import org.opensaml.xml.schema.impl.XSStringBuilder;
 import org.opensaml.xml.signature.KeyInfo;
+
 import org.swssf.wss.ext.WSSecurityException;
-import org.swssf.wss.impl.saml.bean.*;
+import org.swssf.wss.impl.saml.bean.ActionBean;
+import org.swssf.wss.impl.saml.bean.AttributeBean;
+import org.swssf.wss.impl.saml.bean.AttributeStatementBean;
+import org.swssf.wss.impl.saml.bean.AuthDecisionStatementBean;
+import org.swssf.wss.impl.saml.bean.AuthenticationStatementBean;
+import org.swssf.wss.impl.saml.bean.ConditionsBean;
+import org.swssf.wss.impl.saml.bean.KeyInfoBean;
+import org.swssf.wss.impl.saml.bean.SubjectBean;
+import org.swssf.wss.impl.saml.bean.SubjectLocalityBean;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -44,42 +76,44 @@ import java.util.UUID;
  */
 public class SAML2ComponentBuilder {
     private static SAMLObjectBuilder<Assertion> assertionBuilder;
-
+    
     private static SAMLObjectBuilder<Issuer> issuerBuilder;
-
+    
     private static SAMLObjectBuilder<Subject> subjectBuilder;
-
+    
     private static SAMLObjectBuilder<NameID> nameIdBuilder;
-
+    
     private static SAMLObjectBuilder<SubjectConfirmation> subjectConfirmationBuilder;
-
+    
     private static SAMLObjectBuilder<Conditions> conditionsBuilder;
-
+    
     private static SAMLObjectBuilder<SubjectConfirmationData> subjectConfirmationDataBuilder;
-
+    
     private static SAMLObjectBuilder<KeyInfoConfirmationDataType> keyInfoConfirmationDataBuilder;
-
+    
     private static SAMLObjectBuilder<AuthnStatement> authnStatementBuilder;
-
+    
     private static SAMLObjectBuilder<AuthnContext> authnContextBuilder;
-
+    
     private static SAMLObjectBuilder<AuthnContextClassRef> authnContextClassRefBuilder;
-
+    
     private static SAMLObjectBuilder<AttributeStatement> attributeStatementBuilder;
-
+    
     private static SAMLObjectBuilder<Attribute> attributeBuilder;
-
+    
     private static XSStringBuilder stringBuilder;
-
+    
     private static SAMLObjectBuilder<AudienceRestriction> audienceRestrictionBuilder;
-
+    
     private static SAMLObjectBuilder<Audience> audienceBuilder;
-
+    
     private static SAMLObjectBuilder<AuthzDecisionStatement> authorizationDecisionStatementBuilder;
-
+    
     private static SAMLObjectBuilder<Action> actionElementBuilder;
-
+    
     private static XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
+    
+    private static SAMLObjectBuilder<SubjectLocality> subjectLocalityBuilder;
 
     /**
      * Create a SAML 2 assertion
@@ -89,18 +123,18 @@ public class SAML2ComponentBuilder {
     @SuppressWarnings("unchecked")
     public static Assertion createAssertion() {
         if (assertionBuilder == null) {
-            assertionBuilder = (SAMLObjectBuilder<Assertion>)
-                    builderFactory.getBuilder(Assertion.DEFAULT_ELEMENT_NAME);
+            assertionBuilder = (SAMLObjectBuilder<Assertion>) 
+                builderFactory.getBuilder(Assertion.DEFAULT_ELEMENT_NAME);
             if (assertionBuilder == null) {
                 throw new IllegalStateException(
-                        "OpenSaml engine not initialized. Please make sure to initialize the OpenSaml engine "
-                                + "prior using it"
+                    "OpenSaml engine not initialized. Please make sure to initialize the OpenSaml engine "
+                    + "prior using it"
                 );
             }
         }
-        Assertion assertion =
-                assertionBuilder.buildObject(Assertion.DEFAULT_ELEMENT_NAME, Assertion.TYPE_NAME);
-        assertion.setID(UUID.randomUUID().toString());
+        Assertion assertion = 
+            assertionBuilder.buildObject(Assertion.DEFAULT_ELEMENT_NAME, Assertion.TYPE_NAME);
+        assertion.setID("_" + UUID.randomUUID().toString());
         assertion.setVersion(SAMLVersion.VERSION_20);
         assertion.setIssueInstant(new DateTime());
         return assertion;
@@ -115,9 +149,9 @@ public class SAML2ComponentBuilder {
     @SuppressWarnings("unchecked")
     public static Issuer createIssuer(String issuerValue) {
         if (issuerBuilder == null) {
-            issuerBuilder = (SAMLObjectBuilder<Issuer>)
-                    builderFactory.getBuilder(Issuer.DEFAULT_ELEMENT_NAME);
-
+            issuerBuilder = (SAMLObjectBuilder<Issuer>) 
+                builderFactory.getBuilder(Issuer.DEFAULT_ELEMENT_NAME);
+            
         }
         Issuer issuer = issuerBuilder.buildObject();
         //
@@ -136,27 +170,27 @@ public class SAML2ComponentBuilder {
     @SuppressWarnings("unchecked")
     public static Conditions createConditions(ConditionsBean conditionsBean) {
         if (conditionsBuilder == null) {
-            conditionsBuilder = (SAMLObjectBuilder<Conditions>)
-                    builderFactory.getBuilder(Conditions.DEFAULT_ELEMENT_NAME);
+            conditionsBuilder = (SAMLObjectBuilder<Conditions>) 
+                builderFactory.getBuilder(Conditions.DEFAULT_ELEMENT_NAME);
         }
-
+        
         Conditions conditions = conditionsBuilder.buildObject();
-
+        
         if (conditionsBean == null) {
             DateTime newNotBefore = new DateTime();
             conditions.setNotBefore(newNotBefore);
             conditions.setNotOnOrAfter(newNotBefore.plusMinutes(5));
             return conditions;
         }
-
+        
         int tokenPeriodMinutes = conditionsBean.getTokenPeriodMinutes();
         DateTime notBefore = conditionsBean.getNotBefore();
         DateTime notAfter = conditionsBean.getNotAfter();
-
+        
         if (notBefore != null && notAfter != null) {
             if (notBefore.isAfter(notAfter)) {
                 throw new IllegalStateException(
-                        "The value of notBefore may not be after the value of notAfter"
+                    "The value of notBefore may not be after the value of notAfter"
                 );
             }
             conditions.setNotBefore(notBefore);
@@ -164,8 +198,18 @@ public class SAML2ComponentBuilder {
         } else {
             DateTime newNotBefore = new DateTime();
             conditions.setNotBefore(newNotBefore);
+            if (tokenPeriodMinutes <= 0) {
+                tokenPeriodMinutes = 5;
+            }
             conditions.setNotOnOrAfter(newNotBefore.plusMinutes(tokenPeriodMinutes));
         }
+        
+        if (conditionsBean.getAudienceURI() != null) {
+            AudienceRestriction audienceRestriction = 
+                createAudienceRestriction(conditionsBean.getAudienceURI());
+            conditions.getAudienceRestrictions().add(audienceRestriction);
+        }
+        
         return conditions;
     }
 
@@ -178,14 +222,14 @@ public class SAML2ComponentBuilder {
     @SuppressWarnings("unchecked")
     public static AudienceRestriction createAudienceRestriction(String audienceURI) {
         if (audienceRestrictionBuilder == null) {
-            audienceRestrictionBuilder = (SAMLObjectBuilder<AudienceRestriction>)
-                    builderFactory.getBuilder(AudienceRestriction.DEFAULT_ELEMENT_NAME);
+            audienceRestrictionBuilder = (SAMLObjectBuilder<AudienceRestriction>) 
+                builderFactory.getBuilder(AudienceRestriction.DEFAULT_ELEMENT_NAME);
         }
         if (audienceBuilder == null) {
-            audienceBuilder = (SAMLObjectBuilder<Audience>)
-                    builderFactory.getBuilder(Audience.DEFAULT_ELEMENT_NAME);
+            audienceBuilder = (SAMLObjectBuilder<Audience>) 
+                builderFactory.getBuilder(Audience.DEFAULT_ELEMENT_NAME);
         }
-
+       
         AudienceRestriction audienceRestriction = audienceRestrictionBuilder.buildObject();
         Audience audience = audienceBuilder.buildObject();
         audience.setAudienceURI(audienceURI);
@@ -201,38 +245,57 @@ public class SAML2ComponentBuilder {
      */
     @SuppressWarnings("unchecked")
     public static List<AuthnStatement> createAuthnStatement(
-            List<AuthenticationStatementBean> authBeans
+        List<AuthenticationStatementBean> authBeans
     ) {
         List<AuthnStatement> authnStatements = new ArrayList<AuthnStatement>();
-
+        
         if (authnStatementBuilder == null) {
-            authnStatementBuilder = (SAMLObjectBuilder<AuthnStatement>)
-                    builderFactory.getBuilder(AuthnStatement.DEFAULT_ELEMENT_NAME);
+            authnStatementBuilder = (SAMLObjectBuilder<AuthnStatement>) 
+                builderFactory.getBuilder(AuthnStatement.DEFAULT_ELEMENT_NAME);
         }
         if (authnContextBuilder == null) {
-            authnContextBuilder = (SAMLObjectBuilder<AuthnContext>)
-                    builderFactory.getBuilder(AuthnContext.DEFAULT_ELEMENT_NAME);
+            authnContextBuilder = (SAMLObjectBuilder<AuthnContext>) 
+                builderFactory.getBuilder(AuthnContext.DEFAULT_ELEMENT_NAME);
         }
         if (authnContextClassRefBuilder == null) {
-            authnContextClassRefBuilder = (SAMLObjectBuilder<AuthnContextClassRef>)
-                    builderFactory.getBuilder(AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
+            authnContextClassRefBuilder = (SAMLObjectBuilder<AuthnContextClassRef>) 
+                builderFactory.getBuilder(AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
         }
-
-
+        if (subjectLocalityBuilder == null) {
+            subjectLocalityBuilder = (SAMLObjectBuilder<SubjectLocality>) 
+            builderFactory.getBuilder(SubjectLocality.DEFAULT_ELEMENT_NAME);
+        }
+        
         if (authBeans != null && authBeans.size() > 0) {
             for (AuthenticationStatementBean statementBean : authBeans) {
                 AuthnStatement authnStatement = authnStatementBuilder.buildObject();
-                authnStatement.setAuthnInstant(statementBean.getAuthenticationInstant());
-                //authnStatement.setSessionIndex("b07b804c-7c29-ea16-7300-4f3d6f7928ac");
-
+                DateTime authInstant = statementBean.getAuthenticationInstant();
+                if (authInstant == null) {
+                    authInstant = new DateTime();
+                }
+                authnStatement.setAuthnInstant(authInstant);
+                
+                if (statementBean.getSessionIndex() != null) {
+                    authnStatement.setSessionIndex(statementBean.getSessionIndex());
+                }
+                
                 AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder.buildObject();
                 authnContextClassRef.setAuthnContextClassRef(
-                        transformAuthenticationMethod(statementBean.getAuthenticationMethod())
+                    transformAuthenticationMethod(statementBean.getAuthenticationMethod())
                 );
                 AuthnContext authnContext = authnContextBuilder.buildObject();
                 authnContext.setAuthnContextClassRef(authnContextClassRef);
                 authnStatement.setAuthnContext(authnContext);
 
+                SubjectLocalityBean subjectLocalityBean = statementBean.getSubjectLocality();
+                if (subjectLocalityBean != null) {
+                    SubjectLocality subjectLocality = subjectLocalityBuilder.buildObject();
+                    subjectLocality.setDNSName(subjectLocalityBean.getDnsAddress());
+                    subjectLocality.setAddress(subjectLocalityBean.getIpAddress());
+
+                    authnStatement.setSubjectLocality(subjectLocality);
+                }
+                
                 authnStatements.add(authnStatement);
             }
         }
@@ -241,9 +304,8 @@ public class SAML2ComponentBuilder {
     }
 
     /**
-     * Transform the user-supplied authentication method value into one of the supported
+     * Transform the user-supplied authentication method value into one of the supported 
      * specification-compliant values.
-     * NOTE: Only "Password" is supported at this time.
      *
      * @param sourceMethod of type String
      * @return String
@@ -253,6 +315,8 @@ public class SAML2ComponentBuilder {
 
         if ("Password".equalsIgnoreCase(sourceMethod)) {
             transformedMethod = SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD;
+        } else if (sourceMethod != null && !"".equals(sourceMethod)) {
+            return sourceMethod;
         }
 
         return transformedMethod;
@@ -265,17 +329,38 @@ public class SAML2ComponentBuilder {
      * @param name         of type String
      * @param values       of type ArrayList
      * @return a SAML2 Attribute
+     * @deprecated
      */
     public static Attribute createAttribute(String friendlyName, String name, List<String> values) {
+        return createAttribute(friendlyName, name, null, values);
+    }
+    
+    /**
+     * Create a SAML2 Attribute
+     *
+     * @param friendlyName of type String
+     * @param name         of type String
+     * @param nameFormat   of type String
+     * @param values       of type ArrayList
+     * @return a SAML2 Attribute
+     */
+    public static Attribute createAttribute(
+        String friendlyName, String name, String nameFormat, List<?> values
+    ) {
         if (stringBuilder == null) {
-            stringBuilder = (XSStringBuilder) builderFactory.getBuilder(XSString.TYPE_NAME);
+            stringBuilder = (XSStringBuilder)builderFactory.getBuilder(XSString.TYPE_NAME);
         }
-        Attribute attribute = createAttribute(friendlyName, name);
-        for (String value : values) {
-            XSString attributeValue =
+        Attribute attribute = createAttribute(friendlyName, name, nameFormat);
+        
+        for (Object value : values) {
+            if (value instanceof String) {
+                XSString attributeValue = 
                     stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
-            attributeValue.setValue(value);
-            attribute.getAttributeValues().add(attributeValue);
+                attributeValue.setValue((String)value);
+                attribute.getAttributeValues().add(attributeValue);
+            } else if (value instanceof XMLObject) {
+                attribute.getAttributeValues().add((XMLObject)value);
+            }
         }
 
         return attribute;
@@ -288,72 +373,75 @@ public class SAML2ComponentBuilder {
      * @return a Subject
      */
     @SuppressWarnings("unchecked")
-    public static Subject createSaml2Subject(SubjectBean subjectBean)
-            throws org.opensaml.xml.security.SecurityException, WSSecurityException {
+    public static Subject createSaml2Subject(SubjectBean subjectBean) 
+        throws org.opensaml.xml.security.SecurityException, WSSecurityException {
         if (subjectBuilder == null) {
-            subjectBuilder = (SAMLObjectBuilder<Subject>)
-                    builderFactory.getBuilder(Subject.DEFAULT_ELEMENT_NAME);
+            subjectBuilder = (SAMLObjectBuilder<Subject>) 
+                builderFactory.getBuilder(Subject.DEFAULT_ELEMENT_NAME);
         }
         Subject subject = subjectBuilder.buildObject();
-
+        
         NameID nameID = SAML2ComponentBuilder.createNameID(subjectBean);
         subject.setNameID(nameID);
-
-        SubjectConfirmationData subjectConfData =
+        
+        SubjectConfirmationData subjectConfData = null;
+        if (subjectBean.getKeyInfo() != null) {
+            subjectConfData = 
                 SAML2ComponentBuilder.createSubjectConfirmationData(
-                        null,
-                        null,
-                        null,
-                        subjectBean.getKeyInfo()
+                    null, 
+                    null, 
+                    null, 
+                    subjectBean.getKeyInfo() 
                 );
-
+        }
+        
         String confirmationMethodStr = subjectBean.getSubjectConfirmationMethod();
         if (confirmationMethodStr == null) {
             confirmationMethodStr = SAML2Constants.CONF_SENDER_VOUCHES;
         }
-        SubjectConfirmation subjectConfirmation =
-                SAML2ComponentBuilder.createSubjectConfirmation(
-                        confirmationMethodStr, subjectConfData
-                );
-
+        SubjectConfirmation subjectConfirmation = 
+            SAML2ComponentBuilder.createSubjectConfirmation(
+                confirmationMethodStr, subjectConfData
+            );
+        
         subject.getSubjectConfirmations().add(subjectConfirmation);
         return subject;
     }
-
+    
     /**
      * Create a SubjectConfirmationData object
      *
      * @param inResponseTo of type String
      * @param recipient    of type String
      * @param notOnOrAfter of type DateTime
-     * @param keyInfoBean  of type KeyInfoBean
+     * @param keyInfoBean of type KeyInfoBean
      * @return a SubjectConfirmationData object
      */
     @SuppressWarnings("unchecked")
     public static SubjectConfirmationData createSubjectConfirmationData(
-            String inResponseTo,
-            String recipient,
-            DateTime notOnOrAfter,
-            KeyInfoBean keyInfoBean
+        String inResponseTo, 
+        String recipient, 
+        DateTime notOnOrAfter,
+        KeyInfoBean keyInfoBean
     ) throws org.opensaml.xml.security.SecurityException, WSSecurityException {
         SubjectConfirmationData subjectConfirmationData = null;
         KeyInfo keyInfo = null;
         if (keyInfoBean == null) {
             if (subjectConfirmationDataBuilder == null) {
-                subjectConfirmationDataBuilder = (SAMLObjectBuilder<SubjectConfirmationData>)
-                        builderFactory.getBuilder(SubjectConfirmationData.DEFAULT_ELEMENT_NAME);
+                subjectConfirmationDataBuilder = (SAMLObjectBuilder<SubjectConfirmationData>) 
+                    builderFactory.getBuilder(SubjectConfirmationData.DEFAULT_ELEMENT_NAME);
             }
             subjectConfirmationData = subjectConfirmationDataBuilder.buildObject();
         } else {
             if (keyInfoConfirmationDataBuilder == null) {
-                keyInfoConfirmationDataBuilder = (SAMLObjectBuilder<KeyInfoConfirmationDataType>)
-                        builderFactory.getBuilder(KeyInfoConfirmationDataType.TYPE_NAME);
+                keyInfoConfirmationDataBuilder = (SAMLObjectBuilder<KeyInfoConfirmationDataType>) 
+                    builderFactory.getBuilder(KeyInfoConfirmationDataType.TYPE_NAME);
             }
             subjectConfirmationData = keyInfoConfirmationDataBuilder.buildObject();
             keyInfo = SAML1ComponentBuilder.createKeyInfo(keyInfoBean);
-            ((KeyInfoConfirmationDataType) subjectConfirmationData).getKeyInfos().add(keyInfo);
+            ((KeyInfoConfirmationDataType)subjectConfirmationData).getKeyInfos().add(keyInfo);
         }
-
+        
         if (inResponseTo != null) {
             subjectConfirmationData.setInResponseTo(inResponseTo);
         }
@@ -363,31 +451,31 @@ public class SAML2ComponentBuilder {
         if (notOnOrAfter != null) {
             subjectConfirmationData.setNotOnOrAfter(notOnOrAfter);
         }
-
+        
         return subjectConfirmationData;
     }
-
+    
     /**
      * Create a SubjectConfirmation object
      * One of the following subject confirmation methods MUST be used:
-     * urn:oasis:names:tc:SAML:2.0:cm:holder-of-key
-     * urn:oasis:names:tc:SAML:2.0:cm:sender-vouches
-     * urn:oasis:names:tc:SAML:2.0:cm:bearer
+     *   urn:oasis:names:tc:SAML:2.0:cm:holder-of-key
+     *   urn:oasis:names:tc:SAML:2.0:cm:sender-vouches
+     *   urn:oasis:names:tc:SAML:2.0:cm:bearer
      *
-     * @param method                  of type String
+     * @param method of type String
      * @param subjectConfirmationData of type SubjectConfirmationData
      * @return a SubjectConfirmation object
      */
     @SuppressWarnings("unchecked")
     public static SubjectConfirmation createSubjectConfirmation(
-            String method,
-            SubjectConfirmationData subjectConfirmationData
+        String method,
+        SubjectConfirmationData subjectConfirmationData
     ) {
         if (subjectConfirmationBuilder == null) {
-            subjectConfirmationBuilder = (SAMLObjectBuilder<SubjectConfirmation>)
-                    builderFactory.getBuilder(SubjectConfirmation.DEFAULT_ELEMENT_NAME);
+            subjectConfirmationBuilder = (SAMLObjectBuilder<SubjectConfirmation>) 
+                builderFactory.getBuilder(SubjectConfirmation.DEFAULT_ELEMENT_NAME);
         }
-
+        
         SubjectConfirmation subjectConfirmation = subjectConfirmationBuilder.buildObject();
         subjectConfirmation.setMethod(method);
         subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData);
@@ -397,14 +485,14 @@ public class SAML2ComponentBuilder {
     /**
      * Create a NameID object
      * One of the following formats MUST be used:
-     * urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
-     * urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
-     * urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName
-     * urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName
-     * urn:oasis:names:tc:SAML:2.0:nameid-format:kerberos
-     * urn:oasis:names:tc:SAML:2.0:nameid-format:entity
-     * urn:oasis:names:tc:SAML:2.0:nameid-format:persistent
-     * urn:oasis:names:tc:SAML:2.0:nameid-format:transient
+     *   urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
+     *   urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
+     *   urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName
+     *   urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName
+     *   urn:oasis:names:tc:SAML:2.0:nameid-format:kerberos
+     *   urn:oasis:names:tc:SAML:2.0:nameid-format:entity
+     *   urn:oasis:names:tc:SAML:2.0:nameid-format:persistent
+     *   urn:oasis:names:tc:SAML:2.0:nameid-format:transient
      *
      * @param subject A SubjectBean instance
      * @return NameID
@@ -412,12 +500,12 @@ public class SAML2ComponentBuilder {
     @SuppressWarnings("unchecked")
     public static NameID createNameID(SubjectBean subject) {
         if (nameIdBuilder == null) {
-            nameIdBuilder = (SAMLObjectBuilder<NameID>)
-                    builderFactory.getBuilder(NameID.DEFAULT_ELEMENT_NAME);
+            nameIdBuilder = (SAMLObjectBuilder<NameID>) 
+                builderFactory.getBuilder(NameID.DEFAULT_ELEMENT_NAME);
         }
         NameID nameID = nameIdBuilder.buildObject();
         nameID.setNameQualifier(subject.getSubjectNameQualifier());
-        nameID.setFormat(NameID.UNSPECIFIED);
+        nameID.setFormat(subject.getSubjectNameIDFormat());
         nameID.setValue(subject.getSubjectName());
         return nameID;
     }
@@ -431,24 +519,29 @@ public class SAML2ComponentBuilder {
      */
     @SuppressWarnings("unchecked")
     public static List<AttributeStatement> createAttributeStatement(
-            List<AttributeStatementBean> attributeData
+        List<AttributeStatementBean> attributeData
     ) {
         List<AttributeStatement> attributeStatements = new ArrayList<AttributeStatement>();
         if (attributeStatementBuilder == null) {
-            attributeStatementBuilder = (SAMLObjectBuilder<AttributeStatement>)
-                    builderFactory.getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME);
+            attributeStatementBuilder = (SAMLObjectBuilder<AttributeStatement>) 
+            builderFactory.getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME);
         }
 
         if (attributeData != null && attributeData.size() > 0) {
             for (AttributeStatementBean statementBean : attributeData) {
                 AttributeStatement attributeStatement = attributeStatementBuilder.buildObject();
                 for (AttributeBean values : statementBean.getSamlAttributes()) {
-                    Attribute samlAttribute =
-                            createAttribute(
-                                    values.getSimpleName(),
-                                    values.getQualifiedName(),
-                                    values.getAttributeValues()
-                            );
+                    List<?> attributeValues = values.getAttributeValues();
+                    if (attributeValues == null || attributeValues.isEmpty()) {
+                        attributeValues = values.getCustomAttributeValues();
+                    }
+                    Attribute samlAttribute = 
+                        createAttribute(
+                            values.getSimpleName(), 
+                            values.getQualifiedName(),
+                            values.getNameFormat(),
+                            attributeValues
+                        );
                     attributeStatement.getAttributes().add(samlAttribute);
                 }
                 // Add the completed attribute statementBean to the collection
@@ -461,24 +554,41 @@ public class SAML2ComponentBuilder {
 
     /**
      * Create an Attribute object. The name format is of type:
-     * urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified
-     * urn:oasis:names:tc:SAML:2.0:attrname-format:uri
-     * urn:oasis:names:tc:SAML:2.0:attrname-format:basic
+     *   urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified
+     *   urn:oasis:names:tc:SAML:2.0:attrname-format:uri
+     *   urn:oasis:names:tc:SAML:2.0:attrname-format:basic
      *
      * @param friendlyName of type String
-     * @param name         of type String
+     * @param name of type String
      * @return an Attribute object
+     * @deprecated
      */
-    @SuppressWarnings("unchecked")
     public static Attribute createAttribute(String friendlyName, String name) {
+        return createAttribute(friendlyName, name, (String)null);
+    }
+    
+    /**
+     * Create an Attribute object.
+     *
+     * @param friendlyName of type String
+     * @param name of type String
+     * @param nameFormat of type String
+     * @return an Attribute object
+     */
+    @SuppressWarnings("unchecked")
+    public static Attribute createAttribute(String friendlyName, String name, String nameFormat) {
         if (attributeBuilder == null) {
             attributeBuilder = (SAMLObjectBuilder<Attribute>)
-                    builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
+                builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
         }
-
+        
         Attribute attribute = attributeBuilder.buildObject();
         attribute.setFriendlyName(friendlyName);
-        attribute.setNameFormat(SAML2Constants.ATTRNAME_FORMAT_URI);
+        if (nameFormat == null) {
+            attribute.setNameFormat(SAML2Constants.ATTRNAME_FORMAT_URI);
+        } else {
+            attribute.setNameFormat(nameFormat);
+        }
         attribute.setName(name);
         return attribute;
     }
@@ -491,28 +601,34 @@ public class SAML2ComponentBuilder {
      */
     @SuppressWarnings("unchecked")
     public static List<AuthzDecisionStatement> createAuthorizationDecisionStatement(
-            List<AuthDecisionStatementBean> decisionData
+        List<AuthDecisionStatementBean> decisionData
     ) {
-        List<AuthzDecisionStatement> authDecisionStatements = new ArrayList();
+        List<AuthzDecisionStatement> authDecisionStatements = 
+                new ArrayList<AuthzDecisionStatement>();
         if (authorizationDecisionStatementBuilder == null) {
-            authorizationDecisionStatementBuilder =
-                    (SAMLObjectBuilder<AuthzDecisionStatement>)
-                            builderFactory.getBuilder(AuthzDecisionStatement.DEFAULT_ELEMENT_NAME);
+            authorizationDecisionStatementBuilder = 
+                (SAMLObjectBuilder<AuthzDecisionStatement>)
+                    builderFactory.getBuilder(AuthzDecisionStatement.DEFAULT_ELEMENT_NAME);
         }
 
         if (decisionData != null && decisionData.size() > 0) {
             for (AuthDecisionStatementBean decisionStatementBean : decisionData) {
-                AuthzDecisionStatement authDecision =
-                        authorizationDecisionStatementBuilder.buildObject();
+                AuthzDecisionStatement authDecision = 
+                    authorizationDecisionStatementBuilder.buildObject();
                 authDecision.setResource(decisionStatementBean.getResource());
                 authDecision.setDecision(
-                        transformDecisionType(decisionStatementBean.getDecision())
+                    transformDecisionType(decisionStatementBean.getDecision())
                 );
 
                 for (ActionBean actionBean : decisionStatementBean.getActions()) {
                     Action actionElement = createSamlAction(actionBean);
                     authDecision.getActions().add(actionElement);
                 }
+
+                if (decisionStatementBean.getEvidence() instanceof Evidence) {                                    
+                    authDecision.setEvidence((Evidence)decisionStatementBean.getEvidence());
+                }
+                
                 authDecisionStatements.add(authDecision);
             }
         }
@@ -531,10 +647,13 @@ public class SAML2ComponentBuilder {
     public static Action createSamlAction(ActionBean actionBean) {
         if (actionElementBuilder == null) {
             actionElementBuilder = (SAMLObjectBuilder<Action>)
-                    builderFactory.getBuilder(Action.DEFAULT_ELEMENT_NAME);
+                builderFactory.getBuilder(Action.DEFAULT_ELEMENT_NAME);
         }
         Action actionElement = actionElementBuilder.buildObject();
         actionElement.setNamespace(actionBean.getActionNamespace());
+        if (actionBean.getActionNamespace() == null) {
+            actionElement.setNamespace("urn:oasis:names:tc:SAML:1.0:action:rwedc-negation");
+        }
         actionElement.setAction(actionBean.getContents());
 
         return actionElement;
@@ -544,10 +663,10 @@ public class SAML2ComponentBuilder {
      * Create a DecisionTypeEnumeration object
      *
      * @param decision of type Decision
-     * @return a DecisionTypeEnumeration object
+     * @return a DecisionTypeEnumeration object 
      */
     private static DecisionTypeEnumeration transformDecisionType(
-            AuthDecisionStatementBean.Decision decision
+        AuthDecisionStatementBean.Decision decision
     ) {
         DecisionTypeEnumeration decisionTypeEnum = DecisionTypeEnumeration.DENY;
         if (decision.equals(AuthDecisionStatementBean.Decision.PERMIT)) {

Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML2Constants.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML2Constants.java?rev=1237808&r1=1237807&r2=1237808&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML2Constants.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/saml/builder/SAML2Constants.java Mon Jan 30 17:22:39 2012
@@ -30,133 +30,133 @@ public class SAML2Constants {
     //
     // NAME ID FORMAT
     //
-
-    public static final String NAMEID_FORMAT_UNSPECIFIED =
-            "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified";
-
-    public static final String NAMEID_FORMAT_EMAIL_ADDRESS =
-            "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress";
-
-    public static final String NAMEID_FORMAT_X509_SUBJECT_NAME =
-            "urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName";
-
-    public static final String NAMEID_FORMAT_WINDOWS_DQN =
-            "urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName";
-
-    public static final String NAMEID_FORMAT_KERBEROS =
-            "urn:oasis:names:tc:SAML:2.0:nameid-format:kerberos";
-
-    public static final String NAMEID_FORMAT_ENTITY =
-            "urn:oasis:names:tc:SAML:2.0:nameid-format:entity";
-
-    public static final String NAMEID_FORMAT_PERSISTENT =
-            "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent";
-
-    public static final String NAMEID_FORMAT_TRANSIENT =
-            "urn:oasis:names:tc:SAML:2.0:nameid-format:transient";
+    
+    public static final String NAMEID_FORMAT_UNSPECIFIED = 
+        "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified";
+    
+    public static final String NAMEID_FORMAT_EMAIL_ADDRESS = 
+        "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress";
+    
+    public static final String NAMEID_FORMAT_X509_SUBJECT_NAME = 
+        "urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName";
+    
+    public static final String NAMEID_FORMAT_WINDOWS_DQN = 
+        "urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName";
+    
+    public static final String NAMEID_FORMAT_KERBEROS = 
+        "urn:oasis:names:tc:SAML:2.0:nameid-format:kerberos";
+    
+    public static final String NAMEID_FORMAT_ENTITY = 
+        "urn:oasis:names:tc:SAML:2.0:nameid-format:entity";
+    
+    public static final String NAMEID_FORMAT_PERSISTENT = 
+        "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent";
+    
+    public static final String NAMEID_FORMAT_TRANSIENT = 
+        "urn:oasis:names:tc:SAML:2.0:nameid-format:transient";
 
     //
     // SUBJECT CONFIRMATION
     //
-
-    public static final String CONF_BEARER =
-            "urn:oasis:names:tc:SAML:2.0:cm:bearer";
-
-    public static final String CONF_HOLDER_KEY =
-            "urn:oasis:names:tc:SAML:2.0:cm:holder-of-key";
-
-    public static final String CONF_SENDER_VOUCHES =
-            "urn:oasis:names:tc:SAML:2.0:cm:sender-vouches";
-
+    
+    public static final String CONF_BEARER = 
+        "urn:oasis:names:tc:SAML:2.0:cm:bearer";
+    
+    public static final String CONF_HOLDER_KEY = 
+        "urn:oasis:names:tc:SAML:2.0:cm:holder-of-key";
+    
+    public static final String CONF_SENDER_VOUCHES = 
+        "urn:oasis:names:tc:SAML:2.0:cm:sender-vouches";
+    
     //
     // AUTH CONTEXT CLASS REF
     //
-
-    public static final String AUTH_CONTEXT_CLASS_REF_INTERNET_PROTOCOL =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:InternetProtocol";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_INTERNET_PROTOCOL_PASSWORD =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:InternetProtocolPassword";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_KERBEROS =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:Kerberos";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_MOBILE_ONE_FACTOR_UNREGISTERED =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:MobileOneFactorUnregistered";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_MOBILE_TWO_FACTOR_UNREGISTERED =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:MobileTwoFactorUnregistered";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_MOBILE_ONE_FACTOR_CONTRACT =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:MobileOneFactorContract";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_MOBILE_TWO_FACTOR_CONTRACT =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:MobileTwoFactorContract";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_PASSWORD =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:Password";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_PASSWORD_PROTECTED_TRANSPORT =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_PREVIOUS_SESSION =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:PreviousSession";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_X509 =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:X509";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_PGP =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:PGP";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_SPKI =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:SPKI";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_XMLDSIG =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:XMLDSig";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_SMARTCARD =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:Smartcard";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_SMARTCARD_PKI =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:SmartcardPKI";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_SOFTWARE_PKI =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:SoftwarePKI";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_TELEPHONY =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:Telephony";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_NOMAD_TELEPHONY =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:NomadTelephony";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_PERSONAL_TELEPHONY =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:PersonalTelephony";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_AUTHENTICATED_TELEPHONY =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:AuthenticatedTelephony";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_SECURED_REMOTE_PASSWORD =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:SecureRemotePassword";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_TLS_CLIENT =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:TLSClient";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_TIME_SYNC_TOKEN =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:TimeSyncToken";
-
-    public static final String AUTH_CONTEXT_CLASS_REF_UNSPECIFIED =
-            "urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_INTERNET_PROTOCOL = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:InternetProtocol";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_INTERNET_PROTOCOL_PASSWORD = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:InternetProtocolPassword";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_KERBEROS = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:Kerberos";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_MOBILE_ONE_FACTOR_UNREGISTERED = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:MobileOneFactorUnregistered";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_MOBILE_TWO_FACTOR_UNREGISTERED = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:MobileTwoFactorUnregistered";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_MOBILE_ONE_FACTOR_CONTRACT = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:MobileOneFactorContract";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_MOBILE_TWO_FACTOR_CONTRACT = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:MobileTwoFactorContract";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_PASSWORD = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:Password";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_PASSWORD_PROTECTED_TRANSPORT = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_PREVIOUS_SESSION = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:PreviousSession";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_X509 = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:X509";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_PGP = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:PGP";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_SPKI = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:SPKI";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_XMLDSIG = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:XMLDSig";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_SMARTCARD = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:Smartcard";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_SMARTCARD_PKI = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:SmartcardPKI";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_SOFTWARE_PKI = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:SoftwarePKI";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_TELEPHONY = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:Telephony";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_NOMAD_TELEPHONY = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:NomadTelephony";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_PERSONAL_TELEPHONY = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:PersonalTelephony";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_AUTHENTICATED_TELEPHONY = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:AuthenticatedTelephony";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_SECURED_REMOTE_PASSWORD = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:SecureRemotePassword";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_TLS_CLIENT = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:TLSClient";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_TIME_SYNC_TOKEN = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:TimeSyncToken";
+    
+    public static final String AUTH_CONTEXT_CLASS_REF_UNSPECIFIED = 
+        "urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified";
 
     //
     // ATTRIBUTE NAME FORMAT
     //
-
-    public static final String ATTRNAME_FORMAT_UNSPECIFIED =
-            "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified";
-
-    public static final String ATTRNAME_FORMAT_URI =
-            "urn:oasis:names:tc:SAML:2.0:attrname-format:uri";
-
-    public static final String ATTRNAME_FORMAT_BASIC =
-            "urn:oasis:names:tc:SAML:2.0:attrname-format:basic";
+    
+    public static final String ATTRNAME_FORMAT_UNSPECIFIED = 
+        "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified";
+    
+    public static final String ATTRNAME_FORMAT_URI = 
+        "urn:oasis:names:tc:SAML:2.0:attrname-format:uri";
+    
+    public static final String ATTRNAME_FORMAT_BASIC = 
+        "urn:oasis:names:tc:SAML:2.0:attrname-format:basic";
 }

Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/test/java/org/swssf/wss/test/CallbackHandlerImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/test/java/org/swssf/wss/test/CallbackHandlerImpl.java?rev=1237808&r1=1237807&r2=1237808&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/test/java/org/swssf/wss/test/CallbackHandlerImpl.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/test/java/org/swssf/wss/test/CallbackHandlerImpl.java Mon Jan 30 17:22:39 2012
@@ -20,12 +20,12 @@ package org.swssf.wss.test;
 
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.message.WSSecEncryptedKey;
-import org.apache.ws.security.saml.ext.builder.SAML2Constants;
 import org.opensaml.common.SAMLVersion;
 import org.swssf.wss.ext.WSPasswordCallback;
 import org.swssf.wss.impl.saml.SAMLCallback;
 import org.swssf.wss.impl.saml.bean.*;
 import org.swssf.wss.impl.saml.builder.SAML1Constants;
+import org.swssf.wss.impl.saml.builder.SAML2Constants;
 import org.swssf.xmlsec.crypto.CryptoBase;
 import org.swssf.xmlsec.crypto.Merlin;
 import org.w3c.dom.Document;
@@ -40,6 +40,7 @@ import java.io.IOException;
 import java.security.KeyStore;
 import java.security.cert.X509Certificate;
 import java.util.Collections;
+import java.util.List;
 
 /**
  * @author $Author$
@@ -63,6 +64,13 @@ public class CallbackHandlerImpl impleme
     private byte[] ephemeralKey = null;
     private String issuer = null;
     private SAMLVersion samlVersion = SAMLVersion.VERSION_11;
+    
+    private String subjectNameIDFormat = null;
+    private String subjectLocalityIpAddress = null;
+    private String subjectLocalityDnsAddress = null;
+    private String resource = null;
+    private List<?> customAttributeValues = null;
+    private ConditionsBean conditions = null;
 
     private boolean signAssertion = true;
 
@@ -106,41 +114,34 @@ public class CallbackHandlerImpl impleme
                 samlCallback.setIssuerKeyName("samlissuer");
                 samlCallback.setIssuerKeyPassword("default");
                 samlCallback.setSignAssertion(this.signAssertion);
+                samlCallback.setIssuer(issuer);
+                
+                if (conditions != null) {
+                    samlCallback.setConditions(conditions);
+                }
+                
+                SubjectBean subjectBean =
+                        new SubjectBean(subjectName, subjectQualifier, confirmationMethod);
+                if (subjectNameIDFormat != null) {
+                    subjectBean.setSubjectNameIDFormat(subjectNameIDFormat);
+                }
+                
+                if (SAML1Constants.CONF_HOLDER_KEY.equals(confirmationMethod)
+                        || SAML2Constants.CONF_HOLDER_KEY.equals(confirmationMethod)) {
+                    try {
+                        KeyInfoBean keyInfo = createKeyInfo();
+                        subjectBean.setKeyInfo(keyInfo);
+                    } catch (Exception ex) {
+                        throw new IOException("Problem creating KeyInfo: " + ex.getMessage());
+                    }
+                }
+                samlCallback.setSubject(subjectBean);
 
                 if (getSamlVersion() == SAMLVersion.VERSION_11) {
-
                     samlCallback.setSamlVersion(SAMLVersion.VERSION_11);
-                    samlCallback.setIssuer(issuer);
-                    SubjectBean subjectBean =
-                            new SubjectBean(
-                                    subjectName, subjectQualifier, confirmationMethod
-                            );
-                    if (SAML1Constants.CONF_HOLDER_KEY.equals(confirmationMethod)) {
-                        try {
-                            KeyInfoBean keyInfo = createKeyInfo();
-                            subjectBean.setKeyInfo(keyInfo);
-                        } catch (Exception ex) {
-                            throw new IOException("Problem creating KeyInfo: " + ex.getMessage());
-                        }
-                    }
-                    samlCallback.setSubject(subjectBean);
                     createAndSetStatement(subjectBean, samlCallback);
                 } else {
                     samlCallback.setSamlVersion(SAMLVersion.VERSION_20);
-                    samlCallback.setIssuer(issuer);
-                    SubjectBean subjectBean =
-                            new SubjectBean(
-                                    subjectName, subjectQualifier, confirmationMethod
-                            );
-                    if (SAML2Constants.CONF_HOLDER_KEY.equals(confirmationMethod)) {
-                        try {
-                            KeyInfoBean keyInfo = createKeyInfo();
-                            subjectBean.setKeyInfo(keyInfo);
-                        } catch (Exception ex) {
-                            throw new IOException("Problem creating KeyInfo: " + ex.getMessage());
-                        }
-                    }
-                    samlCallback.setSubject(subjectBean);
                     createAndSetStatement(null, samlCallback);
                 }
             } catch (Exception e) {
@@ -158,16 +159,29 @@ public class CallbackHandlerImpl impleme
             if (subjectBean != null) {
                 authBean.setSubject(subjectBean);
             }
+            if (subjectLocalityIpAddress != null || subjectLocalityDnsAddress != null) {
+                SubjectLocalityBean subjectLocality = new SubjectLocalityBean();
+                subjectLocality.setIpAddress(subjectLocalityIpAddress);
+                subjectLocality.setDnsAddress(subjectLocalityDnsAddress);
+                authBean.setSubjectLocality(subjectLocality);
+            }
             authBean.setAuthenticationMethod("Password");
             callback.setAuthenticationStatementData(Collections.singletonList(authBean));
         } else if (statement == Statement.ATTR) {
             AttributeStatementBean attrBean = new AttributeStatementBean();
+            AttributeBean attributeBean = new AttributeBean();
             if (subjectBean != null) {
                 attrBean.setSubject(subjectBean);
+                attributeBean.setSimpleName("role");
+                attributeBean.setQualifiedName("http://custom-ns");
+            } else {
+                attributeBean.setQualifiedName("role");
+            }
+            if (customAttributeValues != null) {
+                attributeBean.setCustomAttributeValues(customAttributeValues);   
+            } else {
+                attributeBean.setAttributeValues(Collections.singletonList("user"));
             }
-            AttributeBean attributeBean = new AttributeBean();
-            attributeBean.setSimpleName("role");
-            attributeBean.setAttributeValues(Collections.singletonList("user"));
             attrBean.setSamlAttributes(Collections.singletonList(attributeBean));
             callback.setAttributeStatementData(Collections.singletonList(attrBean));
         } else {
@@ -180,6 +194,7 @@ public class CallbackHandlerImpl impleme
             authzBean.setActions(Collections.singletonList(actionBean));
             authzBean.setResource("endpoint");
             authzBean.setDecision(AuthDecisionStatementBean.Decision.PERMIT);
+            authzBean.setResource(resource);
             callback.setAuthDecisionStatementData(Collections.singletonList(authzBean));
         }
     }
@@ -199,7 +214,7 @@ public class CallbackHandlerImpl impleme
 
             // Create an Encrypted Key
             WSSecEncryptedKey encrKey = new WSSecEncryptedKey();
-            encrKey.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);
+            encrKey.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
             encrKey.setUseThisCert(certs[0]);
             encrKey.prepare(doc, null);
             ephemeralKey = encrKey.getEphemeralKey();
@@ -315,4 +330,25 @@ public class CallbackHandlerImpl impleme
     public void setSecret(byte[] secret) {
         this.secret = secret;
     }
+    
+    public void setConditions(ConditionsBean conditionsBean) {
+        this.conditions = conditionsBean;
+    }
+    
+    public void setSubjectNameIDFormat(String subjectNameIDFormat) {
+        this.subjectNameIDFormat = subjectNameIDFormat;
+    }
+    
+    public void setSubjectLocality(String ipAddress, String dnsAddress) {
+        this.subjectLocalityIpAddress = ipAddress;
+        this.subjectLocalityDnsAddress = dnsAddress;
+    }
+    
+    public void setResource(String resource) {
+        this.resource = resource;
+    }
+    
+    public void setCustomAttributeValues(List<?> customAttributeValues) {
+        this.customAttributeValues = customAttributeValues;
+    }
 }