Package com.erudika.para.core

Examples of com.erudika.para.core.User


  @Override
  public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    final String requestURI = request.getRequestURI();
    Authentication userAuth = null;
    User user = null;

    if (requestURI.endsWith(OPENID_ACTION)) {
      Authentication oidAuth = super.attemptAuthentication(request, response);

      if (oidAuth == null) {
        // hang on... redirecting to openid provider
        return null;
      } else {
        //success!
        user = (User) oidAuth.getPrincipal();
        userAuth = new UserAuthentication(user);
      }
    }

    if (userAuth == null || user == null || user.getIdentifier() == null) {
      throw new BadCredentialsException("Bad credentials.");
    } else if (!user.isEnabled()) {
      throw new LockedException("Account is locked.");
//    } else {
//      SecurityUtils.setAuthCookie(user, request, response);
    }
    return userAuth;
View Full Code Here


   * Loads a user from the data store.
   * @param ident the user identifier
   * @return a user object or null if user is not found
   */
  public UserDetails loadUserByUsername(String ident) {
    User user = new User();
    user.setIdentifier(ident);
    user = loadUser(user);

    if (user == null) {
      throw new UsernameNotFoundException(ident);
    }
View Full Code Here

  public UserDetails loadUserDetails(OpenIDAuthenticationToken token) {
    if (token == null) {
      return null;
    }

    User user = new User();
    user.setIdentifier(token.getIdentityUrl());
    user = loadUser(user);

    if (user == null) {
      // create new OpenID user
      String email = "email@domain.com";
      String firstName = null, lastName = null, fullName = null;
      List<OpenIDAttribute> attributes = token.getAttributes();

      for (OpenIDAttribute attribute : attributes) {
        if (attribute.getName().equals("email")) {
          email = attribute.getValues().get(0);
        }
        if (attribute.getName().equals("firstname")) {
          firstName = attribute.getValues().get(0);
        }
        if (attribute.getName().equals("lastname")) {
          lastName = attribute.getValues().get(0);
        }
        if (attribute.getName().equals("fullname")) {
          fullName = attribute.getValues().get(0);
        }
      }

      if (fullName == null) {
        if (firstName == null) {
          firstName = "No";
        }
        if (lastName == null) {
          lastName = "Name";
        }
        fullName = firstName.concat(" ").concat(lastName);
      }

      user = new User();
      user.setEmail(email);
      user.setName(fullName);
      user.setPassword(new UUID().toString());
      user.setIdentifier(token.getIdentityUrl());
      String id = user.create();
      if (id == null) {
        throw new BadCredentialsException("Authentication failed: cannot create new user.");
      }
    }
View Full Code Here

  /**
   * Extracts a User object from the security context
   * @return an authenticated user or null if a user is not authenticated
   */
  public static User getAuthenticatedUser() {
    User u = null;
    if (SecurityContextHolder.getContext().getAuthentication() != null) {
      Authentication auth = SecurityContextHolder.getContext().getAuthentication();
      if (auth.isAuthenticated() && auth.getPrincipal() instanceof User) {
        u = (User) auth.getPrincipal();
      }
View Full Code Here

  @Override
  public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    String requestURI = request.getRequestURI();
    Authentication userAuth = null;
    User user = new User();

    if (requestURI.endsWith(PASSWORD_ACTION)) {
      user.setIdentifier(request.getParameter(EMAIL));
      user.setPassword(request.getParameter(PASSWORD));

      if (User.passwordMatches(user) && StringUtils.contains(user.getIdentifier(), "@")) {
        //success!
        user = User.readUserForIdentifier(user);
        userAuth = new UserAuthentication(user);
      }
    }

    if (userAuth == null || user == null || user.getIdentifier() == null) {
      throw new BadCredentialsException("Bad credentials.");
    } else if (!user.isEnabled()) {
      throw new LockedException("Account is locked.");
//    } else {
//      SecurityUtils.setAuthCookie(user, request, response);
    }
    return userAuth;
View Full Code Here

  @Override
  public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    String requestURI = request.getRequestURI();
    Authentication userAuth = null;
    User user = new User();

    if (requestURI.endsWith(FACEBOOK_ACTION)) {
      //Facebook Connect Authentication
      String fbSig = request.getParameter("fbsig");
      String fbEmail = request.getParameter("fbemail");
      String fbName = request.getParameter("fbname");
      String fbID = verifiedFacebookID(fbSig);

      if (fbID != null) {
        //success!
        user.setIdentifier(Config.FB_PREFIX.concat(fbID));
        user = User.readUserForIdentifier(user);
        if (user == null) {
          //user is new
          user = new User();
          user.setEmail(StringUtils.isBlank(fbEmail) ? "email@domain.com" : fbEmail);
          user.setName(StringUtils.isBlank(fbName) ? "No Name" : fbName);
          user.setPassword(new UUID().toString());
          user.setIdentifier(Config.FB_PREFIX.concat(fbID));
          String id = user.create();
          if (id == null) {
            throw new AuthenticationServiceException("Authentication failed: cannot create new user.");
          }
        }
        userAuth = new UserAuthentication(user);
      }
    }

    if (userAuth == null || user == null || user.getIdentifier() == null) {
      throw new BadCredentialsException("Bad credentials.");
    } else if (!user.isEnabled()) {
      throw new LockedException("Account is locked.");
//    } else {
//      SecurityUtils.setAuthCookie(user, request, response);
    }
    return userAuth;
View Full Code Here

TOP

Related Classes of com.erudika.para.core.User

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.