Search in sources :

Example 6 with FSAuthnResponse

use of com.sun.identity.federation.message.FSAuthnResponse in project OpenAM by OpenRock.

the class CDCServlet method createAuthnResponse.

private FSAuthnResponse createAuthnResponse(String providerID, String responseID, String inResponseTo, Status status, FSAssertion assertion, String relayState) throws SAMLException, FSMsgException {
    List contents = new ArrayList(1);
    contents.add(assertion);
    FSAuthnResponse response = new FSAuthnResponse(null, inResponseTo, status, contents, relayState);
    response.setProviderId(providerID);
    return response;
}
Also used : FSAuthnResponse(com.sun.identity.federation.message.FSAuthnResponse) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with FSAuthnResponse

use of com.sun.identity.federation.message.FSAuthnResponse in project OpenAM by OpenRock.

the class FSSSOAndFedHandler method processAuthnRequest.

/**
     * Processes authentication request.
     * @param authnRequest authentication request
     * @param bPostAuthn <code>true</code> indicates it's post authentication;
     *  <code>false</code> indicates it's pre authentication.
     */
public void processAuthnRequest(FSAuthnRequest authnRequest, boolean bPostAuthn) {
    FSUtils.debug.message("FSSSOAndFedHandler.processAuthnRequest: Called");
    this.authnRequest = authnRequest;
    String message = null;
    String inResponseTo = authnRequest.getRequestID();
    Status status = null;
    FSAuthnResponse errResponse = null;
    spEntityId = authnRequest.getProviderId();
    try {
        spDescriptor = metaManager.getSPDescriptor(realm, spEntityId);
        spConfig = metaManager.getSPDescriptorConfig(realm, spEntityId);
        if (!metaManager.isTrustedProvider(realm, hostedEntityId, spEntityId)) {
            FSUtils.debug.error("FSSSOAndFedHandler.processAuthnRequest: " + "RemoteProvider is not trusted");
            message = FSUtils.bundle.getString("AuthnRequestProcessingFailed");
            status = new Status(new StatusCode("samlp:Responder"), message, null);
            errResponse = new FSAuthnResponse(null, inResponseTo, status, null, relayState);
            errResponse.setMinorVersion(authnRequest.getMinorVersion());
            sendAuthnResponse(errResponse);
            return;
        }
        if (bPostAuthn) {
            if (processPostAuthnSSO(authnRequest)) {
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSSSOAndFedHandler." + "processAuthnRequest: AuthnRequest Processing " + "successful");
                }
                return;
            } else {
                if (FSUtils.debug.warningEnabled()) {
                    FSUtils.debug.warning("FSSSOAndFedHandler.processAuthnRequest: " + "AuthnRequest Processing failed");
                }
                message = FSUtils.bundle.getString("AuthnRequestProcessingFailed");
                if (noFedStatus != null) {
                    status = noFedStatus;
                } else {
                    status = new Status(new StatusCode("samlp:Responder"), message, null);
                }
                errResponse = new FSAuthnResponse(null, inResponseTo, status, null, relayState);
                errResponse.setMinorVersion(authnRequest.getMinorVersion());
                sendAuthnResponse(errResponse);
                return;
            }
        } else {
            boolean authnRequestSigned = spDescriptor.isAuthnRequestsSigned();
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSSOAndFedHandler.processAuthnRequest: " + "ProviderID : " + spEntityId + " AuthnRequestSigned :this is for testing " + authnRequestSigned);
            }
            if (FSServiceUtils.isSigningOn()) {
                if (authnRequestSigned) {
                    //verify request signature
                    if (!verifyRequestSignature(authnRequest)) {
                        FSUtils.debug.error("FSSSOAndFedHandler." + "processAuthnRequest: " + "AuthnRequest Signature Verification Failed");
                        message = FSUtils.bundle.getString("signatureVerificationFailed");
                        String[] data = { message };
                        LogUtil.error(Level.INFO, LogUtil.SIGNATURE_VERIFICATION_FAILED, data, ssoToken);
                        status = new Status(new StatusCode("samlp:Responder", new StatusCode("lib:UnsignedAuthnRequest", null)), message, null);
                        errResponse = new FSAuthnResponse(null, inResponseTo, status, null, relayState);
                        errResponse.setMinorVersion(authnRequest.getMinorVersion());
                        sendAuthnResponse(errResponse);
                        return;
                    } else {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSSSOAndFedHandler. processAuthnRequest" + ": AuthnRequest Signature Verified");
                        }
                    }
                }
            }
            if (processPreAuthnSSO(authnRequest)) {
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSSSOAndFedHandler.processAuthnRequest: " + "AuthnRequest Processing successful");
                }
                return;
            } else {
                if (FSUtils.debug.warningEnabled()) {
                    FSUtils.debug.warning("FSSSOAndFedHandler.processAuthnRequest: " + "AuthnRequest Processing failed");
                }
                String[] data = { FSUtils.bundle.getString("AuthnRequestProcessingFailed") };
                LogUtil.error(Level.INFO, LogUtil.AUTHN_REQUEST_PROCESSING_FAILED, data, ssoToken);
                message = FSUtils.bundle.getString("AuthnRequestProcessingFailed");
                status = new Status(new StatusCode("samlp:Responder"), message, null);
                if (noFedStatus != null) {
                    status = noFedStatus;
                }
                errResponse = new FSAuthnResponse(null, inResponseTo, status, null, relayState);
                errResponse.setMinorVersion(authnRequest.getMinorVersion());
                sendAuthnResponse(errResponse);
                return;
            }
        }
    } catch (Exception e) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(out));
        FSUtils.debug.error("FSSSOAndFedHandler.processAuthnRequest: " + "Exception Occured: " + e.getMessage() + "Stack trace is " + out.toString());
        message = FSUtils.bundle.getString("AuthnRequestProcessingFailed");
        try {
            status = new Status(new StatusCode("samlp:Responder"), message, null);
            errResponse = new FSAuthnResponse(null, inResponseTo, status, null, relayState);
            errResponse.setMinorVersion(authnRequest.getMinorVersion());
            sendAuthnResponse(errResponse);
        } catch (Exception ex) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSSOAndFedHandler.processAuthnRequest: " + "Exception Occured: ", ex);
            }
        }
    }
}
Also used : Status(com.sun.identity.saml.protocol.Status) PrintStream(java.io.PrintStream) FSAuthnResponse(com.sun.identity.federation.message.FSAuthnResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StatusCode(com.sun.identity.saml.protocol.StatusCode) SessionException(com.sun.identity.plugin.session.SessionException) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) FSAccountMgmtException(com.sun.identity.federation.accountmgmt.FSAccountMgmtException) SAMLException(com.sun.identity.saml.common.SAMLException) FSException(com.sun.identity.federation.common.FSException) IOException(java.io.IOException) FSRedirectException(com.sun.identity.federation.common.FSRedirectException)

