508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson/**
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson *
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson *
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * The contents of this file are subject to the terms
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * of the Common Development and Distribution License
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * (the License). You may not use this file except in
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * compliance with the License.
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson *
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * You can obtain a copy of the License at
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * https://opensso.dev.java.net/public/CDDLv1.0.html or
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * opensso/legal/CDDLv1.0.txt
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * See the License for the specific language governing
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * permission and limitations under the License.
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson *
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * When distributing Covered Code, include this CDDL
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * Header Notice in each file and include the License file
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * at opensso/legal/CDDLv1.0.txt.
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * If applicable, add the following below the CDDL Header,
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * with the fields enclosed by brackets [] replaced by
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * your own identifying information:
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * "Portions Copyrighted [year] [name of copyright owner]"
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson *
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * $Id: AuthnSvcRequestHandlerImpl.java,v 1.2 2008/06/25 05:47:06 qcheng Exp $
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson *
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson */
6628d1d9db933d9d322961047f8f63a300eff6ecJames C. McPherson
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonpackage com.sun.identity.liberty.ws.authnsvc;
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonimport java.util.List;
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonimport java.util.StringTokenizer;
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonimport java.util.logging.Level;
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonimport org.w3c.dom.Element;
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonimport com.sun.identity.liberty.ws.authnsvc.mechanism.MechanismHandler;
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonimport com.sun.identity.liberty.ws.authnsvc.protocol.SASLRequest;
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonimport com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse;
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonimport com.sun.identity.liberty.ws.common.LogUtil;
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonimport com.sun.identity.liberty.ws.soapbinding.Message;
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonimport com.sun.identity.liberty.ws.soapbinding.RequestHandler;
7014882c6a3672fd0e5d60200af8643ae53c5928Richard Lowe
7014882c6a3672fd0e5d60200af8643ae53c5928Richard Lowe/**
7014882c6a3672fd0e5d60200af8643ae53c5928Richard Lowe * The class <code>AuthnSvcRequestHandlerImpl</code> is used to process
7014882c6a3672fd0e5d60200af8643ae53c5928Richard Lowe * SASL requests.
7014882c6a3672fd0e5d60200af8643ae53c5928Richard Lowe */
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPhersonpublic final class AuthnSvcRequestHandlerImpl implements RequestHandler {
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson /**
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * Default constructor
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson */
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson public AuthnSvcRequestHandlerImpl() {
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson if (AuthnSvcUtils.debug.messageEnabled()) {
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson AuthnSvcUtils.debug.message(
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson "AuthnSvcRequestHanderImpl constructor.");
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson }
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson }
7014882c6a3672fd0e5d60200af8643ae53c5928Richard Lowe
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson /**
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * Extracts SASL request out of a SOAP Message and processes it.
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * @param request a SOAP Message containing a SASL request
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * @return a SOAP Message containing a SASL response
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * @exception AuthnSvcException if an error occurs while processing the
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson * SOAP Message
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson */
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson public Message processRequest(Message request) throws AuthnSvcException {
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson List list = request.getBodies(AuthnSvcConstants.NS_AUTHN_SVC,
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson AuthnSvcConstants.TAG_SASL_REQUEST);
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson if (list.isEmpty()) {
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson throw new AuthnSvcException("missingSASLRequet");
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson } else if (list.size() > 1) {
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson throw new AuthnSvcException("tooManySASLRequet");
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson }
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson SASLRequest saslReq = new SASLRequest((Element)list.get(0));
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson saslReq.setMessageID(request.getCorrelationHeader().getMessageID());
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson saslReq.setRefToMessageID(request.getCorrelationHeader()
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson .getRefToMessageID());
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson Message message = new Message();
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson String respMessageID = message.getCorrelationHeader().getMessageID();
508aff1a85ed04f187fd074799bcaefd630490f1James C. McPherson SASLResponse saslResp = processSASLRequest(saslReq, request,
respMessageID);
message.setSOAPBody(saslResp.toElement());
return message;
}
/**
* 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;
}
}