use of com.iplanet.dpro.session.service.InternalSession in project OpenAM by OpenRock.
the class LogoutViewBean method forwardTo.
/**
* Forwards the request to this view bean, displaying the page. This
* method is the equivalent of <code>RequestDispatcher.forward()</code>,
* meaning that the same semantics apply to the use of this method.
* This method makes implicit use of the display URL returned
* by the <code>getDisplayURL()</code> method.
* @param requestContext servlet context for auth request
*/
public void forwardTo(RequestContext requestContext) {
SessionID sessionID = null;
SSOToken token = null;
InternalSession intSess = null;
java.util.Locale locale = null;
logoutDebug.message("In forwardTo()");
if (requestContext != null) {
request = requestContext.getRequest();
response = requestContext.getResponse();
}
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "0");
gotoUrl = request.getParameter("goto");
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Goto query param : " + gotoUrl);
}
try {
sessionID = new SessionID(request);
intSess = AuthD.getSession(sessionID);
if (intSess != null) {
populateL10NFileAttrs(intSess);
String localeStr = intSess.getProperty(ISAuthConstants.LOCALE);
// I18N get resource bundle
locale = com.sun.identity.shared.locale.Locale.getLocale(localeStr);
fallbackLocale = locale;
} else {
ISLocaleContext localeContext = new ISLocaleContext();
localeContext.setLocale(request);
locale = localeContext.getLocale();
if (locale == null) {
String localeStr = AuthD.getAuth().getPlatformLocale();
locale = com.sun.identity.shared.locale.Locale.getLocale(localeStr);
}
}
rb = (ResourceBundle) rbCache.getResBundle("amAuthUI", locale);
clientType = AuthUtils.getClientType(request);
if (logoutDebug.messageEnabled()) {
logoutDebug.message("clienttype is : " + clientType);
}
token = SSOTokenManager.getInstance().createSSOToken(sessionID.toString());
} catch (Exception e) {
ResultVal = getL10NMessage(e, locale);
}
// Get the Login URL and query map
if (token != null) {
try {
loginURL = token.getProperty(ISAuthConstants.FULL_LOGIN_URL);
} catch (com.iplanet.sso.SSOException ssoExp) {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("LogoutViewBean.forwardTo: " + " Cannot get Login URL");
}
}
}
// If there is a gotoUrl value and the orgDN is null do some additional processing
if (orgDN == null && isGotoSet()) {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("OrgDN was null, getting from request for goto validation");
}
// First check if there is a org parameter in request, for example realm=/sub-realm
String orgParm = AuthUtils.getOrgParam(AuthUtils.parseRequestParameters(request));
if (orgParm == null) {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Attempting to get orgDN from AuthUtils for serverName " + request.getServerName());
}
orgDN = AuthUtils.getOrganizationDN(request.getServerName(), true, request);
} else {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Attempting to get orgDN from AuthUtils for orgParm " + orgParm);
}
orgDN = AuthUtils.getOrganizationDN(orgParm, true, request);
}
if (orgDN == null) {
// Last resort, get it from the root domain
orgDN = DNMapper.orgNameToDN("/");
}
}
if (isGotoSet()) {
gotoUrl = AuthUtils.getValidGotoURL(request, orgDN);
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Goto after validation for orgDN: " + orgDN + " gotoUrl: " + gotoUrl);
}
}
// set the cookie Value or set the logoutcookie string in
// the case of URL rewriting otherwise set in the responsed
// header
Cookie[] cookieArr = request.getCookies();
if ((cookieArr != null) && (cookieArr.length != 0)) {
cookieSupported = true;
} else {
cookieSupported = false;
}
if (cookieSupported) {
logoutDebug.message("Cookie is supported");
AuthUtils.clearAllCookies(request, response);
} else {
logoutDebug.message("Cookie is not supported");
if ((sessionID != null) && (sessionID.toString().length() != 0)) {
logoutCookie = AuthUtils.getLogoutCookieString(sessionID);
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Logout Cookie is " + logoutCookie);
}
}
}
// get the Logout JSP page path
jsp_page = appendLogoutCookie(getFileName(LOGOUT_JSP));
if ((intSess != null) && intSess.isTimedOut()) {
try {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Goto Login URL : " + loginURL);
}
if (doSendRedirect(loginURL)) {
response.sendRedirect(appendLogoutCookie(loginURL));
return;
} else {
int queryIndex = loginURL.indexOf("?");
String qString = null;
if (queryIndex != -1) {
qString = loginURL.substring(queryIndex);
}
if (qString != null) {
jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP) + qString);
} else {
jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP));
}
}
} catch (Exception e) {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Redirect failed : " + loginURL, e);
}
ResultVal = getL10NMessage(e, locale);
}
super.forwardTo(requestContext);
return;
}
boolean wasTokenValid = false;
try {
wasTokenValid = AuthUtils.logout(intSess, token, request, response);
ResultVal = rb.getString("logout.successful");
String postProcessURL = AuthUtils.getPostProcessURL(request, AMPostAuthProcessInterface.POST_PROCESS_LOGOUT_URL);
if (postProcessURL != null) {
gotoUrl = postProcessURL;
}
} catch (SSOException ssoe) {
try {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Exception during logout", ssoe);
logoutDebug.message("Goto Login URL : " + LOGINURL);
}
if (doSendRedirect(LOGINURL)) {
response.sendRedirect(appendLogoutCookie(LOGINURL));
return;
} else {
jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP));
}
} catch (Exception ex) {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Redirect failed:" + LOGINURL, ex);
}
ResultVal = ex.getMessage();
}
super.forwardTo(requestContext);
return;
}
if (!wasTokenValid) {
if (!isGotoSet()) {
String originalRedirectURL = AuthUtils.getOrigRedirectURL(request, sessionID);
if (originalRedirectURL != null) {
try {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Original Redirect URL: " + originalRedirectURL);
}
int index = originalRedirectURL.indexOf("/Login");
if (index != -1) {
originalRedirectURL = originalRedirectURL.substring(0, index) + "/Logout";
}
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Redirect to Original Redirect URL :" + originalRedirectURL);
}
if (doSendRedirect(originalRedirectURL)) {
response.sendRedirect(appendLogoutCookie(originalRedirectURL));
return;
}
} catch (Exception e) {
ResultVal = getL10NMessage(e, locale);
}
} else {
try {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Goto LOGINURL : " + LOGINURL);
}
if (doSendRedirect(LOGINURL)) {
response.sendRedirect(appendLogoutCookie(LOGINURL));
return;
} else {
jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP));
}
} catch (Exception e) {
ResultVal = getL10NMessage(e, locale);
}
}
}
}
if (!redirectToGoto(locale)) {
super.forwardTo(requestContext);
}
}
use of com.iplanet.dpro.session.service.InternalSession in project OpenAM by OpenRock.
the class CTSOperationsTest method shouldReadTokenFromCTS.
@Test
public void shouldReadTokenFromCTS() throws CoreTokenException, SessionException {
// Given
Token mockToken = mock(Token.class);
given(mockCTS.read(anyString())).willReturn(mockToken);
InternalSession mockInternalSession = mock(InternalSession.class);
given(mockAdapter.fromToken(eq(mockToken))).willReturn(mockInternalSession);
SessionInfo mockSessionInfo = mock(SessionInfo.class);
given(mockInfoFactory.getSessionInfo(eq(mockInternalSession), any(SessionID.class))).willReturn(mockSessionInfo);
// When
SessionInfo result = ctsOperations.refresh(mockSession, false);
// Then
assertThat(result).isEqualTo(mockSessionInfo);
}
use of com.iplanet.dpro.session.service.InternalSession in project OpenAM by OpenRock.
the class CTSOperationsTest method shouldInvokeRemoteActionDuringSetProperty.
@Test
public void shouldInvokeRemoteActionDuringSetProperty() throws SessionException, CoreTokenException {
// Given
String name = "name";
String value = "value";
SessionID mockSessionID = mock(SessionID.class);
given(mockSession.getID()).willReturn(mockSessionID);
Token mockToken = mock(Token.class);
given(mockCTS.read(anyString())).willReturn(mockToken);
InternalSession mockInternalSession = mock(InternalSession.class);
given(mockAdapter.fromToken(eq(mockToken))).willReturn(mockInternalSession);
// When
ctsOperations.setProperty(mockSession, name, value);
// Then
verify(mockRemote).setProperty(mockSession, name, value);
}
use of com.iplanet.dpro.session.service.InternalSession in project OpenAM by OpenRock.
the class CTSOperationsTest method shouldResetLastAccessTimeRemotely.
@Test
public void shouldResetLastAccessTimeRemotely() throws CoreTokenException, SessionException {
// Given
Token mockToken = mock(Token.class);
given(mockCTS.read(anyString())).willReturn(mockToken);
InternalSession mockInternalSession = mock(InternalSession.class);
given(mockAdapter.fromToken(eq(mockToken))).willReturn(mockInternalSession);
// When
ctsOperations.refresh(mockSession, true);
// Then
verify(mockRemote).refresh(mockSession, true);
}
use of com.iplanet.dpro.session.service.InternalSession in project OpenAM by OpenRock.
the class HOTP method init.
public void init(Subject subject, Map sharedState, Map options) {
currentConfig = options;
String authLevel = CollectionHelper.getMapAttr(options, AUTHLEVEL);
if (authLevel != null) {
try {
setAuthLevel(Integer.parseInt(authLevel));
} catch (Exception e) {
debug.error("HOTP.init() : " + "Unable to set auth level " + authLevel, e);
}
}
gatewaySMSImplClass = CollectionHelper.getMapAttr(options, GATEWAYSMSImplCLASS);
codeValidityDuration = CollectionHelper.getMapAttr(options, CODEVALIDITYDURATION);
codeLength = CollectionHelper.getMapAttr(options, CODELENGTH);
codeDelivery = CollectionHelper.getMapAttr(options, CODEDELIVERY);
telephoneAttribute = CollectionHelper.getMapAttr(options, ATTRIBUTEPHONE);
carrierAttribute = CollectionHelper.getMapAttr(options, ATTRIBUTECARRIER);
emailAttribute = CollectionHelper.getMapAttr(options, ATTRIBUTEEMAIL);
try {
userSearchAttributes = getUserAliasList();
} catch (final AuthLoginException ale) {
debug.warning("HOTP.init: unable to retrieve search attributes", ale);
}
if (debug.messageEnabled()) {
debug.message("HOTP.init() : " + "telephone attribute=" + telephoneAttribute + " carrier attribute=" + carrierAttribute + " email attribute=" + emailAttribute + " user search attributes=" + userSearchAttributes);
}
java.util.Locale locale = getLoginLocale();
bundle = amCache.getResBundle(amAuthHOTP, locale);
if (debug.messageEnabled()) {
debug.message("HOTP.init() : " + "HOTP resouce bundle locale=" + locale);
}
userName = (String) sharedState.get(getUserKey());
if (userName == null || userName.isEmpty()) {
try {
//Session upgrade case. Need to find the user ID from the old session.
SSOTokenManager mgr = SSOTokenManager.getInstance();
InternalSession isess = getLoginState("HOTP").getOldSession();
if (isess == null) {
throw new AuthLoginException("amAuth", "noInternalSession", null);
}
SSOToken token = mgr.createSSOToken(isess.getID().toString());
userUUID = token.getPrincipal().getName();
userName = token.getProperty("UserToken");
if (debug.messageEnabled()) {
debug.message("HOTP.init() : UserName in SSOToken : " + userName);
}
} catch (SSOException ssoe) {
debug.error("HOTP.init() : Unable to retrieve userName from existing session", ssoe);
} catch (AuthLoginException ale) {
debug.error("HOTP.init() : Unable to retrieve userName from existing session", ale);
}
}
this.sharedState = sharedState;
if (sharedState.containsKey(SKIP_HOTP)) {
skip = (Boolean) sharedState.get(SKIP_HOTP);
}
hotpAutoClicking = CollectionHelper.getMapAttr(options, AUTO_CLICKING).equals("true");
HOTPParams hotpParams = new HOTPParams(gatewaySMSImplClass, Long.parseLong(codeValidityDuration), telephoneAttribute, carrierAttribute, emailAttribute, codeDelivery, currentConfig, Integer.parseInt(codeLength), bundle.getString("messageSubject"), bundle.getString("messageContent"), FROM_ADDRESS, userSearchAttributes);
hotpService = new HOTPService(getAMIdentityRepository(getRequestOrg()), userName, hotpParams);
}
Aggregations