本文整理汇总了Java中org.springframework.security.core.authority.AuthorityUtils.commaSeparatedStringToAuthorityList方法的典型用法代码示例。如果您正苦于以下问题:Java AuthorityUtils.commaSeparatedStringToAuthorityList方法的具体用法?Java AuthorityUtils.commaSeparatedStringToAuthorityList怎么用?Java AuthorityUtils.commaSeparatedStringToAuthorityList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.core.authority.AuthorityUtils
的用法示例。
在下文中一共展示了AuthorityUtils.commaSeparatedStringToAuthorityList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAuthentication
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
public Authentication getAuthentication(HttpServletRequest request) {
String token = request.getHeader(HEADER_STRING);
if (token != null) {
// parse the token.
String user = getUsername(token);
String roles = getBody(token).get("roles", String.class);
List<GrantedAuthority> grantedAuths =
AuthorityUtils.commaSeparatedStringToAuthorityList(roles);
return user != null ?
new UsernamePasswordAuthenticationToken(user, null,
grantedAuths) :
null;
}
return null;
}
示例2: mapUserEntityToUserDetails
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
private UserDetails mapUserEntityToUserDetails(UserEntity userEntity) {
List<GrantedAuthority> authorities = AuthorityUtils.NO_AUTHORITIES;
if (userEntity.getRoles() != null && userEntity.getRoles().size() > 0) {
authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(
userEntity.getRoles().stream().map(r -> r.getScope().name()+":"+r.getName()).collect(Collectors.joining(","))
);
}
io.gravitee.management.idp.api.authentication.UserDetails userDetails = new io.gravitee.management.idp.api.authentication.UserDetails(
userEntity.getUsername(), userEntity.getPassword(), authorities);
userDetails.setFirstname(userEntity.getFirstname());
userDetails.setLastname(userEntity.getLastname());
userDetails.setEmail(userEntity.getEmail());
userDetails.setSource(RepositoryIdentityProvider.PROVIDER_TYPE);
userDetails.setSourceId(userEntity.getUsername());
return userDetails;
}
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:21,代码来源:RepositoryAuthenticationProvider.java
示例3: getAuthentication
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
public static Authentication getAuthentication(HttpServletRequest request) {
// 从Header中拿到token
String token = request.getHeader(HEADER_STRING);
if (token == null) {
token = getTokenFromCookis(request);
}
if (token != null && !token.isEmpty()) {
// 解析 Token
Claims claims = Jwts.parser().setSigningKey(SECRET)
.parseClaimsJws(token).getBody();
// 获取用户名
String user = claims.get("UserId").toString();
// 获取权限(角色)
List<GrantedAuthority> authorities = AuthorityUtils.commaSeparatedStringToAuthorityList((String) claims.get("authorities"));
// 返回验证令牌
return user != null ? new UsernamePasswordAuthenticationToken(user, null, authorities) : null;
}
return null;
}
示例4: getUserFromToken
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
public JWTUserDetails getUserFromToken(String token){
JWTUserDetails user;
try {
final Claims claims=getClaimsFromToken(token);
String userId = getUserIdFromToken(token);
String username=claims.getSubject();
List<GrantedAuthority> authorities =AuthorityUtils.commaSeparatedStringToAuthorityList((String) claims.get(CLAIM_KEY_AUTHORITIES));
/* boolean account_enabled = (Boolean) claims.get(CLAIM_KEY_ACCOUNT_ENABLED);
boolean account_non_locked = (Boolean) claims.get(CLAIM_KEY_ACCOUNT_NON_LOCKED);
boolean account_non_expired = (Boolean) claims.get(CLAIM_KEY_ACCOUNT_NON_EXPIRED);*/
user = new JWTUserDetails(userId, username, "password", authorities);
}catch (Exception e){
logger.error("getUserFromToken error");
user=null;
}
return user;
}
示例5: testOverrideAuthenticationManagerWithBuilderAndInjectBuilderIntoSecurityFilter
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectBuilderIntoSecurityFilter()
throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(AuthenticationManagerCustomizer.class,
WorkaroundSecurityCustomizer.class, SecurityAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
"foo", "bar",
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
assertThat(this.context.getBean(AuthenticationManager.class).authenticate(user))
.isNotNull();
}
示例6: testOverrideAuthenticationManagerWithBuilderAndInjectIntoSecurityFilter
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectIntoSecurityFilter()
throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(AuthenticationManagerCustomizer.class,
SecurityCustomizer.class, SecurityAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
"foo", "bar",
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
assertThat(this.context.getBean(AuthenticationManager.class).authenticate(user))
.isNotNull();
pingAuthenticationListener();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:SecurityAutoConfigurationTests.java
示例7: userDetailsService
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Bean
public UserDetailsService userDetailsService() {
return new UserDetailsService() {
@Override
public UserDetails loadUserByUsername(String username) {
logger.info("Got https client name of " + username);
if (username.equals("cid") || username.equals("learnsphere")) {
return new User(username, "",
AuthorityUtils
.commaSeparatedStringToAuthorityList("TRUSTED_USER_AGENT"));
} else {
return null;
}
}
};
}
示例8: authenticate
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Override
public AuthenticatedExternalWebService authenticate(String username, String password) {
ExternalWebServiceStub externalWebService = new ExternalWebServiceStub();
// Do all authentication mechanisms required by external web service protocol and validated response.
// Throw descendant of Spring AuthenticationException in case of unsucessful authentication. For example BadCredentialsException
User user = userSecurityService.getUser(username);
if(user == null || !password.equals(user.getPassword())) {
throw new BadCredentialsException("user " + username + " not found");
}
// If authentication to external service succeeded then create authenticated wrapper with proper Principal and GrantedAuthorities.
// GrantedAuthorities may come from external service authentication or be hardcoded at our layer as they are here with ROLE_DOMAIN_USER
AuthenticatedExternalWebService authenticatedExternalWebService =
new AuthenticatedExternalWebService(
YopeUser.builder().username(username).password(password).build(), null,
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_DOMAIN_USER"));
authenticatedExternalWebService.setExternalWebService(externalWebService);
return authenticatedExternalWebService;
}
示例9: create
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
public static CerberusUser create(User user) {
Collection<? extends GrantedAuthority> authorities;
try {
authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(user.getAuthorities());
} catch (Exception e) {
authorities = null;
}
return new CerberusUser(
user.getId(),
user.getUsername(),
user.getPassword(),
user.getEmail(),
user.getLastPasswordReset(),
authorities
);
}
示例10: configure
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Override
public org.springframework.security.authentication.AuthenticationProvider
configure() throws Exception {
boolean found = true;
int userIdx = 0;
while (found) {
String user = environment.getProperty("users[" + userIdx + "].user");
found = (user != null && user.isEmpty());
if (found) {
String username = environment.getProperty("users[" + userIdx + "].username");
String password = environment.getProperty("users[" + userIdx + "].password");
String roles = environment.getProperty("users[" + userIdx + "].roles");
List<GrantedAuthority> authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(roles);
userIdx++;
User newUser = new User(username, password, authorities);
LOGGER.debug("Add an in-memory user: {}", newUser);
userDetailsService.createUser(newUser);
}
}
return this;
}
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:27,代码来源:InMemoryAuthentificationProvider.java
示例11: testOverrideAuthenticationManagerWithBuilderAndInjectIntoSecurityFilter
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectIntoSecurityFilter()
throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(AuthenticationManagerCustomizer.class,
SecurityCustomizer.class, SecurityAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
"foo", "bar",
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
assertNotNull(
this.context.getBean(AuthenticationManager.class).authenticate(user));
pingAuthenticationListener();
}
示例12: testOverrideAuthenticationManagerWithBuilderAndInjectBuilderIntoSecurityFilter
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectBuilderIntoSecurityFilter()
throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(AuthenticationManagerCustomizer.class,
WorkaroundSecurityCustomizer.class, SecurityAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
"foo", "bar",
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
assertNotNull(
this.context.getBean(AuthenticationManager.class).authenticate(user));
}
示例13: userDetailsService
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Bean
UserDetailsService userDetailsService() {
return new UserDetailsService() {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
org.starfishrespect.myconsumption.server.business.entities.User account = mUserRepository.getUser(username);
if(account != null) {
List<GrantedAuthority> auth = AuthorityUtils
.commaSeparatedStringToAuthorityList("ROLE_USER");
return new User(account.getName(), account.getPassword(), auth);
} else {
throw new UsernameNotFoundException("could not find the user '"
+ username + "'");
}
}
};
}
示例14: buildUserFromItem
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
protected UserDetails buildUserFromItem(Map<String, AttributeValue> item) {
if (item == null) {
return null;
}
String username = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnUsername()));
String password = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnPassword()));
String authoritiesStr = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnAuthorities()));
List<GrantedAuthority> authorities = null;
if (StringUtils.hasText(authoritiesStr)) {
authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(authoritiesStr);
} else {
authorities = Collections.emptyList();
}
return buildUserFromItem(username, password, authorities, item);
}
示例15: authenticate
import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Override
public AuthenticatedExternalWebService authenticate(String username, String password) {
ExternalWebServiceStub externalWebService = new ExternalWebServiceStub();
// Do all authentication mechanisms required by external web service protocol and validated response.
// Throw descendant of Spring AuthenticationException in case of unsucessful authentication. For example BadCredentialsException
// ...
// ...
// If authentication to external service succeeded then create authenticated wrapper with proper Principal and GrantedAuthorities.
// GrantedAuthorities may come from external service authentication or be hardcoded at our layer as they are here with ROLE_DOMAIN_USER
AuthenticatedExternalWebService authenticatedExternalWebService = new AuthenticatedExternalWebService(new DomainUser(username), null,
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_DOMAIN_USER"));
authenticatedExternalWebService.setExternalWebService(externalWebService);
return authenticatedExternalWebService;
}
开发者ID:FutureProcessing,项目名称:spring-boot-security-example,代码行数:19,代码来源:SomeExternalServiceAuthenticator.java