Search in sources :

Example 11 with SSOTokenManager

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;
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) PolicyException(com.sun.identity.policy.PolicyException) SSOException(com.iplanet.sso.SSOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServerEntryNotFoundException(com.iplanet.services.naming.ServerEntryNotFoundException) SMSException(com.sun.identity.sm.SMSException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AuthException(com.sun.identity.authentication.service.AuthException) SessionException(com.iplanet.dpro.session.SessionException)

Example 12 with SSOTokenManager

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;
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) Hashtable(java.util.Hashtable) SSOException(com.iplanet.sso.SSOException) SessionID(com.iplanet.dpro.session.SessionID)

Example 13 with SSOTokenManager

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;
    }
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) PolicyDecision(com.sun.identity.policy.PolicyDecision) SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) PolicyEvaluator(com.sun.identity.policy.PolicyEvaluator) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 14 with SSOTokenManager

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);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOTokenManager(com.iplanet.sso.SSOTokenManager) HttpServletRequestWrapperEx(com.sun.identity.rest.HttpServletRequestWrapperEx) SSOToken(com.iplanet.sso.SSOToken) SSOTokenPrincipal(com.sun.identity.rest.SSOTokenPrincipal) HttpServletResponse(javax.servlet.http.HttpServletResponse) SSOException(com.iplanet.sso.SSOException)

Example 15 with SSOTokenManager

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);
    }
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) RestException(com.sun.identity.rest.RestException) SSOException(com.iplanet.sso.SSOException)

Aggregations

SSOTokenManager (com.iplanet.sso.SSOTokenManager)53 SSOToken (com.iplanet.sso.SSOToken)48 SSOException (com.iplanet.sso.SSOException)39 IdRepoException (com.sun.identity.idm.IdRepoException)11 AMIdentity (com.sun.identity.idm.AMIdentity)9 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)8 IOException (java.io.IOException)7 Map (java.util.Map)6 Set (java.util.Set)6 ForbiddenException (org.forgerock.json.resource.ForbiddenException)6 SessionException (com.iplanet.dpro.session.SessionException)5 InternalSession (com.iplanet.dpro.session.service.InternalSession)5 AuthPrincipal (com.sun.identity.authentication.internal.AuthPrincipal)5 AuthException (com.sun.identity.authentication.service.AuthException)5 Iterator (java.util.Iterator)5 AuthContext (com.sun.identity.authentication.AuthContext)4 SMSException (com.sun.identity.sm.SMSException)4 Response (com.iplanet.services.comm.share.Response)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HashMap (java.util.HashMap)3