in a certain method, you want to obtain custom Realm information through getPrincipal (), but all the field information of the obtained entity is null
configuration without cache processing, nor does it implement SessionDao
login code. If you get the information after login, it will return
normally.public Result login(String username, String password) {
if (StringUtils.isBlank(username) || StringUtils.isBlank(password))
throw new GlobalException(CodeMsg.BIND_ERROR.fillArgs(""));
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
Subject subject = SecurityUtils.getSubject();
try {
subject.login(token);
return DefaultResult.success();
} catch (AuthenticationException e) {
return DefaultResult.error(CodeMsg.USER_ERROR.fillArgs(""), e.getMessage());
}
}
Login authentication code
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) authenticationToken;
String username = usernamePasswordToken.getUsername();
UserEntity userEntity = userService.getUserByLoginName(username);
if (userEntity == null || userEntity.getDelFlag().equals(UserConstant.DEL_NOT_EXIST))
throw new GlobalException(CodeMsg.USER_ERROR.fillArgs(""));
if (userEntity.getStatus().equals(UserConstant.STATUS_DISABLE))
throw new GlobalException(CodeMsg.USER_ERROR.fillArgs(""));
String dbPassword = userEntity.getPassword();
String salt = userEntity.getSalt();
String inputPassword = new String(usernamePasswordToken.getPassword());
//TODO inputPasswordsalt
String password = inputPassword;
if (!dbPassword.equals(password))
throw new GlobalException(CodeMsg.USER_ERROR.fillArgs(""));
return new SimpleAuthenticationInfo(userEntity, dbPassword, getName());
}