예제 #1
0
  // @Test
  public void testUpdatePassword() throws Exception {
    IAuthorizationUserService userService =
        (IAuthorizationUserService) _context.getBean("DBAuthorizationUserService");

    // find
    try {
      AuthorizationUser au = (AuthorizationUser) userService.loadUserByUsername("camry");
    } catch (UnknownAccountException e) {
      System.out.println("donot find camry!");

      // add
      AuthorizationUser au = new AuthorizationUser();
      au.setUsername("camry");
      au.setPassword("123");
      au.setVerifyEmail("*****@*****.**");
      au.setVerifyCellPhoneNo("12345");
      userService.saveUser(au);
    }

    // update password
    userService.updatePassword("camry", "345");

    // print
    AuthorizationUser au = (AuthorizationUser) userService.loadUserByUsername("camry");
    System.out.println(au);
  }
예제 #2
0
  /** test method for loadUserByUsername. */
  @Test
  public void testLoadUserByUsername() throws Exception {
    IAuthorizationUserService userService =
        (IAuthorizationUserService) _context.getBean("DBAuthorizationUserService");
    try {
      AuthorizationUser au = (AuthorizationUser) userService.loadUserByUsername("danny");

      System.out.println("------ query user --------");
      System.out.println(au);
    } catch (UnknownAccountException e) {
      System.out.println("donot find danny!");
    }
  }
예제 #3
0
  // @Test
  public void testAddUser() throws Exception {
    IAuthorizationUserService userService =
        (IAuthorizationUserService) _context.getBean("DBAuthorizationUserService");

    // add
    AuthorizationUser au = new AuthorizationUser();
    au.setUsername("testUser");
    au.setPassword("testUser");
    au.setVerifyEmail("*****@*****.**");
    au.setVerifyCellPhoneNo("testUser-12345");
    userService.saveUser(au);

    // delete
    userService.deleteUser(au);
  }
예제 #4
0
  /**
   * Retrieves authentication data from an implementation-specific datasource (RDBMS, LDAP, etc) for
   * the given authentication token.
   *
   * @param token the authentication token containing the user's principal and credentials.
   * @return an AuthenticationInfo object containing account data resulting from the authentication
   *     ONLY if the lookup is successful (i.e. account exists and is valid, etc.)
   * @throws AuthenticationException if there is an error acquiring data or performing
   *     realm-specific authentication logic for the specified token
   */
  protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
      throws AuthenticationException {
    String username = (String) token.getPrincipal();

    AuthorizationUser user = _authorizationUserService.loadUserByUsername(username);

    if (Boolean.TRUE.equals(user.getLocked())) {
      throw new LockedAccountException(); // account locked
    }

    // call CredentialsMatcher to match password
    // if need, can do this yourself
    SimpleAuthenticationInfo info =
        new SimpleAuthenticationInfo(
            user.getUsername(),
            user.getPassword(),
            ByteSource.Util.bytes(user.getCredentialsSalt()),
            getName());

    if (_logger.isDebugEnabled()) {
      _logger.debug("call doGetAuthenticationInfo.. salt=" + user.getCredentialsSalt());
    }

    return info;
  }