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 Oracle Single Sign-On credentials service * */ public class OSSOCredentialsService implements RTXCredentialsService { /** The shared log instance */ private static Log LOG = LogFactory.getLog(OSSOCredentialsService.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("Osso-User-Dn"); LOG.debug("OSSO User DN = " + userName); if (StringUtils.isBlank(userName)) { return null; } userName = StringUtils.substringAfter(userName, "cn="); userName = StringUtils.substringBefore(userName, ",").trim(); /* 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; } }