Search in sources :

Example 6 with Assertion

use of com.sun.identity.saml.assertion.Assertion in project OpenAM by OpenRock.

the class SAMLUtils method getListOfAssertions.

/**
     * Gets the list of <code>Assertion</code> objects from a list of
     * 'String' assertions.
     * @param assertions List of assertions in string format
     * @return List of <code>Assertion</code> objects
     */
public static List getListOfAssertions(List assertions) {
    List returnAssertions = new ArrayList();
    try {
        if (assertions != null) {
            Iterator it = assertions.iterator();
            while (it.hasNext()) {
                Document doc = XMLUtils.toDOMDocument((String) it.next(), debug);
                Element root = doc.getDocumentElement();
                if (root != null) {
                    Assertion assertion = new Assertion(root);
                    returnAssertions.add(assertion);
                }
            }
        }
    } catch (Exception e) {
        if (debug.messageEnabled()) {
            debug.message("SAMLUtils.getListOfAssertions : " + "Exception : ", e);
        }
    }
    return returnAssertions;
}
Also used : ArrayList(java.util.ArrayList) CharacterIterator(java.text.CharacterIterator) Iterator(java.util.Iterator) StringCharacterIterator(java.text.StringCharacterIterator) Assertion(com.sun.identity.saml.assertion.Assertion) List(java.util.List) ArrayList(java.util.ArrayList) ServletException(javax.servlet.ServletException) SystemConfigurationException(com.sun.identity.common.SystemConfigurationException) SessionException(com.sun.identity.plugin.session.SessionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 7 with Assertion

use of com.sun.identity.saml.assertion.Assertion in project OpenAM by OpenRock.

the class SAMLUtils method examAssertions.

/**
     * Determines if there is a valid SSO Assertion
     * inside of SAML Response.
     *
     * @param assertions a List of <code>Assertion</code> objects
     * @return a Subject object
     * @exception IOException IOException
     */
public static com.sun.identity.saml.assertion.Subject examAssertions(List assertions) throws IOException {
    if (assertions == null) {
        return null;
    }
    boolean validation = false;
    com.sun.identity.saml.assertion.Subject subject = null;
    Iterator iter = assertions.iterator();
    while (iter.hasNext()) {
        Assertion assertion = (Assertion) iter.next();
        if (!checkCondition(assertion)) {
            return null;
        }
        debug.message("Passed checking Conditions!");
        // exam the Statement inside the Assertion
        Set statements = new HashSet();
        statements = assertion.getStatement();
        if (statements == null || statements.isEmpty()) {
            debug.error(bundle.getString("noStatement"));
            return null;
        }
        Iterator iterator = statements.iterator();
        while (iterator.hasNext()) {
            Statement statement = (Statement) iterator.next();
            subject = ((SubjectStatement) statement).getSubject();
            SubjectConfirmation sc = subject.getSubjectConfirmation();
            Set cm = new HashSet();
            cm = sc.getConfirmationMethod();
            if (cm == null || cm.isEmpty()) {
                debug.error("Subject confirmation method is null");
                return null;
            }
            String conMethod = (String) cm.iterator().next();
            // on Assertion version number
            if ((conMethod != null) && (assertion.getMajorVersion() == SAMLConstants.ASSERTION_MAJOR_VERSION) && (((assertion.getMinorVersion() == SAMLConstants.ASSERTION_MINOR_VERSION_ONE) && conMethod.equals(SAMLConstants.CONFIRMATION_METHOD_ARTIFACT)) || ((assertion.getMinorVersion() == SAMLConstants.ASSERTION_MINOR_VERSION_ZERO) && (conMethod.equals(SAMLConstants.DEPRECATED_CONFIRMATION_METHOD_ARTIFACT))))) {
                if (debug.messageEnabled()) {
                    debug.message("Correct Confirmation method");
                }
            } else {
                debug.error("Wrong Confirmation Method.");
                return null;
            }
            if (statement instanceof AuthenticationStatement) {
                //found an SSO Assertion
                validation = true;
            }
        }
    // end of  while (iterator.hasNext()) for Statements
    }
    if (!validation) {
        debug.error(bundle.getString("noSSOAssertion"));
        return null;
    }
    return subject;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Statement(com.sun.identity.saml.assertion.Statement) AuthenticationStatement(com.sun.identity.saml.assertion.AuthenticationStatement) AttributeStatement(com.sun.identity.saml.assertion.AttributeStatement) SubjectStatement(com.sun.identity.saml.assertion.SubjectStatement) Assertion(com.sun.identity.saml.assertion.Assertion) Subject(com.sun.identity.saml.assertion.Subject) AuthenticationStatement(com.sun.identity.saml.assertion.AuthenticationStatement) SubjectConfirmation(com.sun.identity.saml.assertion.SubjectConfirmation) CharacterIterator(java.text.CharacterIterator) Iterator(java.util.Iterator) StringCharacterIterator(java.text.StringCharacterIterator) HashSet(java.util.HashSet)

Example 8 with Assertion

use of com.sun.identity.saml.assertion.Assertion in project OpenAM by OpenRock.

the class AssertionManagerImpl method createAssertion.

public String createAssertion(String ssoToken) throws SAMLException {
    checkInitialization();
    Object token = null;
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        token = sessionProvider.getSession(ssoToken);
    } catch (SessionException ssoe) {
        if (SAMLUtils.debug.messageEnabled()) {
            SAMLUtils.debug.message("AssertionManagerImpl:createAssertion(SSO) " + ssoe);
        }
        throw (new SAMLException(ssoe.getMessage()));
    }
    Assertion a = assertionManager.createAssertion(token);
    // would be thrown
    return (a.toString(true, true));
}
Also used : Assertion(com.sun.identity.saml.assertion.Assertion) SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 9 with Assertion

use of com.sun.identity.saml.assertion.Assertion in project OpenAM by OpenRock.

the class AssertionManagerImpl method getAssertionByIdRefToken.

public String getAssertionByIdRefToken(String idref, String ssoToken) throws SAMLException {
    checkInitialization();
    Object token = null;
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        token = sessionProvider.getSession(ssoToken);
    } catch (SessionException ssoe) {
        if (SAMLUtils.debug.messageEnabled()) {
            SAMLUtils.debug.message("AssertionManagerImpl:getAssertionByIdRefToken: " + ssoe);
        }
        throw (new SAMLException(ssoe.getMessage()));
    }
    Assertion a = assertionManager.getAssertion(new AssertionIDReference(idref), token);
    return (a.toString(true, true));
}
Also used : Assertion(com.sun.identity.saml.assertion.Assertion) SessionException(com.sun.identity.plugin.session.SessionException) AssertionIDReference(com.sun.identity.saml.assertion.AssertionIDReference) SAMLException(com.sun.identity.saml.common.SAMLException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 10 with Assertion

use of com.sun.identity.saml.assertion.Assertion in project OpenAM by OpenRock.

the class AssertionManagerImpl method getAssertionByIdRef2.

public String getAssertionByIdRef2(String idref, String destID) throws SAMLException {
    checkInitialization();
    Assertion a = assertionManager.getAssertion(new AssertionIDReference(idref), SAMLUtils.byteArrayToString(Base64.decode(destID)));
    return (a.toString(true, true));
}
Also used : Assertion(com.sun.identity.saml.assertion.Assertion) AssertionIDReference(com.sun.identity.saml.assertion.AssertionIDReference)

Aggregations

Assertion (com.sun.identity.saml.assertion.Assertion)32 SAMLException (com.sun.identity.saml.common.SAMLException)18 SessionException (com.sun.identity.plugin.session.SessionException)16 Iterator (java.util.Iterator)9 SessionProvider (com.sun.identity.plugin.session.SessionProvider)7 AssertionIDReference (com.sun.identity.saml.assertion.AssertionIDReference)6 AssertionArtifact (com.sun.identity.saml.protocol.AssertionArtifact)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Set (java.util.Set)6 FSException (com.sun.identity.federation.common.FSException)4 FSAssertion (com.sun.identity.federation.message.FSAssertion)4 AssertionManager (com.sun.identity.saml.AssertionManager)4 Statement (com.sun.identity.saml.assertion.Statement)4 Subject (com.sun.identity.saml.assertion.Subject)4 SubjectConfirmation (com.sun.identity.saml.assertion.SubjectConfirmation)4 SubjectStatement (com.sun.identity.saml.assertion.SubjectStatement)4 Status (com.sun.identity.saml.protocol.Status)4 AttributeStatement (com.sun.identity.saml.assertion.AttributeStatement)3 StatusCode (com.sun.identity.saml.protocol.StatusCode)3