use of com.iplanet.dpro.session.SessionID in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeLevelWithSessionUpgrade.
@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeLevelWithSessionUpgrade() throws AuthException, AuthLoginException, SSOException, RestAuthException {
//Given
LoginConfiguration loginConfiguration = new LoginConfiguration();
HttpServletRequest request = mock(HttpServletRequest.class);
String sessionId = null;
AuthIndexType authIndexType = AuthIndexType.LEVEL;
String authIndexValue = "15";
String ssoTokenId = "SSO_TOKEN_ID";
AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
SSOToken ssoToken = mock(SSOToken.class);
loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue).sessionUpgrade(ssoTokenId);
given(ssoToken.getProperty("AuthLevel")).willReturn("10");
given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn("ORG_DN");
given(coreServicesWrapper.getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(true), eq(false))).willReturn(authContextLocalWrapper);
given(coreServicesWrapper.getExistingValidSSOToken(eq(new SessionID("SSO_TOKEN_ID")))).willReturn(ssoToken);
given(coreServicesWrapper.isNewRequest(authContextLocalWrapper)).willReturn(true);
given(coreServicesWrapper.doesValueContainKey(anyString(), anyString())).willReturn(false);
given(coreServicesWrapper.doesValueContainKey("INDEX_VALUE", "INDEX_VALUE")).willReturn(true);
given(authContextLocalWrapper.isSessionUpgrade()).willReturn(true);
//When
LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
//Then
verify(authContextLocalWrapper).login(AuthContext.IndexType.LEVEL, "15");
assertNotNull(loginProcess);
}
use of com.iplanet.dpro.session.SessionID in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeCompositeWithSessionUpgrade.
@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeCompositeWithSessionUpgrade() throws AuthException, AuthLoginException, SSOException, RestAuthException {
//Given
LoginConfiguration loginConfiguration = new LoginConfiguration();
HttpServletRequest request = mock(HttpServletRequest.class);
String sessionId = null;
AuthIndexType authIndexType = AuthIndexType.COMPOSITE;
String authIndexValue = "INDEX_VALUE";
String ssoTokenId = "SSO_TOKEN_ID";
AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
SSOToken ssoToken = mock(SSOToken.class);
loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue).sessionUpgrade(ssoTokenId);
given(coreServicesWrapper.getDomainNameByRequest(Matchers.<HttpServletRequest>anyObject())).willReturn("ORG_DN");
given(coreServicesWrapper.getAuthContext((HttpServletRequest) anyObject(), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(true), eq(false))).willReturn(authContextLocalWrapper);
given(authContextLocalWrapper.isSessionUpgrade()).willReturn(true);
given(coreServicesWrapper.getExistingValidSSOToken(eq(new SessionID("SSO_TOKEN_ID")))).willReturn(ssoToken);
given(coreServicesWrapper.isNewRequest(authContextLocalWrapper)).willReturn(true);
//When
LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
//Then
verify(authContextLocalWrapper).login(AuthContext.IndexType.COMPOSITE_ADVICE, "INDEX_VALUE");
assertNotNull(loginProcess);
}
use of com.iplanet.dpro.session.SessionID in project OpenAM by OpenRock.
the class NamingService method usePreferredNamingURL.
private URL usePreferredNamingURL(NamingRequest request, float reqVersion) throws ServerEntryNotFoundException, MalformedURLException {
String preferredNamingURL = null;
URL preferredURL = null;
if (request == null) {
return null;
}
preferredNamingURL = request.getPreferredNamingURL();
if (preferredNamingURL == null) {
return null;
}
String sessionid = request.getSessionId();
if (sessionid == null) {
return null;
}
URL url = new URL(request.getPreferredNamingURL());
String uri = (reqVersion < 3.0) ? SystemProperties.get(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR) : WebtopNaming.getURI(url);
String serverID = WebtopNaming.getServerID(url.getProtocol(), url.getHost(), Integer.toString(url.getPort()), uri);
SessionID sessionID = new SessionID(sessionid);
String primary_id = sessionID.getExtension().getPrimaryID();
if (primary_id != null) {
String secondarysites = WebtopNaming.getSecondarySites(primary_id);
if ((secondarysites != null) && (serverID != null)) {
if (secondarysites.indexOf(serverID) != -1) {
preferredURL = url;
}
}
}
return preferredURL;
}
use of com.iplanet.dpro.session.SessionID in project OpenAM by OpenRock.
the class SSOProviderImpl method createSSOToken.
/**
* Creates a single sign on token.
*
* @param tokenId single sign on token ID.
* @param invokedByAuth boolean flag indicating that this method has been invoked by the AuthContext.getSSOToken()
* API.
* @param possiblyResetIdleTime If true, the idle time of the token/session may be reset to zero. If false, the
* idle time will never be reset.
* @return single sign on token.
* @throws SSOException if the single sign on token cannot be created for any reason.
* @throws java.lang.UnsupportedOperationException only here to satisfy the interface, this is never thrown.
*/
public SSOToken createSSOToken(String tokenId, boolean invokedByAuth, boolean possiblyResetIdleTime) throws SSOException, UnsupportedOperationException {
try {
SessionID sessionId = new SessionID(tokenId);
sessionId.setComingFromAuth(invokedByAuth);
Session session = sessionCache.getSession(sessionId, false, possiblyResetIdleTime);
SSOToken ssoToken = new SSOTokenImpl(session);
return ssoToken;
} catch (Exception e) {
if (debug.messageEnabled()) {
debug.message("SSOProviderImpl.createSSOToken(tokenId, " + invokedByAuth + ", " + possiblyResetIdleTime + ") could not create SSOToken for token ID \"" + tokenId + "\" (" + e.getMessage() + ")");
}
throw new SSOException(e);
}
}
use of com.iplanet.dpro.session.SessionID in project OpenAM by OpenRock.
the class SSOProviderImpl method logout.
@Override
public void logout(final SSOToken token) throws SSOException {
try {
Session session = sessionCache.getSession(new SessionID(token.getTokenID().toString()));
session.logout();
} catch (SessionException e) {
if (debug.messageEnabled()) {
debug.message("Logout: ", e);
}
throw new SSOException(e);
}
}
Aggregations