本文整理汇总了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());
}
示例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);
}
示例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);
}
示例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());
}