Search in sources :

Example 41 with FSMsgException

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

the class FSSingleLogoutHandler method doHttpRedirect.

/**
     * Performs the logout notification in the case of HTTP Redirect profile.
     * @param entityId the remote provider to whom logout message needs to
     *  be sent
     * @return logout status
     */
private FSLogoutStatus doHttpRedirect(String entityId) {
    try {
        FSUtils.debug.message("In HTTP Redirect profile");
        isHttpRedirect = true;
        FSSessionManager sMgr = FSSessionManager.getInstance(metaAlias);
        if (ssoToken == null) {
            try {
                //this is HTTP based protocol, get from HTTP servlet request
                ssoToken = SessionManager.getProvider().getSession(request);
            } catch (SessionException ex) {
                FSUtils.debug.error("FSSLOHandler.doHttpRedirect: null ssoToken:", ex);
            }
        }
        FSSession session = sMgr.getSession(ssoToken);
        FSAccountFedInfo acctObj = null;
        if (session != null) {
            acctObj = session.getAccountFedInfo();
        }
        if (acctObj == null && session != null && !session.getOneTime()) {
            acctObj = FSLogoutUtil.getCurrentWorkingAccount(userID, entityId, metaAlias);
        }
        if (acctObj == null) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSingleLogoutHandler.doHttp" + "Redirect: Account might have been terminated.");
            }
            return new FSLogoutStatus(IFSConstants.SAML_SUCCESS);
        }
        FSLogoutNotification reqLogout = createSingleLogoutRequest(acctObj, sessionIndex);
        if (this.relayState != null) {
            reqLogout.setRelayState(this.relayState);
        }
        if (reqLogout == null) {
            FSUtils.debug.message("Logout Request is null");
            return new FSLogoutStatus(IFSConstants.SAML_REQUESTER);
        }
        reqLogout.setMinorVersion(getMinorVersion(remoteDescriptor));
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSSingleLogoutHandler::doHttpRedirect " + remoteDescriptor.getSingleLogoutServiceURL() + "\nLogout request: " + reqLogout.toXMLString());
        }
        String urlEncodedRequest = reqLogout.toURLEncodedQueryString();
        // Sign the request querystring
        if (FSServiceUtils.isSigningOn()) {
            String certAlias = IDFFMetaUtils.getFirstAttributeValueFromConfig(hostedConfig, IFSConstants.SIGNING_CERT_ALIAS);
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("Retrieving self certalias  : " + certAlias);
            }
            if (certAlias == null || certAlias.length() == 0) {
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSSingleLogoutHandler::" + " doHttpRedirect: couldn't obtain " + "this site's cert alias.");
                }
                return new FSLogoutStatus(IFSConstants.SAML_RESPONDER);
            }
            urlEncodedRequest = FSSignatureUtil.signAndReturnQueryString(urlEncodedRequest, certAlias);
        }
        StringBuffer redirectURL = new StringBuffer();
        String retURL = remoteDescriptor.getSingleLogoutServiceURL();
        FSUtils.debug.message("Encoded Redirect URL " + urlEncodedRequest);
        redirectURL.append(retURL);
        if (retURL.indexOf(QUESTION_MARK) == -1) {
            redirectURL.append(QUESTION_MARK);
        } else {
            redirectURL.append(AMPERSAND);
        }
        redirectURL.append(urlEncodedRequest);
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSSingleLogoutHandler::doHttpRedirect" + " URL is " + redirectURL.toString());
        }
        response.sendRedirect(redirectURL.toString());
        return new FSLogoutStatus(IFSConstants.SAML_SUCCESS);
    } catch (FSMsgException e) {
        FSUtils.debug.error("FSSingleLogoutHandler::" + " doHttpRedirect FSMsgException:", e);
    } catch (IOException e) {
        FSUtils.debug.error("FSSingleLogoutHandler::" + "doHttpRedirect IOException:", e);
    }
    return new FSLogoutStatus(IFSConstants.SAML_RESPONDER);
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) FSAccountFedInfo(com.sun.identity.federation.accountmgmt.FSAccountFedInfo) FSSession(com.sun.identity.federation.services.FSSession) SessionException(com.sun.identity.plugin.session.SessionException) FSLogoutNotification(com.sun.identity.federation.message.FSLogoutNotification) IOException(java.io.IOException) FSSessionManager(com.sun.identity.federation.services.FSSessionManager)

Example 42 with FSMsgException

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

