本文整理匯總了Java中org.springframework.security.core.authority.AuthorityUtils.NO_AUTHORITIES屬性的典型用法代碼示例。如果您正苦於以下問題:Java AuthorityUtils.NO_AUTHORITIES屬性的具體用法?Java AuthorityUtils.NO_AUTHORITIES怎麽用?Java AuthorityUtils.NO_AUTHORITIES使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.springframework.security.core.authority.AuthorityUtils
的用法示例。
在下文中一共展示了AuthorityUtils.NO_AUTHORITIES屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mapUserEntityToUserDetails
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,代碼行數:20,代碼來源:RepositoryAuthenticationProvider.java
示例2: getOAuth2Authentication
@Override
protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {
try {
Authentication userAuth = null;
User user = extensionGrantProvider.grant(convert(tokenRequest));
if (user != null) {
userAuth = new UsernamePasswordAuthenticationToken(user, "", AuthorityUtils.NO_AUTHORITIES);
if (extensionGrant.isCreateUser()) {
Map<String, String> parameters = new LinkedHashMap<String, String>(tokenRequest.getRequestParameters());
parameters.put(RepositoryProviderUtils.SOURCE, extensionGrant.getIdentityProvider());
((AbstractAuthenticationToken) userAuth).setDetails(parameters);
eventPublisher.publishAuthenticationSuccess(userAuth);
}
}
OAuth2Request storedOAuth2Request = getRequestFactory().createOAuth2Request(client, tokenRequest);
return new OAuth2Authentication(storedOAuth2Request, userAuth);
} catch (InvalidGrantException e) {
throw new org.springframework.security.oauth2.common.exceptions.InvalidGrantException(e.getMessage(), e);
}
}
示例3: loadUserAuthorities
/**
* Creates the user authority list from the values of the {@code memberOf} attribute
* obtained from the user's Active Directory entry.
*/
@Override
protected Collection<? extends GrantedAuthority> loadUserAuthorities(
DirContextOperations userData, String username, String password) {
String[] groups = userData.getStringAttributes("memberOf");
if (groups == null) {
logger.debug("No values for 'memberOf' attribute.");
return AuthorityUtils.NO_AUTHORITIES;
}
if (logger.isDebugEnabled()) {
logger.debug("'memberOf' attribute values: " + Arrays.asList(groups));
}
ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(
groups.length);
for (String group : groups) {
authorities.add(new SimpleGrantedAuthority(new DistinguishedName(group).removeLast().getValue()));
}
return authorities;
}
示例4: createUnauthenticated
public static JwtAuthenticationToken createUnauthenticated(final String jwtToken,
final HttpServletRequest request) {
final String principal = "jwtToken-" + UUID.randomUUID();
final WebAuthenticationDetails details = new WebAuthenticationDetails(request);
return new JwtAuthenticationToken(false, principal, jwtToken, AuthorityUtils.NO_AUTHORITIES, details);
}
示例5: afterPropertiesSet
@Override
public void afterPropertiesSet() throws Exception {
for(io.gravitee.am.identityprovider.inline.model.User user : configuration.getUsers()) {
List<GrantedAuthority> authorities = AuthorityUtils.NO_AUTHORITIES; //createAuthorityList(user.getRoles());
InlineUser newUser = new InlineUser(user.getUsername(), user.getPassword(), authorities);
newUser.setFirstname(user.getFirstname());
newUser.setLastname(user.getLastname());
LOGGER.debug("Add an inline user: {}", newUser);
userDetailsService.createUser(newUser);
}
}
示例6: getAuthorities
private Collection<? extends GrantedAuthority> getAuthorities(Map<String, ?> map) {
if (!map.containsKey(AUTHORITIES)) {
return AuthorityUtils.NO_AUTHORITIES;
}
Object authorities = map.get(AUTHORITIES);
if (authorities instanceof String) {
return AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities);
}
if (authorities instanceof Collection) {
return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils
.collectionToCommaDelimitedString((Collection<?>) authorities));
}
throw new IllegalArgumentException("Authorities must be either a String or a Collection");
}
示例7: buildAutorities
private Collection<GrantedAuthority> buildAutorities(List<String> roles) {
if (roles==null || roles.isEmpty()) {
return AuthorityUtils.NO_AUTHORITIES;
} else {
Collection<GrantedAuthority> autorities = new ArrayList<>();
for (String role : user.getRoles()) {
autorities.add(new SimpleGrantedAuthority(role));
}
return autorities;
}
}
示例8: getUserInfo
/**
* Obtain current user principal
* @return BasicSecurityUser
*/
public static BasicSecurityUser getUserInfo(){
BasicSecurityUser userDetails=null;
try{
SecurityContext sc=SecurityContextHolder.getContext();
Authentication au=sc.getAuthentication();
userDetails = (BasicSecurityUser) au.getPrincipal();
}catch(NullPointerException e){
userDetails=new BasicSecurityUser("guest", "guest", true, true, true, true, AuthorityUtils.NO_AUTHORITIES, "root", "","127.0.0.1");
}
return userDetails;
}
示例9: JwtAuthenticationToken
/**
* Creates a {@link JwtAuthenticationToken} instance for an unauthenticated token.
*
* @param authenticationToken
*/
public JwtAuthenticationToken(String authenticationToken) {
super(AuthorityUtils.NO_AUTHORITIES);
this.authenticationToken = authenticationToken;
this.setAuthenticated(false);
}
示例10: mtlsSUserDetailsService
private UserDetailsService mtlsSUserDetailsService() {
return username -> new User(username, "", AuthorityUtils.NO_AUTHORITIES);
}
示例11: retrieveUser
@Override
public UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
throws AuthenticationException {
String password = (String) authentication.getCredentials();
if (!StringUtils.hasText(password)) {
logger.warn("Username {}: no password provided", username);
throw new BadCredentialsException("Please enter password");
}
UserAccount user = userService.getByUsername(username);
if (user == null) {
logger.warn("Username {} password {}: user not found", username, password);
throw new UsernameNotFoundException("Invalid Login");
}
if (!encoder.matches(password, user.getPassword())) {
logger.warn("Username {} password {}: invalid password", username, password);
throw new BadCredentialsException("Invalid Login");
}
if (!(UserAccountStatus.STATUS_APPROVED.name().equals(user.getStatus()))) {
logger.warn("Username {}: not approved", username);
throw new BadCredentialsException("User has not been approved");
}
if (!user.getEnabled()) {
logger.warn("Username {}: disabled", username);
throw new BadCredentialsException("User disabled");
}
final List<GrantedAuthority> auths;
if (!user.getRoles().isEmpty()) {
auths = AuthorityUtils.commaSeparatedStringToAuthorityList(user.getRolesCSV());
} else {
auths = AuthorityUtils.NO_AUTHORITIES;
}
return new User(username, password, user.getEnabled(), // enabled
true, // account not expired
true, // credentials not expired
true, // account not locked
auths);
}
示例12: retrieveUser
@Override public UserDetails retrieveUser(final String name, final UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
this.logger.info("MongoDBAuthenticationProvider.retrieveUser");
boolean valid = true;
// Make sure an actual password was entered
final String password = (String)authentication.getCredentials();
if (!StringUtils.hasText(password)) {
this.logger.warn("Username {}: no password provided", name);
valid = false;
}
// Look for user and check their account is activated
final Account account = this.accountService.getByName(name);
if (account == null) {
this.logger.warn("Username {}: user not found", name);
valid = false;
} else {
if (!AccountStatus.STATUS_APPROVED.name().equals(account.getStatus())) {
this.logger.warn("Username {}: not approved", name);
valid = false;
}
// Check password
final String hashedPassword = BCrypt.hashpw(password, account.getSalt());
if (!hashedPassword.equals(account.getHashedPass())) {
this.logger.warn("Username {}: bad password entered", name);
valid = false;
}
}
if (!valid) {
final Locale locale = LocaleContextHolder.getLocale();
final String message = this.messageSource.getMessage("exception.wrongAccountNameAndPass", null, locale);
final MessageBox messageBox = new MessageBox("wrongAccountNameAndPass", message, new ArrayList<String>());
final List<MessageBox> errorMessages = new ArrayList<MessageBox>();
errorMessages.add(messageBox);
final LoginException loginException = new LoginException(errorMessages, name);
throw new BadCredentialsException("Invalid Username/Password", loginException);
}
// Create Springframework-typed User instance
final List<String> roles = account.getRoles();
final List<GrantedAuthority> auths = !roles.isEmpty() ? AuthorityUtils.commaSeparatedStringToAuthorityList(account.getRolesCSV()) : AuthorityUtils.NO_AUTHORITIES;
// enabled, account not expired, credentials not expired, account not locked
return new User(name, password, true, true, true, true, auths);
}