Search in sources :

Example 6 with SASLResponse

use of com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse in project OpenAM by OpenRock.

the class PlainMechanismHandler method processSASLRequest.

/**
     * Generates a SASL response according to the SASL request.
     * @param saslReq a SASL request
     * @param message a SOAP Message containing the SASL request
     * @param respMessageID messageID of SOAP Message response that will
     *                      contain returned SASL response
     * @return a SASL response
     */
public SASLResponse processSASLRequest(SASLRequest saslReq, Message message, String respMessageID) {
    if (debug.messageEnabled()) {
        debug.message("PlainMechanismHandler.processSASLRequest: ");
    }
    String refToMessageID = saslReq.getRefToMessageID();
    boolean isFirstRequest = (refToMessageID == null || refToMessageID.length() == 0);
    if (debug.messageEnabled()) {
        debug.message("PlainMechanismHandler.processSASLRequest: " + "refToMessageID = " + refToMessageID);
    }
    SASLResponse saslResp = null;
    byte[] data = saslReq.getData();
    if (data == null) {
        if (isFirstRequest) {
            saslResp = new SASLResponse(SASLResponse.CONTINUE);
            saslResp.setServerMechanism(AuthnSvcConstants.MECHANISM_PLAIN);
        } else {
            saslResp = new SASLResponse(SASLResponse.ABORT);
        }
    } else {
        String dataStr = null;
        try {
            dataStr = new String(data, "UTF-8");
        } catch (Exception ex) {
            debug.error("PlainMechanismHandler.processSASLRequest: ", ex);
        }
        if (dataStr == null) {
            saslResp = new SASLResponse(SASLResponse.ABORT);
        } else {
            saslResp = authenticate(dataStr, message);
        }
        if (isFirstRequest) {
            saslResp.setServerMechanism(AuthnSvcConstants.MECHANISM_PLAIN);
        }
    }
    return saslResp;
}
Also used : SASLResponse(com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException)

Example 7 with SASLResponse

use of com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse in project OpenAM by OpenRock.

the class SSOTokenMechanismHandler method authenticate.

private SASLResponse authenticate(String data, Message message) {
    if (AuthnSvcUtils.debug.messageEnabled()) {
        AuthnSvcUtils.debug.message("SSOTokenMechanismHandler.authenticate: " + "SSOTokenID = " + data);
    }
    try {
        SSOTokenManager manager = SSOTokenManager.getInstance();
        SSOToken token = manager.createSSOToken(data);
        manager.validateToken(token);
        String userDN = token.getPrincipal().getName();
        SASLResponse saslResp = new SASLResponse(SASLResponse.OK);
        if (!AuthnSvcUtils.setResourceOfferingAndCredentials(saslResp, message, userDN)) {
            return new SASLResponse(SASLResponse.ABORT);
        }
        return saslResp;
    } catch (Exception ex) {
        AuthnSvcUtils.debug.error("SSOTokenMechanismHandler.authenticate: ", ex);
        return new SASLResponse(SASLResponse.ABORT);
    }
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) SASLResponse(com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse) SSOException(com.iplanet.sso.SSOException)

Example 8 with SASLResponse

use of com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse in project OpenAM by OpenRock.

the class SSOTokenMechanismHandler method processSASLRequest.

/**
     * Generates a SASL response according to the SASL request
     * @param saslReq a SASL request
     * @param message a SOAP Message containing the SASL request
     * @param respMessageID messageID of SOAP Message response that will
     *                      contain returned SASL response
     * @return a SASL response
     */
public SASLResponse processSASLRequest(SASLRequest saslReq, Message message, String respMessageID) {
    if (AuthnSvcUtils.debug.messageEnabled()) {
        AuthnSvcUtils.debug.message("SSOTokenMechanismHandler.processSASLRequest: ");
    }
    String refToMessageID = saslReq.getRefToMessageID();
    boolean isFirstRequest = (refToMessageID == null || refToMessageID.length() == 0);
    if (AuthnSvcUtils.debug.messageEnabled()) {
        AuthnSvcUtils.debug.message("SSOTokenMechanismHandler.processSASLRequest: " + "refToMessageID = " + refToMessageID);
    }
    SASLResponse saslResp = null;
    byte[] data = saslReq.getData();
    if (data == null) {
        if (isFirstRequest) {
            saslResp = new SASLResponse(SASLResponse.CONTINUE);
            saslResp.setServerMechanism(MECHANISM_SSOTOKEN);
        } else {
            saslResp = new SASLResponse(SASLResponse.ABORT);
        }
    } else {
        String dataStr = null;
        try {
            dataStr = new String(data, "UTF-8");
        } catch (Exception ex) {
            AuthnSvcUtils.debug.error("SSOTokenMechanismHandler.processSASLRequest: ", ex);
        }
        if (dataStr == null) {
            saslResp = new SASLResponse(SASLResponse.ABORT);
        } else {
            saslResp = authenticate(dataStr, message);
        }
        if (isFirstRequest) {
            saslResp = new SASLResponse(SASLResponse.CONTINUE);
            saslResp.setServerMechanism(MECHANISM_SSOTOKEN);
        }
    }
    return saslResp;
}
Also used : SASLResponse(com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse) SSOException(com.iplanet.sso.SSOException)

Example 9 with SASLResponse

use of com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse 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

SASLResponse (com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse)9 SSOException (com.iplanet.sso.SSOException)6 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)4 SSOToken (com.iplanet.sso.SSOToken)3 AuthContext (com.sun.identity.authentication.AuthContext)2 IdRepoException (com.sun.identity.idm.IdRepoException)2 Message (com.sun.identity.liberty.ws.soapbinding.Message)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 List (java.util.List)2 Callback (javax.security.auth.callback.Callback)2 NameCallback (javax.security.auth.callback.NameCallback)2 PasswordCallback (javax.security.auth.callback.PasswordCallback)2 SSOTokenManager (com.iplanet.sso.SSOTokenManager)1 MechanismHandler (com.sun.identity.liberty.ws.authnsvc.mechanism.MechanismHandler)1 SASLRequest (com.sun.identity.liberty.ws.authnsvc.protocol.SASLRequest)1 StringTokenizer (java.util.StringTokenizer)1