use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.
the class SessionCookies method getLBCookie.
/**
* Returns load balancer cookie value for the Session.
* @param sid Session ID for load balancer cookie.
* @return load balancer cookie value.
* @throws SessionException if session is invalid.
*/
public String getLBCookie(SessionID sid) throws SessionException {
String cookieValue = null;
lbCookieName = SystemProperties.get(Constants.AM_LB_COOKIE_NAME, "amlbcookie");
if (sessionDebug.messageEnabled()) {
sessionDebug.message("Session.getLBCookie()" + "lbCookieName is:" + lbCookieName);
}
if (sid == null || StringUtils.isBlank(sid.toString())) {
throw new SessionException(SessionBundle.rbName, "invalidSessionID", null);
}
if (SystemProperties.isServerMode()) {
SessionService sessionService = InjectorHolder.getInstance(SessionService.class);
if (!sessionService.isSiteEnabled()) {
cookieValue = WebtopNaming.getLBCookieValue(sid.getSessionServerID());
return lbCookieName + "=" + cookieValue;
}
}
if (RESET_LB_COOKIE_NAME) {
if (SystemProperties.isServerMode()) {
SessionService sessionService = InjectorHolder.getInstance(SessionService.class);
if (sessionService.isSessionFailoverEnabled() && sessionService.isLocalSite(sid)) {
cookieValue = WebtopNaming.getLBCookieValue(sessionService.getCurrentHostServer(sid));
}
} else {
Session sess = sessionCache.readSession(sid);
if (sess != null) {
cookieValue = sess.getProperty(lbCookieName);
}
}
}
if (StringUtils.isBlank(cookieValue)) {
cookieValue = WebtopNaming.getLBCookieValue(sid.getExtension().getPrimaryID());
}
return lbCookieName + "=" + cookieValue;
}
use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.
the class SessionPLLSender method sendPLLRequest.
/**
* Returns a Session Response object based on the XML document received from
* remote Session Server. This is in response to a request that we send to
* the session server.
*
* @param svcurl The URL of the Session Service.
* @param sreq The Session Request XML document.
* @return a Vector of responses from the remote server
* @exception com.iplanet.dpro.session.SessionException if there was an error in sending the XML
* document or if the response has multiple components.
*/
public SessionResponse sendPLLRequest(URL svcurl, SessionRequest sreq) throws SessionException {
try {
String cookies = sessionCookies.getCookieName() + "=" + sreq.getSessionID();
if (!SystemProperties.isServerMode()) {
SessionID sessionID = new SessionID(sreq.getSessionID());
cookies = cookies + ";" + sessionCookies.getLBCookie(sessionID);
}
final Request req = new Request(sreq.toXMLString());
final RequestSet set = new RequestSet(SESSION_SERVICE);
set.addRequest(req);
final Vector responses = PLLClient.send(svcurl, cookies, set);
if (responses.size() != 1) {
throw new SessionException(SessionBundle.rbName, "unexpectedResponse", null);
}
final Response res = (Response) responses.elementAt(0);
return SessionResponse.parseXML(res.getContent());
} catch (Exception e) {
throw new SessionException(e);
}
}
use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.
the class SessionPollerSender method run.
public void run() {
try {
SessionRequest sreq = new SessionRequest(SessionRequest.GetSession, sid.toString(), false);
SessionResponse sres = pllSender.sendPLLRequest(session.getSessionServiceURL(), sreq);
if (sres.getException() != null) {
sessionCache.removeSID(sid);
return;
}
List<SessionInfo> infos = sres.getSessionInfo();
if (infos.size() == 1) {
info = infos.get(0);
}
} catch (Exception ex) {
sessionCache.removeSID(sid);
if (debug.messageEnabled())
debug.message("Could not connect to the session server" + ex.getMessage());
}
if (info != null) {
if (debug.messageEnabled()) {
debug.message("Updating" + info.toXMLString());
}
try {
if (info.getState().equals("invalid") || info.getState().equals("destroyed")) {
sessionCache.removeSID(sid);
} else {
long oldMaxCachingTime = session.getMaxCachingTime();
long oldMaxIdleTime = session.getMaxIdleTime();
long oldMaxSessionTime = session.getMaxSessionTime();
session.update(info);
if ((!session.isScheduled()) || (oldMaxCachingTime > session.getMaxCachingTime()) || (oldMaxIdleTime > session.getMaxIdleTime()) || (oldMaxSessionTime > session.getMaxSessionTime())) {
session.scheduleToTimerPool();
}
}
} catch (SessionException se) {
sessionCache.removeSID(sid);
debug.error("Exception encountered while update in polling", se);
}
} else {
sessionCache.removeSID(sid);
}
session.setIsPolling(false);
}
use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.
the class CDCServlet method redirectWithAuthNResponse.
/**
* Constructs the Liberty AuthNResponse with Restricted SSOToken
* and redirects the user to the requested resouce
*/
private void redirectWithAuthNResponse(HttpServletRequest request, HttpServletResponse response, SSOToken token) throws ServletException, IOException {
String gotoURL = getRedirectURL(request, response);
if (debug.messageEnabled()) {
debug.message("CDCServlet.redirectWithAuthNResponse: gotoURL = " + gotoURL);
}
if (debug.messageEnabled()) {
debug.message("CDCServlet.redirectWithAuthNResponse: After encoding: gotoURL = " + gotoURL);
}
if (gotoURL != null) {
try {
String inResponseTo = request.getParameter(REQUEST_ID);
String spDescriptor = request.getParameter(PROVIDER_ID);
String resTokenID = null;
/**
* validateAndGetRestriction throws an exception if an agent
* profile with provider id and goto url is not present
*/
TokenRestriction tokenRes = spValidator.validateAndGetRestriction(FSAuthnRequest.parseURLEncodedRequest(request), gotoURL);
if (uniqueCookieEnabled) {
resTokenID = sessionService.getRestrictedTokenId(token.getTokenID().toString(), tokenRes);
} else {
resTokenID = token.getTokenID().toString();
}
FSAssertion assertion = createAssertion(spDescriptor, SELF_PROVIDER_ID, resTokenID, token.getAuthType(), token.getProperty("authInstant"), token.getPrincipal().getName(), inResponseTo);
String relayState = request.getParameter(RELAY_STATE);
Status status = new Status(new StatusCode(IFSConstants.STATUS_CODE_SUCCESS));
FSAuthnResponse authnResponse = createAuthnResponse(SELF_PROVIDER_ID, responseID, inResponseTo, status, assertion, relayState);
sendAuthnResponse(request, response, authnResponse, gotoURL);
} catch (SAMLException se) {
debug.error("CDCServlet.doGetPost", se);
showError(response);
} catch (FSMsgException fe) {
debug.error("CDCServlet.doGetPost", fe);
showError(response);
} catch (FSException fse) {
debug.error("CDCServlet.doGetPost", fse);
showError(response);
} catch (SessionException e) {
debug.error("CDCServlet.doGetPost", e);
} catch (SSOException ssoe) {
debug.error("CDCServlet.doGetPost", ssoe);
} catch (Exception e) {
debug.error("CDCServlet.doGetPost", e);
spValidator = new LdapSPValidator();
showError(response, FORBIDDEN_STR_MATCH);
}
}
}
use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.
the class SessionUtils method getTrustedSourceList.
/* build the trust source set*/
private static Set getTrustedSourceList() throws SessionException {
Set result = new HashSet();
try {
String rawList = SystemProperties.get(Constants.TRUSTED_SOURCE_LIST);
if (rawList != null) {
StringTokenizer stk = new StringTokenizer(rawList, ",");
while (stk.hasMoreTokens()) {
result.add(InetAddress.getByName(stk.nextToken()));
}
} else {
// use platform server list as a default fallback
Set<String> psl = WebtopNaming.getPlatformServerList();
if (psl == null) {
throw new SessionException(SessionBundle.rbName, "emptyTrustedSourceList", null);
}
for (String e : psl) {
try {
URL url = new URL(e);
result.add(InetAddress.getByName(url.getHost()));
} catch (Exception ex) {
debug.error("SessionUtils.getTrustedSourceList : " + "Validating Host exception", ex);
}
}
}
} catch (Exception e) {
throw new SessionException(e);
}
return result;
}
Aggregations