the class FSNameRegistrationHandler method doRemoteRegistration.

/**
     * Initiates federation registration at remote end.
     * The registration request is constructed and based on the profile the
     * request is sent over SOAP or as HTTP redirect. Profile is always based on
     * the SPs profile.
     * @return <code>true</code> if the process is successful;
     *  <code>false</code> otherwise.
     */
private boolean doRemoteRegistration() {
    FSUtils.debug.message("Entered FSNameRegistrationHandler::doRemoteRegistration");
    try {
        try {
            if (acctInfo == null) {
                acctInfo = managerInst.readAccountFedInfo(userID, remoteEntityId);
            }
        } catch (FSAccountMgmtException e) {
            returnLocallyAtSource(response, false);
            return false;
        }
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSNameRegistrationHandler::doRemoteRegistration create" + " request start");
        }
        FSNameRegistrationRequest regisRequest = createNameRegistrationRequest(acctInfo);
        if (regisRequest == null) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSNameRegistrationHandler::Registration request could " + "not be formed");
            }
            returnLocallyAtSource(response, false);
            return false;
        }
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSNameRegistrationHandler::Registration request formed" + "successfully");
        }
        // Find out which profile to use
        boolean isSOAPProfile = true;
        if (acctInfo.isRoleIDP()) {
            List hostProfiles = hostedDescriptor.getRegisterNameIdentifierProtocolProfile();
            if (hostProfiles == null || hostProfiles.isEmpty()) {
                FSUtils.debug.error("FSNameRegistrationHandler::" + "doRemoteRegistration no registration profile" + " cannot process request");
                returnLocallyAtSource(response, false);
                return false;
            }
            String hostProfile = (String) hostProfiles.iterator().next();
            if (hostProfile.equalsIgnoreCase(IFSConstants.REGISTRATION_SP_SOAP_PROFILE) || hostProfile.equalsIgnoreCase(IFSConstants.REGISTRATION_IDP_SOAP_PROFILE)) {
                isSOAPProfile = true;
            } else if (hostProfile.equalsIgnoreCase(IFSConstants.REGISTRATION_SP_HTTP_PROFILE) || hostProfile.equalsIgnoreCase(IFSConstants.REGISTRATION_IDP_HTTP_PROFILE)) {
                isSOAPProfile = false;
            } else {
                FSUtils.debug.error("FSNameRegistrationHandler::" + "doRemoteRegistration Invalid registration profile" + " cannot process request");
                returnLocallyAtSource(response, false);
                return false;
            }
        } else {
            List remoteProfiles = remoteDescriptor.getRegisterNameIdentifierProtocolProfile();
            if (remoteProfiles == null || remoteProfiles.isEmpty()) {
                FSUtils.debug.error("FSNameRegistrationHandler::" + "doRemoteRegistration no registration profile" + " cannot process request");
                returnLocallyAtSource(response, false);
                return false;
            }
            String remoteProfile = (String) remoteProfiles.iterator().next();
            if (remoteProfile.equalsIgnoreCase(IFSConstants.REGISTRATION_SP_SOAP_PROFILE) || remoteProfile.equalsIgnoreCase(IFSConstants.REGISTRATION_IDP_SOAP_PROFILE)) {
                isSOAPProfile = true;
            } else if (remoteProfile.equalsIgnoreCase(IFSConstants.REGISTRATION_SP_HTTP_PROFILE) || remoteProfile.equalsIgnoreCase(IFSConstants.REGISTRATION_IDP_HTTP_PROFILE)) {
                isSOAPProfile = false;
            } else {
                FSUtils.debug.error("FSNameRegistrationHandler::" + "doRemoteRegistration Invalid registration profile" + " cannot process request");
                returnLocallyAtSource(response, false);
                return false;
            }
        }
        if (isSOAPProfile) {
            FSSOAPService instSOAP = FSSOAPService.getInstance();
            if (instSOAP != null) {
                FSUtils.debug.message("Signing suceeded. To call bindRegistrationRequest");
                regisRequest.setID(IFSConstants.REGISTRATIONID);
                SOAPMessage msgRegistration = instSOAP.bind(regisRequest.toXMLString(true, true));
                if (msgRegistration != null) {
                    SOAPMessage retSOAPMessage = null;
                    try {
                        if (FSServiceUtils.isSigningOn()) {
                            int minorVersion = regisRequest.getMinorVersion();
                            if (minorVersion == IFSConstants.FF_11_PROTOCOL_MINOR_VERSION) {
                                msgRegistration = signRegistrationRequest(msgRegistration, IFSConstants.ID, regisRequest.getID());
                            } else if (minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) {
                                msgRegistration = signRegistrationRequest(msgRegistration, IFSConstants.REQUEST_ID, regisRequest.getRequestID());
                            } else {
                                FSUtils.debug.message("invalid minor version.");
                            }
                        }
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("calling " + "sendRegistrationMessage");
                        }
                        retSOAPMessage = instSOAP.sendMessage(msgRegistration, remoteDescriptor.getSoapEndpoint());
                    } catch (SOAPException e) {
                        FSUtils.debug.error("Error in sending request ", e);
                        returnLocallyAtSource(response, false);
                        return false;
                    } catch (Exception ex) {
                        FSUtils.debug.error("Error in sending request:", ex);
                        returnLocallyAtSource(response, false);
                        return false;
                    }
                    if (retSOAPMessage == null) {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("sendRegistrationMessage" + "return response is null");
                        }
                        returnLocallyAtSource(response, false);
                        return false;
                    }
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("calling" + "parseSOAPMessage after return from IDP");
                    }
                    Element elt = instSOAP.parseSOAPMessage(retSOAPMessage);
                    if (FSServiceUtils.isSigningOn() && regisResponse != null) {
                        if (!verifyResponseSignature(retSOAPMessage, acctInfo.isRoleIDP())) {
                            if (FSUtils.debug.messageEnabled()) {
                                FSUtils.debug.message("Response " + "signature verification failed");
                                FSUtils.debug.message("Name registration" + " failed in doRemoteRegistration");
                            }
                            returnLocallyAtSource(response, false);
                            return false;
                        }
                    }
                    FSUtils.debug.message("Response signature verification succeeded");
                    if (elt.getLocalName().equalsIgnoreCase(IFSConstants.NAME_REGISTRATION_RESPONSE)) {
                        FSNameRegistrationResponse regisResponse = null;
                        try {
                            regisResponse = new FSNameRegistrationResponse(elt);
                        } catch (SAMLException e) {
                            regisResponse = null;
                        }
                        if (regisResponse != null) {
                            String responseStatus = ((regisResponse.getStatus()).getStatusCode()).getValue();
                            if (responseStatus.equals(IFSConstants.SAML_SUCCESS)) {
                                FSUtils.debug.message("Name registration Successful");
                                // do local update
                                oldAcctKey = (FSAccountFedInfoKey) returnMap.get("OldAccountKey");
                                if (oldAcctKey != null) {
                                    if (FSUtils.debug.messageEnabled()) {
                                        FSUtils.debug.message("Get OldAcctKet Name : " + oldAcctKey.getName() + "\nGet OldAcctKet Qualifier:" + oldAcctKey.getNameSpace());
                                    }
                                } else {
                                    FSUtils.debug.message("OldAccount Key is null");
                                }
                                newAcctKey = (FSAccountFedInfoKey) returnMap.get("AccountKey");
                                if (newAcctKey != null) {
                                    if (FSUtils.debug.messageEnabled()) {
                                        FSUtils.debug.message("Get newAcctKey Name : " + newAcctKey.getName() + "\nGet newAcctKey Qualifier:" + newAcctKey.getNameSpace());
                                    }
                                } else {
                                    FSUtils.debug.message("newAcctKey Key is null");
                                }
                                newAcctInfo = (FSAccountFedInfo) returnMap.get("AccountInfo");
                                userID = (String) returnMap.get("userID");
                                regisSource = (String) returnMap.get("RegisSource");
                                returnURL = (String) returnMap.get(IFSConstants.LRURL);
                                boolean bStatus = doCommonRegistration();
                                if (FSUtils.debug.messageEnabled()) {
                                    FSUtils.debug.message("doCommonRegistration returns " + bStatus);
                                }
                                // Call SP Adapter
                                if (bStatus && hostedProviderRole != null && hostedProviderRole.equalsIgnoreCase(IFSConstants.SP)) {
                                    FSUtils.debug.message("doRemoteRegis");
                                    callPostRegisterNameIdentifierSuccess(request, response, userID, regisRequest, regisResponse, IFSConstants.NAME_REGISTRATION_SP_SOAP_PROFILE);
                                }
                                returnLocallyAtSource(response, bStatus);
                                return bStatus;
                            } else if (responseStatus.equals(IFSConstants.FEDERATION_NOT_EXISTS_STATUS)) {
                                if (FSUtils.debug.messageEnabled()) {
                                    FSUtils.debug.message("Name " + "registration Failed. " + "Federation does not exist");
                                }
                                returnLocallyAtSource(response, false);
                                return false;
                            } else if (responseStatus.equals(IFSConstants.REGISTRATION_FAILURE_STATUS)) {
                                FSUtils.debug.message("Name registration Failed.");
                                returnLocallyAtSource(response, false);
                                return false;
                            }
                        }
                    }
                }
            }
            returnLocallyAtSource(response, false);
            return false;
        } else {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSNameRegistrationHandler::doRemoteRegistration " + "In Redirect profile");
            }
            // addition of relay state
            FSNameIdentifierHelper nameHelper = new FSNameIdentifierHelper(hostedConfig);
            String newId = nameHelper.createNameIdentifier();
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("Registration Id : " + newId);
            }
            regisRequest.setRelayState(newId);
            // add information to FSRegistrationMap        
            HashMap valMap = new HashMap();
            valMap.put("SSODetails", regisMap);
            valMap.put("ReturnEntry", returnMap);
            if (returnURL != null) {
                valMap.put(IFSConstants.LRURL, returnURL);
            }
            FSRegistrationManager registInst = FSRegistrationManager.getInstance(metaAlias);
            registInst.setRegistrationMapInfo(newId, valMap);
            // sat1 add null checks 
            Set ketSet = valMap.keySet();
            Iterator iter = ketSet.iterator();
            String key = null;
            String value = null;
            while (iter.hasNext()) {
                key = (String) iter.next();
                value = (String) regisMap.get(key);
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("Putting in Map Key : " + key + "\nPutting in Map Value : " + value);
                }
            }
            String urlEncodedRequest = regisRequest.toURLEncodedQueryString();
            // Sign the request querystring
            if (FSServiceUtils.isSigningOn()) {
                String certAlias = IDFFMetaUtils.getFirstAttributeValueFromConfig(hostedConfig, IFSConstants.SIGNING_CERT_ALIAS);
                if (certAlias == null || certAlias.length() == 0) {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSBrowserArtifactConsumerHandler:: " + "signSAMLRequest:" + "couldn't obtain this site's cert alias.");
                    }
                    throw new SAMLResponderException(FSUtils.bundle.getString(IFSConstants.NO_CERT_ALIAS));
                }
                urlEncodedRequest = FSSignatureUtil.signAndReturnQueryString(urlEncodedRequest, certAlias);
            }
            StringBuffer redirectURL = new StringBuffer();
            String retURL = remoteDescriptor.getRegisterNameIdentifierServiceURL();
            redirectURL.append(retURL);
            if (retURL.indexOf(IFSConstants.QUESTION_MARK) == -1) {
                redirectURL.append(IFSConstants.QUESTION_MARK);
            } else {
                redirectURL.append(IFSConstants.AMPERSAND);
            }
            redirectURL.append(urlEncodedRequest);
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("Request to be sent : " + redirectURL.toString());
            }
            // end of addition                               
            response.sendRedirect(redirectURL.toString());
            return true;
        }
    } catch (IOException e) {
        FSUtils.debug.error("FSNameRegistrationHandler" + FSUtils.bundle.getString(IFSConstants.FEDERATION_REDIRECT_FAILED));
    } catch (FSMsgException e) {
        FSUtils.debug.error("FSNameRegistrationHandler::doRemoteRegistration " + FSUtils.bundle.getString(IFSConstants.TERMINATION_FAILED_SEND_REMOTE));
    } catch (SAMLResponderException e) {
        FSUtils.debug.error("FSNameRegistrationHandler::doRemoteRegistration " + FSUtils.bundle.getString(IFSConstants.TERMINATION_FAILED_SEND_REMOTE));
    }
    returnLocallyAtSource(response, false);
    return false;
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) Set(java.util.Set) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) FSNameRegistrationRequest(com.sun.identity.federation.message.FSNameRegistrationRequest) FSSOAPService(com.sun.identity.federation.services.FSSOAPService) IOException(java.io.IOException) SOAPMessage(javax.xml.soap.SOAPMessage) SAMLException(com.sun.identity.saml.common.SAMLException) SOAPException(javax.xml.soap.SOAPException) SessionException(com.sun.identity.plugin.session.SessionException) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) FSAccountMgmtException(com.sun.identity.federation.accountmgmt.FSAccountMgmtException) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) SAMLResponderException(com.sun.identity.saml.common.SAMLResponderException) SAMLException(com.sun.identity.saml.common.SAMLException) IOException(java.io.IOException) FSNameIdentifierHelper(com.sun.identity.federation.services.util.FSNameIdentifierHelper) SOAPException(javax.xml.soap.SOAPException) FSNameRegistrationResponse(com.sun.identity.federation.message.FSNameRegistrationResponse) Iterator(java.util.Iterator) List(java.util.List) FSAccountMgmtException(com.sun.identity.federation.accountmgmt.FSAccountMgmtException) SAMLResponderException(com.sun.identity.saml.common.SAMLResponderException)

