Ejemplo n.º 1
0
 /** 认证回调函数,登录时调用. */
 @Override
 protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
     throws AuthenticationException {
   UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
   User user = accountService.findUserByLoginName(token.getUsername());
   if (user != null) {
     byte[] salt = Encodes.decodeHex(user.getSalt());
     return new SimpleAuthenticationInfo(
         new ShiroUser(user.getId(), user.getLoginName(), user.getName()),
         user.getPassword(),
         ByteSource.Util.bytes(salt),
         getName());
   } else {
     return null;
   }
 }
Ejemplo n.º 2
0
 @Test
 public void hexEncode() {
   String input = "haha,i am a very long message";
   String result = Encodes.encodeHex(input.getBytes());
   assertEquals(input, new String(Encodes.decodeHex(result)));
 }