当前位置: 首页>>代码示例>>Java>>正文


Java User.getAuthorities方法代码示例

本文整理汇总了Java中org.springframework.security.core.userdetails.User.getAuthorities方法的典型用法代码示例。如果您正苦于以下问题:Java User.getAuthorities方法的具体用法?Java User.getAuthorities怎么用?Java User.getAuthorities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.core.userdetails.User的用法示例。


在下文中一共展示了User.getAuthorities方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authenticate

import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    Assert.notNull(authentication, "No authentication data provided");
    String id = (String) authentication.getPrincipal();
    String key = (String) authentication.getCredentials();

    Agent agent = agentService.retrieveAgent(id);
    if (agent == null) {
        throw new UsernameNotFoundException("Agent not found: " + id);
    }
    if (!StringUtils.equals(key, agent.getKey())) {
        throw new BadCredentialsException("Authentication Failed. Agent ID or Key not valid.");
    }
    User user = new User(id, key, roles);
    return new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
}
 
开发者ID:kinota,项目名称:kinota-server,代码行数:17,代码来源:AgentAuthenticationProvider.java

示例2: createAuthentication

import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
private OAuth2Authentication createAuthentication(String username, Set<String> scopes, Set<String> roles) {
    List<GrantedAuthority> authorities = roles.stream()
        .map(SimpleGrantedAuthority::new)
        .collect(Collectors.toList());

    User principal = new User(username, "test", true, true, true, true, authorities);
    Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(),
        principal.getAuthorities());

    // Create the authorization request and OAuth2Authentication object
    OAuth2Request authRequest = new OAuth2Request(null, "testClient", null, true, scopes, null, null, null,
        null);
    return new OAuth2Authentication(authRequest, authentication);
}
 
开发者ID:xm-online,项目名称:xm-ms-balance,代码行数:15,代码来源:OAuth2TokenMockUtil.java

示例3: getOneOpsUser

import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
/**
 * Helper method to create {@link OneOpsUser} for authentication principal.
 *
 * @param principal authentication principal
 * @return oneops user.
 */
private OneOpsUser getOneOpsUser(User principal) {
    log.debug("Found user details in authentication. Creating OneOps User.");
    String userName = principal.getUsername();
    String password = principal.getPassword();

    if (password == null) {
        log.debug(userName + " credentials are already erased.");
        password = "";
    }
    return new OneOpsUser(userName, password, principal.getAuthorities(), userName, DEFAULT_DOMAIN);
}
 
开发者ID:oneops,项目名称:secrets-proxy,代码行数:18,代码来源:LoginSuccessHandler.java

示例4: authenticate

import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String rawAccessToken = (String) authentication.getCredentials();
    User user = jwtTokenUtil.parseUserFromToken(rawAccessToken);
    return new JwtAuthenticationToken(user, user.getAuthorities());
}
 
开发者ID:kinota,项目名称:kinota-server,代码行数:7,代码来源:JwtAuthenticationProvider.java


注:本文中的org.springframework.security.core.userdetails.User.getAuthorities方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。