Search in sources :

Example 16 with FSException

use of com.sun.identity.federation.common.FSException in project OpenAM by OpenRock.

the class CDCServlet method createAssertion.

private FSAssertion createAssertion(String destID, String sourceID, String tokenID, String authType, String strAuthInst, String userDN, String inResponseTo) throws FSException, SAMLException {
    debug.message("Entering CDCServlet.createAssertion Method");
    if ((destID == null) || (sourceID == null) || (tokenID == null) || (authType == null) || (userDN == null) || (inResponseTo == null)) {
        debug.message("CDCServlet,createAssertion: null input");
        throw new FSException(FSUtils.bundle.getString("nullInput"));
    }
    String securityDomain = sourceID;
    NameIdentifier idpHandle = new NameIdentifier(URLEncDec.encode(tokenID), sourceID);
    NameIdentifier spHandle = idpHandle;
    String authMethod = authType;
    Date authInstant = convertAuthInstanceToDate(strAuthInst);
    if (debug.messageEnabled()) {
        debug.message("CDCServlet.createAssertion " + "Creating Authentication Assertion for user with opaqueHandle =" + spHandle.getName() + " and SecurityDomain = " + securityDomain);
    }
    SubjectConfirmation subConfirmation = new SubjectConfirmation(IFSConstants.CONFIRMATION_METHOD_BEARER);
    IDPProvidedNameIdentifier idpNi = new IDPProvidedNameIdentifier(idpHandle.getNameQualifier(), idpHandle.getName());
    FSSubject sub = new FSSubject(spHandle, subConfirmation, idpNi);
    SubjectLocality authLocality = new SubjectLocality(IPAddress, DNSAddress);
    AuthnContext authnContextStmt = new AuthnContext(null, null);
    FSAuthenticationStatement statement = new FSAuthenticationStatement(authMethod, authInstant, sub, authLocality, null, authnContextStmt);
    //setReauthenticateOnOrAfter date
    Date issueInstant = new Date();
    // get this period from the config
    Integer assertionTimeout = new Integer(IFSConstants.ASSERTION_TIMEOUT_DEFAULT);
    long period = (assertionTimeout.intValue()) * 1000;
    if (period < IFSConstants.ASSERTION_TIMEOUT_ALLOWED_DIFFERENCE) {
        period = IFSConstants.ASSERTION_TIMEOUT_ALLOWED_DIFFERENCE;
    }
    Date notAfter = new Date(issueInstant.getTime() + period);
    statement.setReauthenticateOnOrAfter(notAfter);
    if (debug.messageEnabled()) {
        debug.message("CDCServlet.createAssertion: " + "Authentication Statement: " + statement.toXMLString());
    }
    Conditions cond = new Conditions(issueInstant, notAfter);
    if ((destID != null) && (destID.length() != 0)) {
        List targets = new ArrayList(1);
        targets.add(destID);
        cond.addAudienceRestrictionCondition(new AudienceRestrictionCondition(targets));
    }
    if (debug.messageEnabled()) {
        debug.message("CDCServlet.createAssertion: " + "Condition: " + cond.toString());
    }
    AssertionIDReference aID = new AssertionIDReference();
    Set statements = new HashSet(2);
    statements.add(statement);
    FSAssertion assertion = new FSAssertion(aID.getAssertionIDReference(), sourceID, issueInstant, cond, statements, inResponseTo);
    assertion.setID(aID.getAssertionIDReference());
    String[] params = { FSUtils.bundle.getString("assertionCreated") + ":" + assertion.toString() };
    LogUtil.access(Level.INFO, "CREATE_ASSERTION", params);
    if (debug.messageEnabled()) {
        debug.message("CDCServlet.createAssertion:" + " Returning Assertion: " + assertion.toXMLString());
    }
    return assertion;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) NameIdentifier(com.sun.identity.saml.assertion.NameIdentifier) IDPProvidedNameIdentifier(com.sun.identity.federation.message.common.IDPProvidedNameIdentifier) FSSubject(com.sun.identity.federation.message.FSSubject) FSAuthenticationStatement(com.sun.identity.federation.message.FSAuthenticationStatement) ArrayList(java.util.ArrayList) Date(java.util.Date) SubjectLocality(com.sun.identity.saml.assertion.SubjectLocality) Conditions(com.sun.identity.saml.assertion.Conditions) AuthnContext(com.sun.identity.federation.message.common.AuthnContext) SubjectConfirmation(com.sun.identity.saml.assertion.SubjectConfirmation) FSAssertion(com.sun.identity.federation.message.FSAssertion) FSException(com.sun.identity.federation.common.FSException) List(java.util.List) ArrayList(java.util.ArrayList) AudienceRestrictionCondition(com.sun.identity.saml.assertion.AudienceRestrictionCondition) IDPProvidedNameIdentifier(com.sun.identity.federation.message.common.IDPProvidedNameIdentifier) AssertionIDReference(com.sun.identity.saml.assertion.AssertionIDReference) HashSet(java.util.HashSet)

