Search in sources :

Example 1 with Users

use of io.github.tesla.authz.domain.Users in project tesla by linking12.

the class TeslaUserRealm method doGetAuthenticationInfo.

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    String username = upToken.getUsername();
    if (username == null) {
        throw new AccountException("Null usernames are not allowed by this realm.");
    }
    Users user = userDao.findByUserNamed(username);
    Long userId = user.userId();
    String password = user.password();
    int status = user.status();
    if (password == null) {
        throw new UnknownAccountException("No account found for " + username);
    }
    if (!password.equals(new String((char[]) token.getCredentials()))) {
        throw new IncorrectCredentialsException("Password is not right for " + username);
    }
    if (status == 0) {
        throw new LockedAccountException("account is locked for user " + username);
    }
    SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(userId, password.toCharArray(), username);
    info.setCredentialsSalt(ByteSource.Util.bytes(username));
    return info;
}
Also used : IncorrectCredentialsException(org.apache.shiro.authc.IncorrectCredentialsException) AccountException(org.apache.shiro.authc.AccountException) LockedAccountException(org.apache.shiro.authc.LockedAccountException) UnknownAccountException(org.apache.shiro.authc.UnknownAccountException) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) UnknownAccountException(org.apache.shiro.authc.UnknownAccountException) Users(io.github.tesla.authz.domain.Users) LockedAccountException(org.apache.shiro.authc.LockedAccountException) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 2 with Users

use of io.github.tesla.authz.domain.Users in project tesla by linking12.

the class AuthzUserDao method findByUserNamed.

public Users findByUserNamed(String userName) {
    String sql = "select u.user_id,u.username,u.password,u.status from sys_user u where u.username = ?";
    final List<Users> list = this.jdbcTemplate.query(sql, usersRowMapper, userName);
    Users user = list.isEmpty() ? null : list.get(0);
    if (user != null) {
        List<String> roles = this.findRoleByUserId(user.userId());
        user.roles(roles);
    }
    return user;
}
Also used : Users(io.github.tesla.authz.domain.Users)

Example 3 with Users

use of io.github.tesla.authz.domain.Users in project tesla by linking12.

the class AuthzUserDao method findByUserId.

public Users findByUserId(Long userId) {
    String sql = "select u.user_id,u.username,u.password from sys_user u where u.user_id = ?";
    final List<Users> list = this.jdbcTemplate.query(sql, usersRowMapper, userId);
    Users user = list.isEmpty() ? null : list.get(0);
    if (user != null) {
        List<String> roles = this.findRoleByUserId(user.userId());
        user.roles(roles);
    }
    return user;
}
Also used : Users(io.github.tesla.authz.domain.Users)

Aggregations

Users (io.github.tesla.authz.domain.Users)3 AccountException (org.apache.shiro.authc.AccountException)1 IncorrectCredentialsException (org.apache.shiro.authc.IncorrectCredentialsException)1 LockedAccountException (org.apache.shiro.authc.LockedAccountException)1 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)1 UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1