Example 43 with FSMsgException

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

the class FSScoping method toURLEncodedQueryString.

/**
     * Returns an URL Encoded String.
     *
     * @return a url encoded query string.
     * @throws FSMsgException if there is an error.
     */
public String toURLEncodedQueryString() throws FSMsgException {
    if (proxyCount == -1) {
        FSUtils.debug.error("FSScoping.toURLEncodedQueryString: " + "proxyCount is not defined.");
        throw new FSMsgException("proxyCountNotDefined", null);
    }
    StringBuffer sb = new StringBuffer(100);
    sb.append("ProxyCount=").append(proxyCount).append("&");
    if (idpList != null) {
        IDPEntries entries = idpList.getIDPEntries();
        if (entries != null) {
            List idps = entries.getIDPEntryList();
            if (idps != null && idps.size() != 0) {
                Iterator iter = idps.iterator();
                StringBuffer strProviders = new StringBuffer(100);
                String space = "";
                while (iter.hasNext()) {
                    IDPEntry entry = (IDPEntry) iter.next();
                    String providerID = entry.getProviderID();
                    strProviders.append(space).append(providerID);
                    space = " ";
                }
                sb.append("IDPEntries=").append(URLEncDec.encode(strProviders.toString()));
            }
        }
    }
    sb.append(IFSConstants.AMPERSAND);
    return sb.toString();
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) Iterator(java.util.Iterator) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) IDPEntries(com.sun.identity.federation.message.common.IDPEntries) IDPEntry(com.sun.identity.federation.message.common.IDPEntry)

