Package com.tll.model

Examples of com.tll.model.User


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

    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
    Authority userAuth =
        dao.load(new NameKey<Authority>(Authority.class, AuthorityRoles.ROLE_USER.toString(),
            Authority.FIELDNAME_AUTHORITY));
    user.addAuthority(userAuth);

    persist(user);

    return user;
  }
View Full Code Here


    }
  }

  @Transactional(readOnly = true)
  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

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

  @Transactional
  private User getUserById(long userId) throws EntityNotFoundException {
    final User user = dao.load(User.class, Long.valueOf(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(Long userPk) throws ChangeUserCredentialsFailedException {

    try {
      // get the user
      final User user = dao.load(User.class, userPk);
      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(), User.class, user.getId());
      getDbTrans().endTrans();
      Assert.assertEquals(dbUser, user);
    }
    catch(final Throwable t) {
      Assert.fail(t.getMessage(), t);
View Full Code Here

        final PersistContext pc = (PersistContext) sc.getAttribute(PersistContext.KEY);
        if(pc == null) {
          throw new ServletException("Unable to obtain the persist context");
        }
        final IUserService userService = pc.getEntityServiceFactory().instance(IUserService.class);
        final User user = (User) userService.loadUserByUsername(appContext.getDfltUserEmail());
        log.debug("Creating mock admin context from default user email specified in config..");
        final AdminContext ac = new AdminContext();
        ac.setUser(user);
        session.setAttribute(AdminContext.KEY, ac);
        log.info("Server-side admin context created and stored in the servlet context");
View Full Code Here

        final PersistContext pc = (PersistContext) sc.getAttribute(PersistContext.KEY);
        if(pc == null) {
          throw new ServletException("Unable to obtain the persist context");
        }
        final IUserService userService = pc.getEntityServiceFactory().instance(IUserService.class);
        final User user = (User) userService.loadUserByUsername(appContext.getDfltUserEmail());
        log.debug("Creating mock admin context from default user email specified in config..");
        final AdminContext ac = new AdminContext();
        ac.setUser(user);
        session.setAttribute(AdminContext.KEY, ac);
        log.info("Server-side admin context created and stored in the servlet context");
View Full Code Here

  protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response,
      Authentication authResult) /*throws IOException*/{

    // create an AdminContext for this servlet session
    log.debug("Creating admin context from acegi security context..");
    final User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    assert user != null;
    final AdminContext ac = new AdminContext();
    ac.setUser(user);
    request.getSession(false).setAttribute(AdminContext.KEY, ac);
  }
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.