Package com.github.zhangkaitao.shiro.chapter13.service

Examples of com.github.zhangkaitao.shiro.chapter13.service.UserService


    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

        String username = (String)token.getPrincipal();

        User user = userService.findByUsername(username);

        if(user == null) {
            throw new UnknownAccountException();//没找到帐号
        }

        if(Boolean.TRUE.equals(user.getLocked())) {
            throw new LockedAccountException(); //帐号锁定
        }

        //交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配,如果觉得人家的不好可以自定义实现
        SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
                user.getUsername(), //用户名
                user.getPassword(), //密码
                ByteSource.Util.bytes(user.getCredentialsSalt()),//salt=username+salt
                getName()  //realm name
        );
        return authenticationInfo;
    }
View Full Code Here


     * 修改密码
     * @param userId
     * @param newPassword
     */
    public void changePassword(Long userId, String newPassword) {
        User user =userDao.findOne(userId);
        user.setPassword(newPassword);
        passwordHelper.encryptPassword(user);
        userDao.updateUser(user);
    }
View Full Code Here

*/
public class UserTests extends ForgeAPITestBase {

  @Test
  public void testListUsers() throws IOException {
    UserService service = getTestUserForge().createUserService();
    List<User> Users = service.list(null);
    assertNotNull("Null User list", Users);
    assertFalse("Empty User list", Users.isEmpty());
  }
View Full Code Here

    assertFalse("Empty User list", Users.isEmpty());
  }

  @Test
  public void testListUsersSorted() throws IOException {
    UserService service = getTestUserForge().createUserService();
    ListPreferences listPrefs = new ListPreferences();
    listPrefs.setLimit(4);
    listPrefs.setOffset(1);
    listPrefs.setSortBy("username");
    listPrefs.setSortOrder("descending");
    List<User> Users = service.list(listPrefs);
    assertNotNull("Null User list", Users);
    assertFalse("Empty User list", Users.isEmpty());
  }
View Full Code Here

    assertFalse("Empty User list", Users.isEmpty());
  }

  @Test
  public void testUserDetail() throws IOException {
    UserService service = getTestUserForge().createUserService();
    User user = service.get(TEST_USER);
    assertNotNull("Null user", user);
  }
View Full Code Here

TOP

Related Classes of com.github.zhangkaitao.shiro.chapter13.service.UserService

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.