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;
}
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);
}
}
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;
}
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;
}
Aggregations