use of com.iplanet.sso.SSOTokenManager in project OpenAM by OpenRock.
the class AuthClientUtils method isTimedOut.
// Check for Session Timed Out
// If Session is Timed Out Exception is thrown
public static boolean isTimedOut(SessionID sessID) {
boolean isTimedOut = false;
try {
if (sessID != null) {
String sidString = sessID.toString();
SSOTokenManager manager = SSOTokenManager.getInstance();
SSOToken currentToken = manager.createSSOToken(sidString);
if (manager.isValidToken(currentToken)) {
isTimedOut = false;
}
}
} catch (Exception e) {
if (e.getMessage().indexOf("Session timed out") != -1) {
isTimedOut = true;
}
}
if (utilDebug.messageEnabled()) {
utilDebug.message("Session Timed Out :" + isTimedOut);
}
return isTimedOut;
}
use of com.iplanet.sso.SSOTokenManager in project OpenAM by OpenRock.
the class AuthClientUtils method getCookieURLForSessionUpgrade.
public static String getCookieURLForSessionUpgrade(HttpServletRequest request) {
String cookieURL = null;
try {
SSOTokenManager tokenManager = SSOTokenManager.getInstance();
SSOToken token = tokenManager.createSSOToken(request);
Hashtable reqDataHash = parseRequestParameters(request);
if (tokenManager.isValidToken(token)) {
cookieURL = getCookieURL(new SessionID(token.getTokenID().toString()));
if (cookieURL != null && !isLocalServer(cookieURL, true) && (forceAuthFlagExists(reqDataHash) || checkSessionUpgrade(token, reqDataHash))) {
return cookieURL;
}
}
} catch (SSOException ssoe) {
if (utilDebug.messageEnabled()) {
utilDebug.message("SSOException occurred while checking session upgrade case", ssoe);
}
}
return null;
}
use of com.iplanet.sso.SSOTokenManager in project OpenAM by OpenRock.
the class EvaluatePolicyServlet method processRequest.
/**
* Reads the resource which the user needs to access from the servlet
* request parameter <code>resource</code>.
* if the user's session is invalid, the user gets redirected to the
* amserver login page to log in first.
* Once the session is valid, the access permissions for the requested
* resource is computed and sent back in the servlet response.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException
* @throws java.io.IOException
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
try {
SSOTokenManager mgr = SSOTokenManager.getInstance();
SSOToken ssoToken = mgr.createSSOToken(request);
if (mgr.isValidToken(ssoToken)) {
if (ssoToken.getProperty(Constants.UNIVERSAL_IDENTIFIER) != null) {
debug.message("UNIV ID in ssoToken:" + ssoToken.getProperty(Constants.UNIVERSAL_IDENTIFIER));
} else {
debug.message("univ id is null");
if (debug.messageEnabled()) {
debug.message("principal:" + ssoToken.getPrincipal().getName());
}
}
String resource = request.getParameter("resource");
PolicyEvaluator pe = new PolicyEvaluator(WEB_AGENT_SERVICE);
Set actions = new HashSet();
actions.add("GET");
PolicyDecision pd = pe.getPolicyDecision(ssoToken, resource, actions, null);
boolean allowed = pe.isAllowed(ssoToken, resource, "GET", null);
StringBuffer message = new StringBuffer("<pre>");
message.append("isAllowed() for ").append(resource).append(" action:GET is: ");
message = message.append(allowed);
message.append(NEWLINE);
message.append(NEWLINE);
message.append("getPolicyDecision() for ").append(resource).append(" action:GET is:");
message.append(NEWLINE);
message.append(XMLUtils.escapeSpecialCharacters(pd.toXML()));
message.append("</pre>");
sendResponse(response, message.toString());
}
} catch (Exception ire) {
debug.error("processRequest::exception:", ire);
String requestUrl = request.getRequestURL().toString();
String redirectUrl = serverUrl + "?goto=" + requestUrl;
response.sendRedirect(redirectUrl);
return;
}
}
use of com.iplanet.sso.SSOTokenManager in project OpenAM by OpenRock.
the class SSOTokenAuthN method doFilter.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (!hasCookie((HttpServletRequest) request)) {
redirect((HttpServletRequest) request, (HttpServletResponse) response);
} else {
try {
SSOTokenManager mgr = SSOTokenManager.getInstance();
SSOToken token = mgr.createSSOToken((HttpServletRequest) request);
HttpServletRequestWrapperEx reqWrapper = new HttpServletRequestWrapperEx((HttpServletRequest) request);
reqWrapper.setUserPrincipal(new SSOTokenPrincipal(token));
chain.doFilter(reqWrapper, response);
} catch (SSOException e) {
redirect((HttpServletRequest) request, (HttpServletResponse) response);
}
}
}
use of com.iplanet.sso.SSOTokenManager in project OpenAM by OpenRock.
the class SSOTokenAuthZ method getAuthZSubject.
public Subject getAuthZSubject(HttpServletRequest req) throws RestException {
try {
String tokenId = req.getHeader(RestServiceManager.SUBJECT_HEADER_NAME);
if ((tokenId == null) || (tokenId.trim().length() == 0)) {
SSOTokenManager mgr = SSOTokenManager.getInstance();
SSOToken token = mgr.createSSOToken(req);
return SubjectUtils.createSubject(token);
} else {
int idx = tokenId.indexOf(':');
if (idx != -1) {
tokenId = tokenId.substring(idx + 1);
}
SSOTokenManager mgr = SSOTokenManager.getInstance();
SSOToken token = mgr.createSSOToken(tokenId);
return SubjectUtils.createSubject(token);
}
} catch (SSOException ex) {
throw new RestException(1, ex);
}
}
Aggregations