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


Java OAuth2Authentication.getAuthorities方法代碼示例

本文整理匯總了Java中org.springframework.security.oauth2.provider.OAuth2Authentication.getAuthorities方法的典型用法代碼示例。如果您正苦於以下問題:Java OAuth2Authentication.getAuthorities方法的具體用法?Java OAuth2Authentication.getAuthorities怎麽用?Java OAuth2Authentication.getAuthorities使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.security.oauth2.provider.OAuth2Authentication的用法示例。


在下文中一共展示了OAuth2Authentication.getAuthorities方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hasValidRole

import org.springframework.security.oauth2.provider.OAuth2Authentication; //導入方法依賴的package包/類
public static boolean hasValidRole(Principal principal, String company, String user) {
	OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) principal;
	
	LOGGER.info("Super role is {}", SUPERADMIN);
	
	if (company != null) {
		LOGGER.info("Required company role is {}", String.format(COMPANYADMIN, company.toUpperCase()));
	}
	
	if (user != null) {
		LOGGER.info("Required user role is {}", String.format(USER, user.toUpperCase()));
	}
	
	for(GrantedAuthority ga : oAuth2Authentication.getAuthorities()) {
		LOGGER.info("Checking {}", ga.getAuthority());
		
		if (ga.getAuthority().equalsIgnoreCase(SUPERADMIN)) {
			return true;
		} else if (company != null && ga.getAuthority().equalsIgnoreCase(String.format(COMPANYADMIN, company.toUpperCase()))) {
			return true;
		} else if (user != null && ga.getAuthority().equalsIgnoreCase(String.format(USER, user.toUpperCase()))) {
			return true;
		}
	}
	throw new ResourceUnauthorizedException();
}
 
開發者ID:cypherkey,項目名稱:multi-tenant-rest-api,代碼行數:27,代碼來源:RoleChecker.java

示例2: enhance

import org.springframework.security.oauth2.provider.OAuth2Authentication; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
    final Map<String, Object> additionalInfo = new HashMap<>();
    Collection<GrantedAuthority> authorities = authentication.getAuthorities();
    Object[] ga = authorities.toArray();
    SimpleGrantedAuthority sga = (SimpleGrantedAuthority) ga[0];
    String role = sga.getAuthority();
    additionalInfo.put("role", role);
    ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
    return accessToken;
}
 
開發者ID:PacktPublishing,項目名稱:Building-Web-Apps-with-Spring-5-and-Angular,代碼行數:12,代碼來源:CustomTokenEnhancer.java

示例3: foo

import org.springframework.security.oauth2.provider.OAuth2Authentication; //導入方法依賴的package包/類
@RequestMapping(value="/foo", method=RequestMethod.GET, produces=MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> foo(Principal principal) {
	StringBuilder sb = new StringBuilder();
	OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) principal;
	sb.append("Name=");
	sb.append(oAuth2Authentication.getName());
	sb.append("\r\n");
	sb.append("Authorities:");
	for(GrantedAuthority ga : oAuth2Authentication.getAuthorities()) {
		sb.append(ga.getAuthority());
		sb.append("\r\n");
	}
	return new ResponseEntity<String>(sb.toString(), HttpStatus.OK);
}
 
開發者ID:cypherkey,項目名稱:multi-tenant-rest-api,代碼行數:15,代碼來源:ResourcesController.java

示例4: getAuthorities

import org.springframework.security.oauth2.provider.OAuth2Authentication; //導入方法依賴的package包/類
public Set<String> getAuthorities() {
	OAuth2Authentication oauth = oauth2Authentication();
	if (oauth == null) {
		return new HashSet<String>();
	}

	Collection<GrantedAuthority> authorities = oauth.getAuthorities();
	return authorities == null ? new HashSet<String>() : authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toSet());
}
 
開發者ID:PatternFM,項目名稱:tokamak,代碼行數:10,代碼來源:OAuth2AuthorizationContext.java


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