package authentication; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.webratio.rtx.Pair; import com.webratio.rtx.RTXConstants; import com.webratio.rtx.RTXCredentialsService; import com.webratio.rtx.RTXException; import com.webratio.rtx.RTXManager; import com.webratio.rtx.RTXPermissionException; import com.webratio.rtx.core.BeanHelper; /** * The SiteMinder credentials service * */ public class SiteMinderCredentialsService implements RTXCredentialsService { /** The shared log instance */ private static Log LOG = LogFactory.getLog(SiteMinderCredentialsService.class); /* * (non-Javadoc) * * @see com.webratio.rtx.RTXCredentialsService#getCredentials(java.util.Map, java.util.Map, com.webratio.rtx.RTXManager) */ public Pair getCredentials(Map localContext, Map sessionContext, RTXManager mgr) throws RTXPermissionException, RTXException { LOG.debug("Extract userName from HTTP request header"); /* retrieves the HTTP request */ HttpServletRequest request = (HttpServletRequest) localContext.get(RTXConstants.HTTP_SERVLET_REQUEST_KEY); /* extracts single sign-on header value */ String userName = request.getHeader("SM_USER"); LOG.debug("Site Minder User = '" + userName + "'"); if (StringUtils.isBlank(userName)) { return null; } userName = userName.toUpperCase(); if (userName.indexOf('\\') > -1) { userName = userName.substring(userName.indexOf('\\') + 1); } else if (userName.indexOf('/') > -1) { userName = userName.substring(userName.indexOf('/') + 1); } /* performs the login */ LOG.debug("Perform login for userName '" + userName + "'"); mgr.getAuthenticationService().performLogin(userName, null, localContext, sessionContext); /* logs retrieved userOid and groupOid */ if (LOG.isDebugEnabled()) { String userOid = BeanHelper.asString(sessionContext.get(RTXConstants.CURRENT_USER_CTX_PARAM_KEY)); String groupOid = BeanHelper.asString(sessionContext.get(RTXConstants.CURRENT_GROUP_CTX_PARAM_KEY)); LOG.debug("Retrieved credentials: " + userOid + " : " + groupOid); } return null; } }