Example 17 with FSException

use of com.sun.identity.federation.common.FSException in project OpenAM by OpenRock.

the class CDCServlet method redirectWithAuthNResponse.

/**
     * Constructs the Liberty AuthNResponse with Restricted SSOToken
     * and redirects the user to the requested resouce
     */
private void redirectWithAuthNResponse(HttpServletRequest request, HttpServletResponse response, SSOToken token) throws ServletException, IOException {
    String gotoURL = getRedirectURL(request, response);
    if (debug.messageEnabled()) {
        debug.message("CDCServlet.redirectWithAuthNResponse: gotoURL = " + gotoURL);
    }
    if (debug.messageEnabled()) {
        debug.message("CDCServlet.redirectWithAuthNResponse: After encoding: gotoURL = " + gotoURL);
    }
    if (gotoURL != null) {
        try {
            String inResponseTo = request.getParameter(REQUEST_ID);
            String spDescriptor = request.getParameter(PROVIDER_ID);
            String resTokenID = null;
            /**
                 * validateAndGetRestriction throws an exception if an agent
                 * profile with provider id and goto url is not present
                 */
            TokenRestriction tokenRes = spValidator.validateAndGetRestriction(FSAuthnRequest.parseURLEncodedRequest(request), gotoURL);
            if (uniqueCookieEnabled) {
                resTokenID = sessionService.getRestrictedTokenId(token.getTokenID().toString(), tokenRes);
            } else {
                resTokenID = token.getTokenID().toString();
            }
            FSAssertion assertion = createAssertion(spDescriptor, SELF_PROVIDER_ID, resTokenID, token.getAuthType(), token.getProperty("authInstant"), token.getPrincipal().getName(), inResponseTo);
            String relayState = request.getParameter(RELAY_STATE);
            Status status = new Status(new StatusCode(IFSConstants.STATUS_CODE_SUCCESS));
            FSAuthnResponse authnResponse = createAuthnResponse(SELF_PROVIDER_ID, responseID, inResponseTo, status, assertion, relayState);
            sendAuthnResponse(request, response, authnResponse, gotoURL);
        } catch (SAMLException se) {
            debug.error("CDCServlet.doGetPost", se);
            showError(response);
        } catch (FSMsgException fe) {
            debug.error("CDCServlet.doGetPost", fe);
            showError(response);
        } catch (FSException fse) {
            debug.error("CDCServlet.doGetPost", fse);
            showError(response);
        } catch (SessionException e) {
            debug.error("CDCServlet.doGetPost", e);
        } catch (SSOException ssoe) {
            debug.error("CDCServlet.doGetPost", ssoe);
        } catch (Exception e) {
            debug.error("CDCServlet.doGetPost", e);
            spValidator = new LdapSPValidator();
            showError(response, FORBIDDEN_STR_MATCH);
        }
    }
}
Also used : Status(com.sun.identity.saml.protocol.Status) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) TokenRestriction(com.iplanet.dpro.session.TokenRestriction) SessionException(com.iplanet.dpro.session.SessionException) SSOException(com.iplanet.sso.SSOException) StatusCode(com.sun.identity.saml.protocol.StatusCode) SAMLException(com.sun.identity.saml.common.SAMLException) ServletException(javax.servlet.ServletException) ParseException(java.text.ParseException) SSOException(com.iplanet.sso.SSOException) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) SAMLException(com.sun.identity.saml.common.SAMLException) FSException(com.sun.identity.federation.common.FSException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SessionException(com.iplanet.dpro.session.SessionException) FSAuthnResponse(com.sun.identity.federation.message.FSAuthnResponse) FSAssertion(com.sun.identity.federation.message.FSAssertion) FSException(com.sun.identity.federation.common.FSException)

Example 18 with FSException

use of com.sun.identity.federation.common.FSException in project OpenAM by OpenRock.

the class FSTerminationRequestServlet method doRequestProcessing.

/**
     * Called when a Termination request is received from a remote provider.
     * @param request <code>HTTPServletRequest</code> object received via HTTP
     *  Redirect
     * @param response <code>HTTPServletResponse</code> object to send the 
     *  response back to user agent
     * @param hostedProviderDesc the provider for whom request is received
     * @param hostedConfig hosted provider's extended meta
     * @param hostedProviderRole hosted provider's role
     * @param realm The realm under which the entity resides
     * @param hostedEntityId hosted provider's entity ID
     * @param providerAlias hosted provider's meta alias
     * @param reqTermination the federation termination request
     */
private void doRequestProcessing(HttpServletRequest request, HttpServletResponse response, ProviderDescriptorType hostedProviderDesc, BaseConfigType hostedConfig, String hostedProviderRole, String realm, String hostedEntityId, String providerAlias, FSFederationTerminationNotification reqTermination) {
    FSUtils.debug.message("Entered FSTerminationRequestServlet::doRequestProcessing");
    String remoteEntityId = reqTermination.getProviderId();
    String retURL = null;
    ProviderDescriptorType remoteDesc = null;
    boolean isIDP = false;
    try {
        if (hostedProviderRole.equalsIgnoreCase(IFSConstants.SP)) {
            remoteDesc = metaManager.getIDPDescriptor(realm, remoteEntityId);
            isIDP = true;
        } else {
            remoteDesc = metaManager.getSPDescriptor(realm, remoteEntityId);
        }
        if (remoteDesc == null) {
            throw new IDFFMetaException((String) null);
        }
        retURL = remoteDesc.getFederationTerminationServiceReturnURL();
    } catch (IDFFMetaException e) {
        FSUtils.debug.error("FSTerminationRequestServlet.doRequest " + "Processing: Can not retrieve remote provider data." + remoteEntityId);
        String[] data = { remoteEntityId, realm };
        LogUtil.error(Level.INFO, LogUtil.INVALID_PROVIDER, data);
        FSServiceUtils.returnToSource(response, retURL, commonErrorPage, IFSConstants.TERMINATION_INVALID_FEDERATION, IFSConstants.METADATA_ERROR);
        return;
    }
    boolean bVerify = true;
    if (FSServiceUtils.isSigningOn()) {
        try {
            if (remoteDesc != null) {
                FSUtils.debug.message("Calling verifyTerminationSignature");
                bVerify = verifyTerminationSignature(request, remoteDesc, remoteEntityId, isIDP);
            } else {
                FSUtils.debug.error("Remote provider metadata not found.");
                String[] data = { remoteEntityId, realm };
                LogUtil.error(Level.INFO, LogUtil.INVALID_PROVIDER, data);
                FSServiceUtils.returnToSource(response, retURL, commonErrorPage, IFSConstants.TERMINATION_INVALID_FEDERATION, IFSConstants.METADATA_ERROR);
                return;
            }
        } catch (FSException e) {
            FSUtils.debug.error("FSTerminationRequestServlet::doRequestProcessing " + "Signature on termination request is invalid" + "Cannot proceed federation termination");
            String[] data = { FSUtils.bundle.getString(IFSConstants.TERMINATION_INVALID_SIGNATURE) };
            LogUtil.error(Level.INFO, LogUtil.INVALID_SIGNATURE, data);
            FSServiceUtils.returnToSource(response, retURL, commonErrorPage, IFSConstants.TERMINATION_INVALID_FEDERATION, IFSConstants.METADATA_ERROR);
            return;
        } catch (SAMLException e) {
            FSUtils.debug.error("FSFedTerminationHandler::doRequestProcessing " + "Signature on termination request is invalid" + "Cannot proceed federation termination");
            String[] data = { FSUtils.bundle.getString(IFSConstants.TERMINATION_INVALID_SIGNATURE) };
            LogUtil.error(Level.INFO, LogUtil.INVALID_SIGNATURE, data);
            FSServiceUtils.returnToSource(response, retURL, commonErrorPage, IFSConstants.TERMINATION_INVALID_FEDERATION, IFSConstants.METADATA_ERROR);
            return;
        }
    }
    if (bVerify) {
        // Check if trusted provider
        if (metaManager.isTrustedProvider(realm, hostedEntityId, remoteEntityId)) {
            FSServiceManager instService = FSServiceManager.getInstance();
            if (instService != null) {
                FSFedTerminationHandler termHandler = instService.getFedTerminationHandler(reqTermination, hostedConfig, realm, hostedEntityId, hostedProviderRole, providerAlias, remoteEntityId);
                if (termHandler != null) {
                    termHandler.setHostedDescriptor(hostedProviderDesc);
                    termHandler.setHostedDescriptorConfig(hostedConfig);
                    termHandler.setRealm(realm);
                    termHandler.setHostedEntityId(hostedEntityId);
                    termHandler.setHostedProviderRole(hostedProviderRole);
                    termHandler.setMetaAlias(providerAlias);
                    termHandler.setRemoteEntityId(remoteEntityId);
                    termHandler.setRemoteDescriptor(remoteDesc);
                    termHandler.processTerminationRequest(request, response, reqTermination);
                    return;
                } else {
                    FSUtils.debug.error("Unable to get termination " + "handler. User account Not valid");
                }
            } else {
                FSUtils.debug.error("FSServiceManager instance is null" + " Cannot process termination request");
            }
        } else {
            FSUtils.debug.error("Remote provider not in trusted list");
        }
    } else {
        FSUtils.debug.error("FSTerminationRequestServlet::doRequestProcesing " + "Signature on termination request is invalid" + "Cannot proceed federation termination");
        String[] data = { FSUtils.bundle.getString(IFSConstants.TERMINATION_INVALID_SIGNATURE) };
        LogUtil.error(Level.INFO, LogUtil.INVALID_SIGNATURE, data);
    }
    FSServiceUtils.returnToSource(response, retURL, commonErrorPage, IFSConstants.TERMINATION_INVALID_FEDERATION, IFSConstants.METADATA_ERROR);
}
Also used : FSServiceManager(com.sun.identity.federation.services.FSServiceManager) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) ProviderDescriptorType(com.sun.identity.liberty.ws.meta.jaxb.ProviderDescriptorType) FSException(com.sun.identity.federation.common.FSException) SAMLException(com.sun.identity.saml.common.SAMLException)

