本文整理匯總了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