Search in sources :

Example 1 with Condition

use of com.sun.identity.saml2.assertion.Condition in project OpenAM by OpenRock.

the class ConditionsImpl method toXMLString.

/**
    * Returns a String representation
    * @param includeNSPrefix Determines whether or not the namespace 
    *        qualifier is prepended to the Element when converted
    * @param declareNS Determines whether or not the namespace is 
    *        declared within the Element.
    * @return A String representation
    * @exception SAML2Exception if something is wrong during conversion
    */
public String toXMLString(boolean includeNSPrefix, boolean declareNS) throws SAML2Exception {
    StringBuffer sb = new StringBuffer(2000);
    String NS = "";
    String appendNS = "";
    if (declareNS) {
        NS = SAML2Constants.ASSERTION_DECLARE_STR;
    }
    if (includeNSPrefix) {
        appendNS = SAML2Constants.ASSERTION_PREFIX;
    }
    sb.append("<").append(appendNS).append(CONDITIONS_ELEMENT).append(NS);
    String str = null;
    if (notBefore != null) {
        str = DateUtils.toUTCDateFormat(notBefore);
        sb.append(" ").append(NOT_BEFORE_ATTR).append("=\"").append(str).append("\"");
    }
    if (notOnOrAfter != null) {
        str = DateUtils.toUTCDateFormat(notOnOrAfter);
        sb.append(" ").append(NOT_ON_OR_AFTER_ATTR).append("=\"").append(str).append("\"");
    }
    sb.append(">\n");
    int length = 0;
    if (conditions != null) {
        length = conditions.size();
        for (int i = 0; i < length; i++) {
            Condition condition = (Condition) conditions.get(i);
            sb.append(condition.toXMLString(includeNSPrefix, false));
        }
    }
    if (audienceRestrictions != null) {
        length = audienceRestrictions.size();
        for (int i = 0; i < length; i++) {
            AudienceRestriction ar = (AudienceRestriction) audienceRestrictions.get(i);
            sb.append(ar.toXMLString(includeNSPrefix, false));
        }
    }
    if (oneTimeUses != null) {
        length = oneTimeUses.size();
        for (int i = 0; i < length; i++) {
            OneTimeUse ar = (OneTimeUse) oneTimeUses.get(i);
            sb.append(ar.toXMLString(includeNSPrefix, false));
        }
    }
    if (proxyRestrictions != null) {
        length = proxyRestrictions.size();
        for (int i = 0; i < length; i++) {
            ProxyRestriction pr = (ProxyRestriction) proxyRestrictions.get(i);
            sb.append(pr.toXMLString(includeNSPrefix, false));
        }
    }
    sb.append("</").append(appendNS).append(CONDITIONS_ELEMENT).append(">\n");
    return sb.toString();
}
Also used : Condition(com.sun.identity.saml2.assertion.Condition) AudienceRestriction(com.sun.identity.saml2.assertion.AudienceRestriction) OneTimeUse(com.sun.identity.saml2.assertion.OneTimeUse) ProxyRestriction(com.sun.identity.saml2.assertion.ProxyRestriction)

Example 2 with Condition

use of com.sun.identity.saml2.assertion.Condition in project OpenAM by OpenRock.

the class AssertionGen method getCondition.

/**
 *Add condition to the SAML assertion
 *
 */
private Conditions getCondition(String SPEntityID) {
    Conditions conditions = AssertionFactory.getInstance().createConditions();
    AudienceRestriction ar = AssertionFactory.getInstance().createAudienceRestriction();
    List SPIDList = new ArrayList();
    List ARList = new ArrayList();
    try {
        conditions.setNotBefore(new Date());
        SPIDList.add(SPEntityID);
        ar.setAudience(SPIDList);
        ARList.add(ar);
        conditions.setAudienceRestrictions(ARList);
    } catch (SAML2Exception ex) {
        Logger.getLogger(AssertionGen.class.getName()).log(Level.SEVERE, null, ex);
    }
    return conditions;
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 3 with Condition

use of com.sun.identity.saml2.assertion.Condition in project OpenAM by OpenRock.

the class ConditionsImpl method makeImmutable.

/**
    * Makes the object immutable
    */
public void makeImmutable() {
    if (isMutable) {
        if (conditions != null) {
            int length = conditions.size();
            for (int i = 0; i < length; i++) {
                Condition condition = (Condition) conditions.get(i);
                condition.makeImmutable();
            }
            conditions = Collections.unmodifiableList(conditions);
        }
        if (audienceRestrictions != null) {
            int length = audienceRestrictions.size();
            for (int i = 0; i < length; i++) {
                AudienceRestriction ar = (AudienceRestriction) audienceRestrictions.get(i);
                ar.makeImmutable();
            }
            audienceRestrictions = Collections.unmodifiableList(audienceRestrictions);
        }
        if (oneTimeUses != null) {
            int length = oneTimeUses.size();
            for (int i = 0; i < length; i++) {
                OneTimeUse oneTimeUse = (OneTimeUse) oneTimeUses.get(i);
                oneTimeUse.makeImmutable();
            }
            oneTimeUses = Collections.unmodifiableList(oneTimeUses);
        }
        if (proxyRestrictions != null) {
            int length = proxyRestrictions.size();
            for (int i = 0; i < length; i++) {
                ProxyRestriction pr = (ProxyRestriction) proxyRestrictions.get(i);
                pr.makeImmutable();
            }
            proxyRestrictions = Collections.unmodifiableList(proxyRestrictions);
        }
        isMutable = false;
    }
}
Also used : Condition(com.sun.identity.saml2.assertion.Condition) AudienceRestriction(com.sun.identity.saml2.assertion.AudienceRestriction) OneTimeUse(com.sun.identity.saml2.assertion.OneTimeUse) ProxyRestriction(com.sun.identity.saml2.assertion.ProxyRestriction)

Aggregations

AudienceRestriction (com.sun.identity.saml2.assertion.AudienceRestriction)2 Condition (com.sun.identity.saml2.assertion.Condition)2 OneTimeUse (com.sun.identity.saml2.assertion.OneTimeUse)2 ProxyRestriction (com.sun.identity.saml2.assertion.ProxyRestriction)2 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1