Example 19 with FSException

use of com.sun.identity.federation.common.FSException in project OpenAM by OpenRock.

the class FSAttributeStatementHelper method getAutoFedAttributeStatement.

/**
     * Gets a SAML <code>AttributeStatement</code> by using an
     * <code>AutoFederate</code> attribute that is configured in Local Provider.
     * @param realm The realm under which the entity resides.
     * @param entityID Host Provider's entity ID.
     * @param sub Liberty Subject.
     * @param ssoToken session of the user
     * @return Generated Auto Federate Attribute Statement.
     * @exception FSException if an error occurred
     */
public static AttributeStatement getAutoFedAttributeStatement(String realm, String entityID, FSSubject sub, Object ssoToken) throws FSException {
    IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
    BaseConfigType hostConfig = null;
    try {
        if (metaManager != null) {
            hostConfig = metaManager.getIDPDescriptorConfig(realm, entityID);
        }
    } catch (IDFFMetaException fae) {
        FSUtils.debug.error("FSAttributeStatementHelper.getAutoFed" + "AttributeStatement: IDFFMetaException ", fae);
        throw new FSException(fae);
    }
    String autoFedAttr = IDFFMetaUtils.getFirstAttributeValueFromConfig(hostConfig, IFSConstants.AUTO_FEDERATION_ATTRIBUTE);
    if (autoFedAttr == null) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAttributeStatementHelper.getAutoFed:" + "AttributeStatement: AutoFederate Attribute is null");
        }
        return null;
    }
    List values = new ArrayList();
    try {
        String userID = SessionManager.getProvider().getPrincipalName(ssoToken);
        DataStoreProvider provider = DataStoreProviderManager.getInstance().getDataStoreProvider(IFSConstants.IDFF);
        Set vals = provider.getAttribute(userID, autoFedAttr);
        Iterator iter = vals.iterator();
        while (iter.hasNext()) {
            values.add(getAttributeValue((String) iter.next()));
        }
    } catch (SessionException se) {
        FSUtils.debug.error("FSAttributeStatementHelper.getAutoFed" + "AttributeStatement: SessionException ", se);
        throw new FSException(se);
    } catch (DataStoreProviderException ie) {
        FSUtils.debug.error("FSAttributeStatementHelper.getAutoFed" + "AttributeStatement: DataStoreProviderException ", ie);
        throw new FSException(ie);
    }
    if (values == null || values.size() == 0) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAtributeStatementHelper.getAuto:" + "FedAttributeStatement. No values for autofed attribute");
        }
        return null;
    }
    try {
        Attribute attribute = new Attribute(IFSConstants.AUTO_FED_ATTR, IFSConstants.assertionSAMLNameSpaceURI, values);
        List attributeList = new ArrayList();
        attributeList.add(attribute);
        return new AttributeStatement(sub, attributeList);
    } catch (SAMLException ex) {
        FSUtils.debug.error("FSAttributeStatementHelper.getAutoFed" + "AttributeStatement: SAMLException ", ex);
        throw new FSException(ex);
    }
}
Also used : DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) Set(java.util.Set) Attribute(com.sun.identity.saml.assertion.Attribute) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) DataStoreProvider(com.sun.identity.plugin.datastore.DataStoreProvider) ArrayList(java.util.ArrayList) SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) IDFFMetaManager(com.sun.identity.federation.meta.IDFFMetaManager) AttributeStatement(com.sun.identity.saml.assertion.AttributeStatement) FSException(com.sun.identity.federation.common.FSException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with FSException

use of com.sun.identity.federation.common.FSException in project OpenAM by OpenRock.

the class FSAttributeStatementHelper method getAttributeValue.

/**
     * Gets the SAML Attribute value as a DOM Element.
     */
private static Element getAttributeValue(String value) throws FSException {
    if (value == null) {
        throw new FSException("nullInputParameter", null);
    }
    StringBuffer sb = new StringBuffer(300);
    sb.append("<").append(SAMLConstants.ASSERTION_PREFIX).append("AttributeValue").append(SAMLConstants.assertionDeclareStr).append(">").append(value).append("</").append(SAMLConstants.ASSERTION_PREFIX).append("AttributeValue>");
    try {
        return XMLUtils.toDOMDocument(sb.toString(), FSUtils.debug).getDocumentElement();
    } catch (Exception ex) {
        throw new FSException(ex);
    }
}
Also used : FSException(com.sun.identity.federation.common.FSException) DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) FSException(com.sun.identity.federation.common.FSException) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException)

