Package com.tll.model

Examples of com.tll.model.User


  }

  @Transactional
  public User create(Account account, String emailAddress, String password) throws ValidationException,
  EntityExistsException {
    final User user = entityAssembler.assembleEntity(User.class, new EntityCache(account), true);

    String encPassword = null;
    try {
      encPassword = encodePassword(password, emailAddress);
    }
    catch(final IllegalArgumentException iae) {
      throw new ValidationException("Invalid password");
    }

    user.setEmailAddress(emailAddress);
    user.setPassword(encPassword);

    // set default expiry date to 1 day from now
    final Calendar clndr = Calendar.getInstance();
    clndr.add(Calendar.DAY_OF_MONTH, 1);
    final Date expires = clndr.getTime();
    user.setExpires(expires);

    // set the user as un-locked by default
    user.setLocked(false);

    // set the role as user by default
    user.addAuthority(dao.load(new NameKey<Authority>(Authority.class, AuthorityRoles.ROLE_USER.toString(),
        Authority.FIELDNAME_AUTHORITY)));

    persist(user);

    return user;
View Full Code Here


      throw new UsernameNotFoundException("Username '" + username + "' not found");
    }
  }

  private User findByEmail(String emailAddress) throws EntityNotFoundException {
    User user;
    try {
      final Criteria<User> criteria = new Criteria<User>(User.class);
      criteria.getPrimaryGroup().addCriterion("emailAddress", emailAddress, true);
      user = dao.findEntity(criteria);
    }
    catch(final InvalidCriteriaException e) {
      throw new IllegalArgumentException("Unexpected invalid criteria exception occurred");
    }
    if(user == null) {
      throw new EntityNotFoundException("User with username: " + emailAddress + " was not found.");
    }
    final Account ua = user.getAccount();
    user.setAccount(ua);
    return user;
  }
View Full Code Here

    super.purge(user);
    updateSecurityContextIfNecessary(user.getUsername(), null, null, true);
  }

  private User getUserById(String userId) throws EntityNotFoundException {
    final User user = dao.load(new PrimaryKey<User>(User.class, userId));
    if(user == null) throw new EntityNotFoundException("User of id '" + userId + "' not found");
    return user;
  }
View Full Code Here

    try {
      // get the user
      final Criteria<User> criteria = new Criteria<User>(User.class);
      criteria.getPrimaryGroup().addCriterion("emailAddress", username, true);
      final User user = dao.findEntity(criteria);

      // encode the new password
      final String encNewPassword = encodePassword(newRawPassword, newUsername);

      // set the credentials
      setCredentials(user.getId(), newUsername, encNewPassword);

      updateSecurityContextIfNecessary(user.getUsername(), newUsername, newRawPassword, false);
    }
    catch(final InvalidCriteriaException e) {
      throw new IllegalArgumentException(
          "Unable to chnage user credentials due to an unexpected invalid criteria exception: "
          + e.getMessage(), e);
View Full Code Here

    ChangeUserCredentialsFailedException.class, RuntimeException.class })
    public String resetPassword(String userId) throws ChangeUserCredentialsFailedException {

    try {
      // get the user
      final User user = dao.load(new PrimaryKey<User>(User.class, userId));
      final String username = user.getUsername();

      // encode the new password
      final String random = RandomStringUtils.randomAlphanumeric(8);
      final String encNewPassword = encodePassword(random, username);
View Full Code Here

    final Authentication authentication = securityContext.getAuthentication();
    if(authentication == null) return;

    final Object principal = authentication.getPrincipal();
    if(principal instanceof User == false) return;
    final User user = (User) authentication.getPrincipal();

    if(user.getUsername().equals(originalUsername)) {
      if(userCache != null) {
        userCache.removeUserFromCache(originalUsername);
      }
      if(justRemove) {
        SecurityContextHolder.clearContext();
View Full Code Here

      // stub the authorities
      stubAuthorities();

      // the service test (should be transactional)
      final IUserService userService = getEntityServiceFactory().instance(IUserService.class);
      final User user = userService.create(account, "name@domain.com", "password");
      Assert.assertNotNull(user);

      getDbTrans().startTrans();
      final User dbUser = AbstractDbAwareTest.getEntityFromDb(getDao(), new PrimaryKey<User>(user));
      getDbTrans().endTrans();
      Assert.assertEquals(dbUser, user);
    }
    catch(final Throwable t) {
      Assert.fail(t.getMessage(), t);
View Full Code Here

TOP

Related Classes of com.tll.model.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.