Search in sources :

Example 1 with MechanismHandler

use of com.sun.identity.liberty.ws.authnsvc.mechanism.MechanismHandler in project OpenAM by OpenRock.

the class AuthnSvcRequestHandlerImpl method processSASLRequest.

/**
     * Processes a SASL request and returns a SASL response.
     * @param saslReq a SASL request
     * @param message a SOAP Message containing a SASL response
     * @param respMessageID messageID of SOAP Message response that will
     *                      contain returned SASL response
     * @return a SASL response
     * @exception AuthnSvcException if an error occurs while processing the
     *                              SASL request
     */
private static SASLResponse processSASLRequest(SASLRequest saslReq, Message message, String respMessageID) throws AuthnSvcException {
    String mechanism = saslReq.getMechanism().trim();
    if (AuthnSvcUtils.debug.messageEnabled()) {
        String msg = AuthnSvcUtils.getString("messageID") + "=" + message.getCorrelationHeader().getMessageID() + ", " + AuthnSvcUtils.getString("mechanism") + "=" + mechanism + ", " + AuthnSvcUtils.getString("authzID") + "=" + saslReq.getAuthzID() + ", " + AuthnSvcUtils.getString("advisoryAuthnID") + "=" + saslReq.getAdvisoryAuthnID();
        AuthnSvcUtils.debug.message(msg);
    }
    String[] data = { message.getCorrelationHeader().getMessageID(), mechanism, saslReq.getAuthzID(), saslReq.getAdvisoryAuthnID() };
    if (mechanism.length() == 0) {
        if (AuthnSvcUtils.debug.messageEnabled()) {
            AuthnSvcUtils.debug.message("AuthnSvcRequestHanderImpl.processSASLRequest: " + "mechanism is empty");
        }
        if (LogUtil.isLogEnabled()) {
            LogUtil.access(Level.INFO, LogUtil.AS_ABORT, data);
        }
        return new SASLResponse(SASLResponse.ABORT);
    }
    MechanismHandler mechanismHandler = null;
    StringTokenizer stz = new StringTokenizer(mechanism);
    while (stz.hasMoreTokens()) {
        String mech = stz.nextToken();
        mechanismHandler = AuthnSvcService.getMechanismHandler(mech);
        if (mechanismHandler != null) {
            break;
        }
    }
    if (mechanismHandler == null) {
        if (AuthnSvcUtils.debug.messageEnabled()) {
            AuthnSvcUtils.debug.message("AuthnSvcRequestHanderImpl.processSASLRequest: " + "Unable to find mechanismHandler");
        }
        if (LogUtil.isLogEnabled()) {
            LogUtil.access(Level.INFO, LogUtil.AS_ABORT, data);
        }
        return new SASLResponse(SASLResponse.ABORT);
    } else {
        if (AuthnSvcUtils.debug.messageEnabled()) {
            AuthnSvcUtils.debug.message("AuthnSvcRequestHanderImpl.processSASLRequest: " + "mechanismHandler = " + mechanismHandler.getClass());
        }
    }
    SASLResponse saslResp = mechanismHandler.processSASLRequest(saslReq, message, respMessageID);
    if (LogUtil.isLogEnabled()) {
        String statusCode = saslResp.getStatusCode();
        if (statusCode.equals(SASLResponse.OK)) {
            LogUtil.access(Level.INFO, LogUtil.AS_OK, data);
        } else if (statusCode.equals(SASLResponse.CONTINUE)) {
            LogUtil.access(Level.INFO, LogUtil.AS_CONTINUE, data);
        } else {
            LogUtil.access(Level.INFO, LogUtil.AS_ABORT, data);
        }
    }
    return saslResp;
}
Also used : StringTokenizer(java.util.StringTokenizer) SASLResponse(com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse) MechanismHandler(com.sun.identity.liberty.ws.authnsvc.mechanism.MechanismHandler)

Aggregations

MechanismHandler (com.sun.identity.liberty.ws.authnsvc.mechanism.MechanismHandler)1 SASLResponse (com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse)1 StringTokenizer (java.util.StringTokenizer)1