use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.
the class SmsRealmProvider method handleQuery.
@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
if (!"true".equals(request.getQueryFilter().toString())) {
return new NotSupportedException("Query not supported: " + request.getQueryFilter()).asPromise();
}
if (request.getPagedResultsCookie() != null || request.getPagedResultsOffset() > 0 || request.getPageSize() > 0) {
return new NotSupportedException("Query paging not currently supported").asPromise();
}
final String principalName = PrincipalRestUtils.getPrincipalNameFromServerContext(context);
try {
final SessionID sessionID = new SessionID(getUserSsoToken(context).getTokenID().toString());
final String realmPath = coreWrapper.convertOrgNameToRealmName(sessionCache.getSession(sessionID).getClientDomain());
final OrganizationConfigManager ocm = new OrganizationConfigManager(getUserSsoToken(context), realmPath);
//Return realm query is being performed on
handler.handleResource(getResource(getJsonValue(realmPath)));
for (final Object subRealmRelativePath : ocm.getSubOrganizationNames("*", true)) {
String realmName;
if (realmPath.endsWith("/")) {
realmName = realmPath + subRealmRelativePath;
} else {
realmName = realmPath + "/" + subRealmRelativePath;
}
handler.handleResource(getResource(getJsonValue(realmName)));
}
debug.message("RealmResource :: QUERY : performed by {}", principalName);
return newResultPromise(newQueryResponse());
} catch (SSOException ex) {
debug.error("RealmResource :: QUERY by " + principalName + " failed : " + ex);
return new ForbiddenException().asPromise();
} catch (SessionException ex) {
debug.error("RealmResource :: QUERY by " + principalName + " failed : " + ex);
return new InternalServerErrorException().asPromise();
} catch (SMSException ex) {
debug.error("RealmResource :: QUERY by " + principalName + " failed :" + ex);
switch(ex.getExceptionCode()) {
case STATUS_NO_PERMISSION:
// This exception will be thrown if permission to read realms from SMS has not been delegated
return new ForbiddenException().asPromise();
default:
return new InternalServerErrorException().asPromise();
}
}
}
use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.
the class SessionCommand method getSessionList.
private List getSessionList(String name, String pattern) throws CLIException {
IOutput output = getOutputWriter();
List list = new ArrayList();
try {
String currentSessionHandler = curSession.getProperty(SESSION_HANDLE_PROP);
SearchResults result = curSession.getValidSessions(name, null);
String warning = getSearchResultWarningMessage(result);
if (warning.length() > 0) {
output.printlnMessage(warning);
}
Map<String, Session> sessions = (Map<String, Session>) result.getResultAttributes();
boolean isCurrentSession = false;
int i = 0;
for (Iterator iter = (Iterator) sessions.values().iterator(); iter.hasNext(); ) {
boolean isCurr = false;
Session sess = (Session) iter.next();
// need to check current session only if we have not found it.
if (!isCurrentSession) {
try {
isCurr = sess.getProperty(SESSION_HANDLE_PROP).equals(currentSessionHandler);
} catch (SessionException se) {
throw new CLIException(se, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
isCurrentSession = isCurr;
}
String userId = sess.getProperty(USER_ID);
if (userId != null) {
userId = dnToName(userId);
if (DisplayUtils.wildcardMatch(userId, pattern)) {
// -1 indicates that it is current session.
int idx = (isCurr) ? -1 : i++;
SessionData sData = createSessionData(idx, userId, sess);
if (idx == -1) {
list.add(0, sData);
} else {
list.add(sData);
}
}
}
}
} catch (SessionException se) {
throw new CLIException(se, ExitCodes.INVALID_OPTION_VALUE);
}
return list;
}
use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.
the class StatelessOperationsTest method shouldNotBlacklistSessionOnDestroyIfNotAllowed.
@Test(expectedExceptions = SessionException.class, expectedExceptionsMessageRegExp = "test")
public void shouldNotBlacklistSessionOnDestroyIfNotAllowed() throws Exception {
// Given
Session requester = mock(Session.class);
SessionException ex = new SessionException("test");
willThrow(ex).given(mockSessionService).checkPermissionToDestroySession(requester, sid);
// When
try {
statelessOperations.destroy(requester, mockSession);
} finally {
// Then
verifyZeroInteractions(mockSessionBlacklist);
}
}
use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.
the class CTSSessionBlacklistTest method shouldPropagateSessionExceptions.
@Test(expectedExceptions = SessionException.class)
public void shouldPropagateSessionExceptions() throws Exception {
// Given
given(mockSession.getBlacklistExpiryTime(anyLong())).willThrow(new SessionException("test"));
// When
testBlacklist.blacklist(mockSession);
// Then - exception
}
use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.
the class SessionService method getClusterMonitor.
/**
* The ClusterMonitor state depends on whether the system is configured for
* SFO or not. As such, this method is aware of the change in SFO state
* and triggers a re-initialisation of the ClusterMonitor as required.
*
* Note, this method also acts as the lazy initialiser for the ClusterMonitor.
*
* Thread Safety: Uses atomic reference to ensure only one thread can modify
* the reference at any one time.
*
* @return A non null instance of the current ClusterMonitor.
* @throws SessionException If there was an error initialising the ClusterMonitor.
*/
private ClusterMonitor getClusterMonitor() throws SessionException {
if (!isClusterMonitorValid()) {
try {
ClusterMonitor previous = clusterMonitor.getAndSet(resolveClusterMonitor());
if (previous != null) {
sessionDebug.message("Previous ClusterMonitor shutdown: {}", previous.getClass().getSimpleName());
previous.shutdown();
}
sessionDebug.message("ClusterMonitor initialised: {}", clusterMonitor.get().getClass().getSimpleName());
} catch (Exception e) {
sessionDebug.error("Failed to initialise ClusterMonitor", e);
}
}
ClusterMonitor monitor = clusterMonitor.get();
if (monitor == null) {
throw new SessionException("Failed to initialise ClusterMonitor");
}
return monitor;
}
Aggregations