當前位置: 首頁>>代碼示例>>Java>>正文


Java AuthorityUtils.commaSeparatedStringToAuthorityList方法代碼示例

本文整理匯總了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;
}
 
開發者ID:Clcanny,項目名稱:MicroServiceDemo,代碼行數:18,代碼來源:JwtTokenUtil.java

示例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;
    }
 
開發者ID:hzwy23,項目名稱:hauth-java,代碼行數:25,代碼來源:JwtService.java

示例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;
}
 
開發者ID:BENULL,項目名稱:LushX,代碼行數:19,代碼來源:JWTUtils.java

示例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();
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:17,代碼來源:SecurityAutoConfigurationTests.java

示例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;
	        }
	    }
	};
}
 
開發者ID:DiscourseDB,項目名稱:discoursedb-core,代碼行數:17,代碼來源:SecurityConfig.java

示例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;
}
 
開發者ID:yopeio,項目名稱:payment-api,代碼行數:24,代碼來源:UserServiceAuthenticator.java

示例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
  );
}
 
開發者ID:brahalla,項目名稱:Cerberus,代碼行數:17,代碼來源:CerberusUserFactory.java

示例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();
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:18,代碼來源:SecurityAutoConfigurationTests.java

示例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));
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:17,代碼來源:SecurityAutoConfigurationTests.java

示例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 + "'");
            }
        }

    };
}
 
開發者ID:S23Y,項目名稱:myconsumption-server,代碼行數:21,代碼來源:AuthConfig.java

示例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);
}
 
開發者ID:Vivastream,項目名稱:spring-security-oauth2-dynamodb,代碼行數:18,代碼來源:DynamoDBUserDetailsManager.java

示例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


注:本文中的org.springframework.security.core.authority.AuthorityUtils.commaSeparatedStringToAuthorityList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。