Example 44 with FSMsgException

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

the class FSAssertionConsumerService method doGet.

/**
     * Handles artifact profile.
     * @param request <code>HttpServletRequest</code> object
     * @param response <code>HttpServletResponse</code> object
     * @exception ServletException, IOException if error occurrs.
     */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if ((request == null) || (response == null)) {
        response.sendError(response.SC_INTERNAL_SERVER_ERROR, FSUtils.bundle.getString("nullInputParameter"));
        return;
    }
    FSUtils.debug.message("FSAssertionConsumerService.doGet(): called");
    String relayState = request.getParameter(IFSConstants.LRURL);
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSAssertionConsumerService.doGet():Resource URL: " + relayState);
    }
    String metaAlias = FSServiceUtils.getMetaAlias(request);
    String realm = IDFFMetaUtils.getRealmByMetaAlias(metaAlias);
    String baseURL = FSServiceUtils.getBaseURL(request);
    String framedPageURL = FSServiceUtils.getCommonLoginPageURL(metaAlias, relayState, null, request, baseURL);
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSAssertionConsumerService: CommonLoginPage: " + framedPageURL);
    }
    SPDescriptorType hostDesc = null;
    BaseConfigType hostConfig = null;
    String hostEntityId = null;
    try {
        hostEntityId = metaManager.getEntityIDByMetaAlias(metaAlias);
        hostDesc = metaManager.getSPDescriptor(realm, hostEntityId);
        hostConfig = metaManager.getSPDescriptorConfig(realm, hostEntityId);
    } catch (Exception e) {
        FSUtils.debug.error("FSAssertionConsumerService.doGet: ", e);
        FSUtils.forwardRequest(request, response, framedPageURL);
        return;
    }
    FSRequest samlRequest = null;
    String firstSourceID = null;
    String artifactName = IFSConstants.ARTIFACT_NAME_DEFAULT;
    String[] arti = (String[]) request.getParameterValues(artifactName);
    if ((arti == null) || (arti.length < 0) || (arti[0] == null)) {
        FSUtils.debug.error("FSAssertionConsumerService.doGet: " + "AuthnRequest Processing Failed at the IDP " + "Redirecting to the Framed Login Page");
        FSUtils.forwardRequest(request, response, framedPageURL);
    }
    List al = new ArrayList();
    try {
        FSAssertionArtifact firstArtifact = new FSAssertionArtifact(arti[0]);
        firstSourceID = firstArtifact.getSourceID();
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionConsumerService.doGet: " + "SourceID within the Artifact is " + firstSourceID);
        }
        al.add(firstArtifact);
        for (int k = 1; k < arti.length; k++) {
            // check all artifacts coming from the same source id
            FSAssertionArtifact assertArtifact = new FSAssertionArtifact(arti[k]);
            String dest = assertArtifact.getSourceID();
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSAssertionConsumerService.doGet: " + "SourceID within the Artifact is " + dest);
            }
            if (!dest.equals(firstSourceID)) {
                FSUtils.debug.error("FSAssertionConsumerService.doGet: " + "Received multiple artifacts have different source id");
                FSUtils.forwardRequest(request, response, framedPageURL);
                return;
            }
            al.add(assertArtifact);
        }
        samlRequest = new FSRequest(null, al);
    } catch (SAMLException se) {
        FSUtils.debug.error("FSAssertionConsumerService.doGet: ", se);
        FSUtils.forwardRequest(request, response, framedPageURL);
        return;
    } catch (FSMsgException se) {
        FSUtils.debug.error("FSAssertionConsumerService.doGet: ", se);
        FSUtils.forwardRequest(request, response, framedPageURL);
        return;
    }
    try {
        // handle sso
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionConsumerService.doGet: " + "Trying to get BrowserArtifactHandler");
        }
        FSServiceManager sm = FSServiceManager.getInstance();
        FSAssertionArtifactHandler handler = sm.getBrowserArtifactHandler(request, response, realm, firstSourceID, samlRequest, relayState);
        if (handler == null) {
            FSUtils.debug.error("FSAssertionConsumerService.doGet: " + FSUtils.bundle.getString("internalError"));
            FSUtils.forwardRequest(request, response, framedPageURL);
            return;
        }
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionConsumerService.doGet: " + "BrowserArtifactHandler created");
        }
        handler.setRealm(realm);
        handler.setHostEntityId(hostEntityId);
        handler.setMetaAlias(metaAlias);
        handler.setHostDescriptor(hostDesc);
        handler.setHostDescriptorConfig(hostConfig);
        handler.processSAMLRequest();
        return;
    } catch (Exception e) {
        FSUtils.debug.error("FSAssertionConsumerService.doGet: " + "Exception occurred :", e);
        FSUtils.forwardRequest(request, response, framedPageURL);
        return;
    }
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) ArrayList(java.util.ArrayList) SPDescriptorType(com.sun.identity.liberty.ws.meta.jaxb.SPDescriptorType) SAMLException(com.sun.identity.saml.common.SAMLException) ServletException(javax.servlet.ServletException) SAMLException(com.sun.identity.saml.common.SAMLException) FSException(com.sun.identity.federation.common.FSException) IOException(java.io.IOException) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) FSServiceManager(com.sun.identity.federation.services.FSServiceManager) ArrayList(java.util.ArrayList) List(java.util.List) FSAssertionArtifact(com.sun.identity.federation.message.FSAssertionArtifact) FSRequest(com.sun.identity.federation.message.FSRequest)