Example 8 with FSAuthnResponse

use of com.sun.identity.federation.message.FSAuthnResponse in project OpenAM by OpenRock.

the class FSSSOBrowserPostProfileHandler method doSingleSignOn.

protected boolean doSingleSignOn(Object ssoToken, String inResponseTo, NameIdentifier spHandle, NameIdentifier idpHandle) {
    FSUtils.debug.message("FSSSOBrowserPostProfileHandler.doSingleSignOn: Called");
    this.ssoToken = ssoToken;
    FSAuthnResponse authnResponse = createAuthnResponse(ssoToken, inResponseTo, spHandle, idpHandle);
    try {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSSSOBrowserPostProfileHandler.doSingleSignOn: " + "AuthnResponse created: " + authnResponse.toXMLString());
        }
    } catch (FSException ex) {
        FSUtils.debug.error("FSSSOBrowserPostProfileHandler.doSingleSignOn: " + "Created AuthnResponse is not valid: ", ex);
        return false;
    }
    if (authnResponse == null) {
        FSUtils.debug.error("FSSSOBrowserPostProfileHandler.doSingleSignOn: " + "No valid AuthnResponse could be created. " + "Sending error AuthnResponse");
        return false;
    }
    sendAuthnResponse(authnResponse);
    return true;
}
Also used : FSAuthnResponse(com.sun.identity.federation.message.FSAuthnResponse) FSException(com.sun.identity.federation.common.FSException)

Aggregations

FSAuthnResponse (com.sun.identity.federation.message.FSAuthnResponse)8 FSException (com.sun.identity.federation.common.FSException)5 SAMLException (com.sun.identity.saml.common.SAMLException)4 Status (com.sun.identity.saml.protocol.Status)3 StatusCode (com.sun.identity.saml.protocol.StatusCode)3 IOException (java.io.IOException)3 FSAssertion (com.sun.identity.federation.message.FSAssertion)2 FSMsgException (com.sun.identity.federation.message.common.FSMsgException)2 SessionException (com.sun.identity.plugin.session.SessionException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ServletException (javax.servlet.ServletException)2 SessionException (com.iplanet.dpro.session.SessionException)1 TokenRestriction (com.iplanet.dpro.session.TokenRestriction)1 SSOException (com.iplanet.sso.SSOException)1 FSAccountMgmtException (com.sun.identity.federation.accountmgmt.FSAccountMgmtException)1 FSRedirectException (com.sun.identity.federation.common.FSRedirectException)1 BaseConfigType (com.sun.identity.federation.jaxb.entityconfig.BaseConfigType)1 FSAuthnRequest (com.sun.identity.federation.message.FSAuthnRequest)1 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)1