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


Java AuthorityUtils.NO_AUTHORITIES属性代码示例

本文整理汇总了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);
    }
}
 
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:21,代码来源:CustomTokenGranter.java

示例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;
}
 
开发者ID:gustajz,项目名称:parking-api,代码行数:28,代码来源:ActiveDirectoryAliasLdapAuthenticationProvider.java

示例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);
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:7,代码来源:JwtAuthenticationToken.java

示例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);
    }
}
 
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:12,代码来源:InlineAuthenticationProvider.java

示例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");
}
 
开发者ID:OpenLMIS,项目名称:openlmis-stockmanagement,代码行数:14,代码来源:CustomUserAuthenticationConverter.java

示例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;
	}
}
 
开发者ID:lucamartellucci,项目名称:bookshop-api,代码行数:11,代码来源:SimpleUserDetails.java

示例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;
	
}
 
开发者ID:rockagen,项目名称:gnext,代码行数:17,代码来源:SS3Tools.java

示例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);
}
 
开发者ID:cassiomolin,项目名称:jersey-jwt-springsecurity,代码行数:10,代码来源:JwtAuthenticationToken.java

示例10: mtlsSUserDetailsService

private UserDetailsService mtlsSUserDetailsService() {
  return username -> new User(username, "", AuthorityUtils.NO_AUTHORITIES);
}
 
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:3,代码来源:AuthWithoutOAuthConfiguration.java

示例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);
}
 
开发者ID:NguyenAnhDuc,项目名称:AIML,代码行数:42,代码来源:LocalAuthenticationProvider.java

示例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);
}
 
开发者ID:llop,项目名称:porra-joc-eda,代码行数:42,代码来源:MongoDBAuthenticationProvider.java


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