Example 45 with FSMsgException

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

the class FSTerminationRequestServlet method doGetPost.

/**
     * Handles termination request.
     * @param request <code>HttpServletRequest</code> object that contains the
     *  request the client has made of the servlet.
     * @param response <code>HttpServletResponse</code> object that contains
     *  the response the servlet sends to the client.
     * @exception IOException if the request could not be handled
     */
private void doGetPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // Alias processing
    String providerAlias = FSServiceUtils.getMetaAlias(request);
    if (providerAlias == null || providerAlias.length() < 1) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("Unable to retrieve alias, Hosted " + "Provider. Cannot process request");
        }
        response.sendError(response.SC_INTERNAL_SERVER_ERROR, FSUtils.bundle.getString("aliasNotFound"));
        return;
    }
    if (metaManager == null) {
        FSUtils.debug.error("Cannot retrieve hosted descriptor. Cannot process request");
        response.sendError(response.SC_INTERNAL_SERVER_ERROR, FSUtils.bundle.getString(IFSConstants.FAILED_HOSTED_DESCRIPTOR));
        return;
    }
    ProviderDescriptorType hostedProviderDesc = null;
    BaseConfigType hostedConfig = null;
    String realm = IDFFMetaUtils.getRealmByMetaAlias(providerAlias);
    String hostedEntityId = null;
    String hostedProviderRole = null;
    try {
        hostedProviderRole = metaManager.getProviderRoleByMetaAlias(providerAlias);
        hostedEntityId = metaManager.getEntityIDByMetaAlias(providerAlias);
        if (hostedProviderRole != null && hostedProviderRole.equalsIgnoreCase(IFSConstants.IDP)) {
            hostedProviderDesc = metaManager.getIDPDescriptor(realm, hostedEntityId);
            hostedConfig = metaManager.getIDPDescriptorConfig(realm, hostedEntityId);
        } else if (hostedProviderRole != null && hostedProviderRole.equalsIgnoreCase(IFSConstants.SP)) {
            hostedProviderDesc = metaManager.getSPDescriptor(realm, hostedEntityId);
            hostedConfig = metaManager.getSPDescriptorConfig(realm, hostedEntityId);
        }
        if (hostedProviderDesc == null) {
            throw new IDFFMetaException((String) null);
        }
    } catch (IDFFMetaException eam) {
        FSUtils.debug.error("Unable to find Hosted Provider. not process request");
        response.sendError(response.SC_INTERNAL_SERVER_ERROR, FSUtils.bundle.getString(IFSConstants.FAILED_HOSTED_DESCRIPTOR));
        return;
    }
    this.request = request;
    setTerminationURL(hostedConfig, providerAlias);
    FSFederationTerminationNotification fedTermObj = new FSFederationTerminationNotification();
    try {
        fedTermObj = FSFederationTerminationNotification.parseURLEncodedRequest(request);
    } catch (FSMsgException e) {
        FSServiceUtils.showErrorPage(response, commonErrorPage, IFSConstants.TERMINATION_REQUEST_IMPROPER, IFSConstants.TERMINATION_LOCAL_FAILED);
        return;
    } catch (SAMLException e) {
        FSServiceUtils.showErrorPage(response, commonErrorPage, IFSConstants.TERMINATION_REQUEST_IMPROPER, IFSConstants.TERMINATION_LOCAL_FAILED);
        return;
    }
    if (fedTermObj == null) {
        FSServiceUtils.showErrorPage(response, commonErrorPage, IFSConstants.TERMINATION_REQUEST_IMPROPER, IFSConstants.TERMINATION_LOCAL_FAILED);
    } else {
        doRequestProcessing(request, response, hostedProviderDesc, hostedConfig, hostedProviderRole, realm, hostedEntityId, providerAlias, fedTermObj);
    }
    return;
}
Also used : BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) FSFederationTerminationNotification(com.sun.identity.federation.message.FSFederationTerminationNotification) ProviderDescriptorType(com.sun.identity.liberty.ws.meta.jaxb.ProviderDescriptorType) SAMLException(com.sun.identity.saml.common.SAMLException)

