use of com.iplanet.dpro.session.Session in project OpenAM by OpenRock.
the class MonitoredOperationsTest method destroyTest.
@Test
public void destroyTest() throws SessionException {
//given
Session mockRequester = mock(Session.class);
Session mockSession = mock(Session.class);
//when
testMoniteredOperations.destroy(mockRequester, mockSession);
//then
verify(mockSessionOperations, times(1)).destroy(mockRequester, mockSession);
verify(mockStore).storeDestroyTime(anyLong(), any(SessionMonitorType.class));
}
use of com.iplanet.dpro.session.Session in project OpenAM by OpenRock.
the class MonitoredOperationsTest method refreshTest.
@Test
public void refreshTest() throws SessionException {
//given
Session mockSession = mock(Session.class);
boolean reset = true;
//when
testMoniteredOperations.refresh(mockSession, reset);
//then
verify(mockSessionOperations).refresh(mockSession, reset);
verify(mockStore).storeRefreshTime(anyLong(), any(SessionMonitorType.class));
}
use of com.iplanet.dpro.session.Session in project OpenAM by OpenRock.
the class PrivilegeAuthzModule method evaluate.
/**
* Given the calling context and the privilege definition attempts to authorise the calling subject.
*
* @param context
* the server context
* @param definition
* the privilege definition
*
* @return the authorisation result
*/
protected Promise<AuthorizationResult, ResourceException> evaluate(final Context context, final PrivilegeDefinition definition) {
// If no realm is specified default to the root realm.
final String realm = (context.containsContext(RealmContext.class)) ? context.asContext(RealmContext.class).getResolvedRealm() : "/";
final SubjectContext subjectContext = context.asContext(SubjectContext.class);
final UriRouterContext routerContext = context.asContext(UriRouterContext.class);
// Map the set of actions to a set of action strings.
final Set<String> actions = transformSet(definition.getActions(), ACTION_TO_STRING_MAPPER);
try {
Session callerSession = subjectContext.getCallerSession();
if (callerSession == null) {
// you don't have a session so return access denied
return Promises.newResultPromise(AuthorizationResult.accessDenied("No session for request."));
}
final String loggedInRealm = coreWrapper.convertOrgNameToRealmName(callerSession.getClientDomain());
final DelegationPermission permissionRequest = permissionFactory.newInstance(loggedInRealm, REST, VERSION, routerContext.getMatchedUri(), definition.getCommonVerb(), actions, Collections.<String, String>emptyMap());
if (evaluator.isAllowed(subjectContext.getCallerSSOToken(), permissionRequest, Collections.<String, Set<String>>emptyMap()) && loggedIntoValidRealm(realm, loggedInRealm)) {
// Authorisation has been approved.
return Promises.newResultPromise(AuthorizationResult.accessPermitted());
}
} catch (DelegationException dE) {
return new InternalServerErrorException("Attempt to authorise the user has failed", dE).asPromise();
} catch (SSOException e) {
//you don't have a user so return access denied
return Promises.newResultPromise(AuthorizationResult.accessDenied("No user supplied in request."));
}
return Promises.newResultPromise(AuthorizationResult.accessDenied("The user has insufficient privileges"));
}
use of com.iplanet.dpro.session.Session in project OpenAM by OpenRock.
the class SSOProviderImpl method createSSOToken.
/**
* Creates a single sign on token for the <code>HttpRequest</code>
*
* @param request <code>HttpServletRequest</code>
* @return single sign on token for the request
* @throws SSOException if the single sign on token cannot be created.
*/
public SSOToken createSSOToken(HttpServletRequest request) throws SSOException {
try {
SessionID sid = new SessionID(request);
Session session = sessionCache.getSession(sid);
if (sid != null) {
Boolean cookieMode = sid.getCookieMode();
if (debug.messageEnabled()) {
debug.message("cookieMode is :" + cookieMode);
}
if (cookieMode != null) {
session.setCookieMode(cookieMode);
}
}
if (checkIP && !isIPValid(session, ClientUtils.getClientIPAddress(request))) {
throw new Exception(SSOProviderBundle.getString("invalidIP"));
}
SSOToken ssoToken = new SSOTokenImpl(session);
return ssoToken;
} catch (Exception e) {
if (debug.messageEnabled()) {
debug.message("could not create SSOToken from HttpRequest (" + e.getMessage() + ")");
}
throw new SSOException(e);
}
}
use of com.iplanet.dpro.session.Session in project OpenAM by OpenRock.
the class DestroyNextExpiringAction method action.
@Override
public boolean action(InternalSession is, Map<String, Long> sessions) {
String nextExpiringSessionID = null;
long smallestExpTime = Long.MAX_VALUE;
for (Map.Entry<String, Long> entry : sessions.entrySet()) {
String sid = entry.getKey();
long expirationTime = entry.getValue();
if (expirationTime < smallestExpTime) {
smallestExpTime = expirationTime;
nextExpiringSessionID = sid;
}
}
if (nextExpiringSessionID != null) {
SessionID sessID = new SessionID(nextExpiringSessionID);
try {
Session s = sessionCache.getSession(sessID);
s.destroySession(s);
} catch (SessionException e) {
if (debug.messageEnabled()) {
debug.message("Failed to destroy the next " + "expiring session.", e);
}
// in this case
return true;
}
}
return false;
}
Aggregations