Package com.dyuproject.openid

Examples of com.dyuproject.openid.OpenIdUser


    }


    public String getClaimedId(HttpServletRequest request,
                               HttpServletResponse response) {
        OpenIdUser user =
            (OpenIdUser)request.getAttribute(OpenIdUser.ATTR_NAME);
        if (user == null) {
            return null;
        }
        return user.getClaimedId();
    }
View Full Code Here


            throw new RuntimeException(e);
        }
    }

    public String getAttribute(String key, HttpServletRequest request) {
        OpenIdUser user =
            (OpenIdUser)request.getAttribute(OpenIdUser.ATTR_NAME);
        if (user == null) {
            return null;
        }
        Map<String, String> info = (Map)user.getAttribute("info");
        if (info == null) {
            return null;
        }
        return info.get(key);
    }
View Full Code Here

    public void login(ActionFormEvent event) throws PortletException {
        ActionRequest request = event.getActionRequest();
        ActionResponse response = event.getActionResponse();

        OpenIdUser user = null;
        try {
            HttpServletRequest httpRequest = (HttpServletRequest)request;
            HttpServletResponse httpResponse = (HttpServletResponse)response;
            user = _relyingParty.discover(httpRequest);
            if (user == null) {
                log.debug("discover return null");
                response.setRenderParameter(ERROR_MESSAGE, "Error was occured.");
                setNextState(request, LOGIN_JSP);
                return ;
            }
            if (user.isAuthenticated()) {
                log.debug("user already authenticated");
                return ;
            }
            log.debug("OpenIDServer: " + user.getOpenIdServer());

            // Associate and authenticate user
            String url = buildPortalUrl(request);
            String trustRoot = url + "/";
            String realm = trustRoot;
            log.debug("trust root: " + trustRoot);
            String returnTo = url + FORWARD_URL_PATH;
            log.debug("Return To: " + returnTo);
            if (_relyingParty.associateAndAuthenticate(user, httpRequest,
                                                       httpResponse,
                                                       trustRoot, realm,
                                                       returnTo)) {
                log.debug("Successful association");
                return ;
            } else {
                log.error("Association failed");
            }
        } catch (UnknownHostException uhe) {
            response.setRenderParameter(ERROR_MESSAGE, "Unknown OpenID Provider");
            log.error(uhe.getMessage(), uhe);
        } catch (IOException e) {
            String providername = user == null ? "" : user.getOpenIdServer();
            response.setRenderParameter(ERROR_MESSAGE,
                    "Coudn't access OpenID Provider " + providername);
            log.error("IO error", e);
        } catch (DistrustedProviderException e) {
            response.setRenderParameter(ERROR_MESSAGE,
View Full Code Here

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        OpenIdUser user =
            (OpenIdUser)request.getAttribute(OpenIdUser.ATTR_NAME);
        if (user != null) {
            dispatch(request, response, "/WEB-INF/views/jsp/home.jsp");       
        } else {
            dispatch(request, response, "/WEB-INF/views/jsp/login.jsp");       
View Full Code Here

  }
 
  public boolean authenticate(Credentials credentials)
      throws RepositoryException {
    if(credentials instanceof SimpleCredentials) {
      OpenIdUser user = (OpenIdUser)((SimpleCredentials)credentials)
        .getAttribute(OpenIDAuthenticationHandler.class.getName());
      if(user != null) {
        return principal.getName().equals(
            OpenIDUserUtil.getPrincipalName(
                user.getIdentity())) &&
            user.isAuthenticated();
      }
    }
    throw new RepositoryException("Can't authenticate credentials of type: " + credentials.getClass());
  }
View Full Code Here

        if (!response.isCommitted()) {
         
          // If we're here & we have a valid authenticated user
          // probably we failed the repository login (no repo user
          // configured for the authenticated principal)
          OpenIdUser user = (OpenIdUser)request.getAttribute(OpenIDConstants.OPEN_ID_USER_ATTRIBUTE);
          if(user != null && user.isAuthenticated()) {
            request.getSession().setAttribute(
                OpenIDConstants.OPENID_FAILURE_REASON_ATTRIBUTE,
                OpenIDConstants.OpenIDFailure.REPOSITORY);
          }
View Full Code Here

    protected AuthenticationInfo extractAuthentication(
            HttpServletRequest request, HttpServletResponse response) {

     
      OpenIdUser user = null;
     
        try
        {
            user = relyingParty.discover(request);
           
            // Authentication timeout
            if(user == null && RelyingParty.isAuthResponse(request))
            {
              log.debug("OpenID authentication timeout");
                response.sendRedirect(request.getRequestURI());
                return AuthenticationInfo.DOING_AUTH;
            }
           
        if(request.getPathInfo() != null) {
          String requestPath = request.getPathInfo();
          if(requestPath != null) {
            if(OpenIDConstants.LOGOUT_REQUEST_PATH.equals(requestPath)) {
              relyingParty.invalidate(request, response);
              user = null;
              return handleLogout(request, response);
            }
            // handle (possibly)anon auth resources
            else if (loginForm.equals(requestPath) ||
                authFailUrl.equals(requestPath) ||
                logoutUrl.equals(requestPath)) {
             
              if (loginForm.equals(requestPath)) {
                // can force a login with Allow Anonymous enabled, by requesting
                // login form directly.  Checking this parameter allows us
                // to redirect user somewhere useful if login is successful
                if(request.getParameter(OpenIDConstants.REDIRECT_URL_PARAMETER) != null) {
                  request.getSession().setAttribute(OpenIDConstants.ORIGINAL_URL_ATTRIBUTE,
                      request.getParameter(OpenIDConstants.REDIRECT_URL_PARAMETER));
                }
               
                moveAttributeFromSessionToRequest(
                    OpenIDConstants.OPENID_FAILURE_REASON_ATTRIBUTE,
                    OpenIDConstants.OpenIDFailure.class,
                    request);
               
                moveAttributeFromSessionToRequest(
                    OpenIDConstants.ORIGINAL_URL_ATTRIBUTE,
                    String.class,
                    request);
               
              } else if (authFailUrl.equals(requestPath)) {
                // move the failure reason attribute from session to request
                moveAttributeFromSessionToRequest(
                    OpenIDConstants.OPENID_FAILURE_REASON_ATTRIBUTE,
                    OpenIDConstants.OpenIDFailure.class,
                    request);
               
                moveAttributeFromSessionToRequest(
                    OpenIDConstants.ORIGINAL_URL_ATTRIBUTE,
                    String.class,
                    request);
              }
             
              if(accessAuthPageAnon) {
                // Causes anonymous login
                // but does not respect SlingAuthenticator allowAnonymous
                return new AuthenticationInfo(OpenIDConstants.OPEN_ID_AUTH_TYPE, null);
              }
            }
          }
        }
         
            if(user != null) {
              if(user.isAuthenticated()) {
                  // user already authenticated
                  request.setAttribute(OpenIdUser.ATTR_NAME, user);
                  return getAuthInfoFromUser(user);
              } else if(user.isAssociated()) {
                if(RelyingParty.isAuthResponse(request)) {
                  if(relyingParty.verifyAuth(user, request, response)) {
                        // authenticated                   
                        response.sendRedirect(request.getRequestURI());
                        return AuthenticationInfo.DOING_AUTH;
View Full Code Here

    }

  public boolean canHandle(Credentials credentials) {
    if(credentials != null && credentials instanceof SimpleCredentials) {
      SimpleCredentials sc = (SimpleCredentials)credentials;
      OpenIdUser user = (OpenIdUser)sc.getAttribute(getClass().getName());
      if(user != null) {
        return user.isAssociated();
      }
    }
    return false;
  }
View Full Code Here

  }

  public Principal getPrincipal(Credentials credentials) {
    if(credentials != null && credentials instanceof SimpleCredentials) {
      SimpleCredentials sc = (SimpleCredentials)credentials;
      OpenIdUser user = (OpenIdUser)sc.getAttribute(getClass().getName());
      if(user != null) {
        return new OpenIDPrincipal(user);
      }
    }
    return null;
View Full Code Here

TOP

Related Classes of com.dyuproject.openid.OpenIdUser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.