Aggregations

FSMsgException (com.sun.identity.federation.message.common.FSMsgException)46 SAMLException (com.sun.identity.saml.common.SAMLException)17 Document (org.w3c.dom.Document)15 Element (org.w3c.dom.Element)15 BaseConfigType (com.sun.identity.federation.jaxb.entityconfig.BaseConfigType)10 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)10 ProviderDescriptorType (com.sun.identity.liberty.ws.meta.jaxb.ProviderDescriptorType)8 Status (com.sun.identity.saml.protocol.Status)8 IOException (java.io.IOException)8 Iterator (java.util.Iterator)8 FSException (com.sun.identity.federation.common.FSException)7 ParseException (java.text.ParseException)7 SessionException (com.sun.identity.plugin.session.SessionException)6 FSNameRegistrationResponse (com.sun.identity.federation.message.FSNameRegistrationResponse)5 StatusCode (com.sun.identity.saml.protocol.StatusCode)5 FSLogoutNotification (com.sun.identity.federation.message.FSLogoutNotification)4 NameIdentifier (com.sun.identity.saml.assertion.NameIdentifier)4 List (java.util.List)4 SOAPMessage (javax.xml.soap.SOAPMessage)4 FSAccountMgmtException (com.sun.identity.federation.accountmgmt.FSAccountMgmtException)3