Search in sources :

Example 1 with Authority

use of com.varsql.core.auth.Authority in project varsql by varsqlinfo.

the class SecurityUtil method loginRole.

public static String loginRole(Authentication auth) {
    if (auth == null)
        return null;
    if (auth instanceof AnonymousAuthenticationToken) {
        return User.ANONYMOUS_USERNAME;
    }
    User user = (User) auth.getPrincipal();
    java.util.Iterator<? extends GrantedAuthority> iter = user.getAuthorities().iterator();
    while (iter.hasNext()) {
        return ((Authority) iter.next()).getName();
    }
    return "";
}
Also used : User(com.varsql.core.auth.User) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Authority(com.varsql.core.auth.Authority) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken)

Example 2 with Authority

use of com.varsql.core.auth.Authority in project varsql by varsqlinfo.

the class AuthDAO method loadUserByUsername.

public User loadUserByUsername(String username, String password, boolean remembermeFlag) {
    try {
        UserEntity userModel = userRepository.findByUid(username);
        if (userModel == null) {
            return null;
        // throw new UsernameNotFoundException("Wrong username or password ");
        }
        if (remembermeFlag == false) {
            if (!passwordEncoder.matches(password, userModel.getUpw())) {
                return null;
            // throw new UsernameNotFoundException("Wrong username or password ");
            }
        }
        User user = new User();
        user.setLoginRememberMe(remembermeFlag);
        user.setViewid(userModel.getViewid());
        user.setUsername(userModel.getUid());
        user.setPassword("");
        user.setFullname(userModel.getUname());
        if (userModel.isBlockYn()) {
            // 차단된 사용자 체크.
            user.setBlockYn(true);
            return user;
        }
        user.setUserLocale(LocaleConstants.parseLocaleString(userModel.getLang()));
        user.setOrgNm(userModel.getOrgNm());
        user.setDeptNm(userModel.getDeptNm());
        user.setEmail(userModel.getUemail());
        user.setAcceptYn(userModel.isAcceptYn());
        String userRole = userModel.getUserRole();
        List<Authority> roles = new ArrayList<Authority>();
        Authority r = new Authority();
        AuthorityType authType = AuthorityType.valueOf(userRole);
        r = new Authority();
        r.setName(userRole);
        r.setPriority(authType.getPriority());
        roles.add(r);
        user.setTopAuthority(authType);
        user.setAuthorities(roles);
        return user;
    } catch (Exception e) {
        logger.error(this.getClass().getName(), e);
        throw new UsernameNotFoundException(new StringBuilder().append("Wrong username or password :").append(username).append(" ").append(e.getMessage()).toString());
    }
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) AuthorityType(com.varsql.core.auth.AuthorityType) User(com.varsql.core.auth.User) Authority(com.varsql.core.auth.Authority) ArrayList(java.util.ArrayList) UserEntity(com.varsql.web.model.entity.user.UserEntity) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) VarsqlAppException(com.varsql.web.exception.VarsqlAppException) SQLException(java.sql.SQLException)

Aggregations

Authority (com.varsql.core.auth.Authority)2 User (com.varsql.core.auth.User)2 AuthorityType (com.varsql.core.auth.AuthorityType)1 VarsqlAppException (com.varsql.web.exception.VarsqlAppException)1 UserEntity (com.varsql.web.model.entity.user.UserEntity)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1