当前位置: 首页>>代码示例>>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;未经允许,请勿转载。