LdapAuthenticationProvider.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:graviteeio-access-management 作者:
@Override
public User loadUserByUsername(String username) {
    try {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        DirContextOperations authenticate;
        try {
            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

            // find user
            authenticate = userSearch.searchForUser(username);

            // fetch user groups
            try {
                List<String> groups = authoritiesPopulator
                        .getGrantedAuthorities(authenticate, authenticate.getNameInNamespace()).stream()
                        .map(a -> a.getAuthority())
                        .collect(Collectors.toList());
                authenticate.setAttributeValue(MEMBEROF_ATTRIBUTE, groups);
            } catch (Exception e) {
                LOGGER.warn("No group found for user {}", authenticate.getNameInNamespace(), e);
            }
        } finally {
            Thread.currentThread().setContextClassLoader(classLoader);
        }

        return createUser(authenticate);
    } catch (UsernameNotFoundException notFound) {
        throw notFound;
    } catch (NamingException ldapAccessFailure) {
        throw new InternalAuthenticationServiceException(
                ldapAccessFailure.getMessage(), ldapAccessFailure);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号