Search in sources :

Example 1 with Evidence

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

the class DefaultActionMapper method getSSOAssertion.

/**
     * This method exams the Evidence in the AuthorizationDecisionQuery.
     * It returns the first valid Assertion that contains at least one
     * AuthenticationStatement.
     * <p>
     * @see com.sun.identity.saml.plugins.ActionMapper#getSSOAssertion
     */
public Assertion getSSOAssertion(AuthorizationDecisionQuery query, String sourceID) {
    if (query == null) {
        return null;
    }
    Assertion assertion = null;
    // check evidence
    Evidence evi = query.getEvidence();
    if (evi != null) {
        Set assertions = evi.getAssertion();
        if (assertions != null) {
            Iterator iter = assertions.iterator();
            while (iter.hasNext()) {
                assertion = (Assertion) iter.next();
                if (SAMLUtils.isAuthNAssertion(assertion)) {
                    return assertion;
                }
            }
        // loop through assertions
        }
        Set idRefs = evi.getAssertionIDReference();
        if (idRefs != null) {
            Iterator iter = idRefs.iterator();
            try {
                AssertionManager am = AssertionManager.getInstance();
                AssertionIDReference idRef = null;
                while (iter.hasNext()) {
                    idRef = (AssertionIDReference) iter.next();
                    try {
                        // get the assertion from server id
                        String remoteUrl = SAMLUtils.getServerURL(idRef.getAssertionIDReference());
                        if (remoteUrl != null) {
                            // call AssertionManagerClient.getAssertion
                            if (SAMLUtils.debug.messageEnabled()) {
                                SAMLUtils.debug.message("DefaultActionMap" + "per: calling another in lb site:" + remoteUrl);
                            }
                            AssertionManagerClient amc = new AssertionManagerClient(SAMLUtils.getFullServiceURL(remoteUrl));
                            assertion = amc.getAssertion(idRef, sourceID);
                        } else {
                            assertion = am.getAssertion(idRef, sourceID);
                        }
                    } catch (Exception e) {
                        if (SAMLUtils.debug.messageEnabled()) {
                            SAMLUtils.debug.message("DefaultActionMapper." + "getSSOAssertion: exception when retrieving " + "Assertion from IDRef:" + e);
                        }
                        continue;
                    }
                    if (SAMLUtils.isAuthNAssertion(assertion)) {
                        return assertion;
                    }
                }
            } catch (Exception e) {
                if (SAMLUtils.debug.messageEnabled()) {
                    SAMLUtils.debug.message("DefaultActionMapper: Couldn't" + " obtain AssertionManager instance:" + e);
                }
            }
        }
    }
    return null;
}
Also used : Set(java.util.Set) AssertionManager(com.sun.identity.saml.AssertionManager) Assertion(com.sun.identity.saml.assertion.Assertion) Iterator(java.util.Iterator) Evidence(com.sun.identity.saml.assertion.Evidence) AssertionIDReference(com.sun.identity.saml.assertion.AssertionIDReference) AssertionManagerClient(com.sun.identity.saml.AssertionManagerClient) SAMLException(com.sun.identity.saml.common.SAMLException) MissingResourceException(java.util.MissingResourceException)

Example 2 with Evidence

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

the class DefaultActionMapper method getAuthorizationDecisions.

/**
     * This method first converts the AttributeStatements in Evidence to
     * OpenAM Policy API environment variables. The Attributes in
     * the AttributeStatement(s) are expected to be OpenAM
     * attributes.
     * It then query the Policy decision one action at a time. Currently,
     * it handles actions defined in urn:oasis:names:tc:SAML:1.0:ghpp only.
     * This action Namespace is mapped to OpenAM
     * iPlanetAMWebAgentService.
     */
public Map getAuthorizationDecisions(AuthorizationDecisionQuery query, Object token, String sourceID) throws SAMLException {
    if ((query == null) || (token == null)) {
        SAMLUtils.debug.message("DefaultActionMapper: null input.");
        throw new SAMLException(SAMLUtils.bundle.getString("nullInput"));
    }
    Evidence evidence = query.getEvidence();
    Subject querySubject = query.getSubject();
    Map envParameters = convertEvidence(evidence, querySubject, sourceID);
    List permitActions = new ArrayList();
    List denyActions = new ArrayList();
    List actions = query.getAction();
    Iterator iterator = actions.iterator();
    PolicyEvaluator pe = null;
    String resource = query.getResource();
    Action action = null;
    String actionNamespace = null;
    while (iterator.hasNext()) {
        action = (Action) iterator.next();
        // get ActionNameSpace
        actionNamespace = action.getNameSpace();
        if ((actionNamespace != null) && (actionNamespace.equals(SAMLConstants.ACTION_NAMESPACE_GHPP))) {
            try {
                if (pe == null) {
                    pe = new PolicyEvaluator("iPlanetAMWebAgentService");
                }
                boolean result = pe.isAllowed((SSOToken) token, resource, action.getAction(), envParameters);
                if (result) {
                    permitActions.add(action);
                } else {
                    denyActions.add(action);
                }
            } catch (Exception e) {
                if (SAMLUtils.debug.messageEnabled()) {
                    SAMLUtils.debug.message("DefaultActionMapper: " + "Exception from policy:" + e);
                }
                // indeterminate
                continue;
            }
        }
    }
    // while loop for each action
    Map resultMap = new HashMap();
    if (!permitActions.isEmpty()) {
        resultMap.put(ActionMapper.PERMIT, permitActions);
    } else if (!denyActions.isEmpty()) {
        resultMap.put(ActionMapper.DENY, denyActions);
    } else {
        resultMap.put(ActionMapper.INDETERMINATE, actions);
    }
    return resultMap;
}
Also used : Action(com.sun.identity.saml.assertion.Action) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SAMLException(com.sun.identity.saml.common.SAMLException) Subject(com.sun.identity.saml.assertion.Subject) SAMLException(com.sun.identity.saml.common.SAMLException) MissingResourceException(java.util.MissingResourceException) PolicyEvaluator(com.sun.identity.policy.PolicyEvaluator) Iterator(java.util.Iterator) Evidence(com.sun.identity.saml.assertion.Evidence) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Evidence (com.sun.identity.saml.assertion.Evidence)2 SAMLException (com.sun.identity.saml.common.SAMLException)2 Iterator (java.util.Iterator)2 MissingResourceException (java.util.MissingResourceException)2 PolicyEvaluator (com.sun.identity.policy.PolicyEvaluator)1 AssertionManager (com.sun.identity.saml.AssertionManager)1 AssertionManagerClient (com.sun.identity.saml.AssertionManagerClient)1 Action (com.sun.identity.saml.assertion.Action)1 Assertion (com.sun.identity.saml.assertion.Assertion)1 AssertionIDReference (com.sun.identity.saml.assertion.AssertionIDReference)1 Subject (com.sun.identity.saml.assertion.Subject)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 NodeList (org.w3c.dom.NodeList)1