Aggregations

FSException (com.sun.identity.federation.common.FSException)49 SAMLException (com.sun.identity.saml.common.SAMLException)25 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)21 SessionException (com.sun.identity.plugin.session.SessionException)19 IOException (java.io.IOException)13 List (java.util.List)12 BaseConfigType (com.sun.identity.federation.jaxb.entityconfig.BaseConfigType)10 FSAssertion (com.sun.identity.federation.message.FSAssertion)10 FSAccountMgmtException (com.sun.identity.federation.accountmgmt.FSAccountMgmtException)8 FSAuthnRequest (com.sun.identity.federation.message.FSAuthnRequest)8 ArrayList (java.util.ArrayList)8 Iterator (java.util.Iterator)8 Document (org.w3c.dom.Document)8 IDFFMetaManager (com.sun.identity.federation.meta.IDFFMetaManager)7 IDPDescriptorType (com.sun.identity.liberty.ws.meta.jaxb.IDPDescriptorType)7 ProviderDescriptorType (com.sun.identity.liberty.ws.meta.jaxb.ProviderDescriptorType)7 NameIdentifier (com.sun.identity.saml.assertion.NameIdentifier)7 Status (com.sun.identity.saml.protocol.Status)7 Map (java.util.Map)7 FSMsgException (com.sun.identity.federation.message.common.FSMsgException)6