Package com.example.helloworld.core

Examples of com.example.helloworld.core.User


public class ExampleAuthenticator implements Authenticator<BasicCredentials, User> {
    @Override
    public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException {
        if ("secret".equals(credentials.getPassword())) {
            return Optional.of(new User(credentials.getUsername()));
        }
        return Optional.absent();
    }
View Full Code Here


      return Response
          .status(Status.NOT_FOUND)
          .entity(new ErrorMessage(AuthResource.NOT_FOUND_MSG)).build();
    }
   
    User userToUpdate = foundUser.get();
    userToUpdate.setDisplayName(user.getDisplayName());
    userToUpdate.setEmail(user.getEmail());
    dao.save(userToUpdate);

    return Response.ok().build();
  }
View Full Code Here

  @POST
  @Path("signup")
  @UnitOfWork
  public Response signup(@Valid User user, @Context HttpServletRequest request) throws JOSEException {
    user.setPassword(PasswordService.hashPassword(user.getPassword()));
    User savedUser = dao.save(user);
    Token token = AuthUtils.createToken(request.getRemoteHost(), savedUser.getId());
    return Response.status(Status.CREATED).entity(token).build();
  }
View Full Code Here

    if (!foundUser.isPresent()) {
      return Response.status(Status.NOT_FOUND).entity(new ErrorMessage(NOT_FOUND_MSG))
          .build();
    }

    User userToUnlink = foundUser.get();

    // check that the user is not trying to unlink the only sign-in method
    if (userToUnlink.getSignInMethodCount() == 1) {
      return Response.status(Status.BAD_REQUEST)
          .entity(new ErrorMessage(String.format(UNLINK_ERROR_MSG, provider))).build();
    }

    try {
      userToUnlink.setProviderId(Provider.valueOf(provider.toUpperCase()), null);
    } catch (IllegalArgumentException e) {
      return Response.status(Status.BAD_REQUEST).build();
    }

    dao.save(userToUnlink);
View Full Code Here

  private Response processUser(HttpServletRequest request, Provider provider, String id,
      String displayName) throws JOSEException, ParseException {
    Optional<User> user = dao.findByProvider(provider, id);

    // Step 3a. If user is already signed in then link accounts.
    User userToSave;
    String authHeader = request.getHeader(AuthUtils.AUTH_HEADER_KEY);
    if (StringUtils.isNotBlank(authHeader)) {
      if (user.isPresent()) {
        return Response
            .status(Status.CONFLICT)
            .entity(new ErrorMessage(String.format(CONFLICT_MSG, provider.capitalize())))
            .build();
      }

      String subject = AuthUtils.getSubject(authHeader);
      Optional<User> foundUser = dao.findById(Long.parseLong(subject));
      if (!foundUser.isPresent()) {
        return Response.status(Status.NOT_FOUND).entity(new ErrorMessage(NOT_FOUND_MSG))
            .build();
      }

      userToSave = foundUser.get();
      userToSave.setProviderId(provider, id);
      if (userToSave.getDisplayName() == null) {
        userToSave.setDisplayName(displayName);
      }
      userToSave = dao.save(userToSave);
    } else {
      // Step 3b. Create a new user account or return an existing one.
      if (user.isPresent()) {
        userToSave = user.get();
      } else {
        userToSave = new User();
        userToSave.setProviderId(provider, id);
        userToSave.setDisplayName(displayName);
        userToSave = dao.save(userToSave);
      }
    }

    Token token = AuthUtils.createToken(request.getRemoteHost(), userToSave.getId());
    return Response.ok().entity(token).build();
  }
View Full Code Here

    public Optional<User> findById(Long id) {
        return Optional.fromNullable(get(id));
    }
   
    public Optional<User> findByEmail(String email) {
      User foundUser = (User) namedQuery("User.findByEmail")
        .setParameter("email", email)
        .uniqueResult();
      return Optional.fromNullable(foundUser);
    }
View Full Code Here

        .uniqueResult();
      return Optional.fromNullable(foundUser);
    }
   
    public Optional<User> findByProvider(Provider provider, String providerId) {
      User foundUser = (User) namedQuery(String.format("User.findBy%s", provider.capitalize()))
                  .setParameter(provider.getName(), providerId)
                  .uniqueResult();
      return Optional.fromNullable(foundUser);
    }
View Full Code Here

TOP

Related Classes of com.example.helloworld.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.