當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。