本文整理汇总了Java中org.springframework.security.core.Authentication.getAuthorities方法的典型用法代码示例。如果您正苦于以下问题:Java Authentication.getAuthorities方法的具体用法?Java Authentication.getAuthorities怎么用?Java Authentication.getAuthorities使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.core.Authentication
的用法示例。
在下文中一共展示了Authentication.getAuthorities方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: determineTargetUrl
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
private String determineTargetUrl(Authentication authentication) {
boolean isUser = false;
boolean isAdmin = false;
Collection<? extends GrantedAuthority> authorities
= authentication.getAuthorities();
for (GrantedAuthority grantedAuthority : authorities){
if (grantedAuthority.getAuthority().equals("ROLE_REGISTER-ROLE")) {
isUser = true;
break;
}else if (grantedAuthority.getAuthority().equals("ROLE_ADMIN")) {
isAdmin = true;
break;
}
}
if (isAdmin) {
return "/admin/";
} else if (isUser) {
return "/phy_register/io/";
} else {
throw new IllegalStateException();
}
}
示例2: decide
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes)
throws AccessDeniedException, InsufficientAuthenticationException {
//System.err.println(" ---------------MaxAccessDecisionManager decide--------------- ");
if(configAttributes == null) {
return;
}
//所请求的资源拥有的权限(一个资源对多个权限)
Iterator<ConfigAttribute> iterator = configAttributes.iterator();
while(iterator.hasNext()) {
ConfigAttribute configAttribute = iterator.next();
//访问所请求资源所需要的权限
String needPermission = configAttribute.getAttribute();
//System.out.println("NEED-> "+needPermission);
//用户所拥有的权限authentication
for(GrantedAuthority ga : authentication.getAuthorities()) {
//System.out.println("USER-> "+ga.getAuthority());
if(needPermission.equals(ga.getAuthority())) {
//System.out.println("pass");
return;
}
}
}
//没有权限
throw new AccessDeniedException("Access Denide!");
}
示例3: decide
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if(null== configAttributes || configAttributes.size() <=0) {
return;
}
ConfigAttribute c;
String needRole;
for(Iterator<ConfigAttribute> iter = configAttributes.iterator(); iter.hasNext(); ) {
c = iter.next();
needRole = c.getAttribute();
for(GrantedAuthority ga : authentication.getAuthorities()) {
if(needRole.trim().equals(ga.getAuthority())) {
return;
}
}
}
throw new AccessDeniedException("no right");
}
示例4: targetUrl
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
protected String targetUrl(Authentication authentication) {
String url = "";
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
List<String> roles = new ArrayList<String>();
for (GrantedAuthority a : authorities) {
roles.add(a.getAuthority());
}
System.out.println(roles);
if (isUserRole(roles)) {
url = "/deptform.html";
} else if (isAdminRole(roles)){
url = "/deptform.html";
} else if (isHrAdminRole(roles)){
url = "/deptform.html";
} else{
url = "/deptform.html";
}
return url;
}
示例5: successfulAuthentication
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain,
Authentication authResult) throws IOException, ServletException {
System.out.println("AUTH FILTER");
Collection<? extends GrantedAuthority> authorities = authResult.getAuthorities();
List<String> roles = new ArrayList<String>();
for (GrantedAuthority a : authorities) {
roles.add(a.getAuthority());
}
System.out.println(roles);
String name = obtainPassword(request);
String password = obtainUsername(request);
UsernamePasswordAuthenticationToken userDetails = new UsernamePasswordAuthenticationToken(name, password, authorities);
setDetails(request, userDetails);
chain.doFilter(request, response);
}
示例6: determineTargetURL
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
private String determineTargetURL(Authentication authentication) {
boolean isStudent = false;
boolean isProf = false;
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
for (GrantedAuthority grantedAuthority : authorities) {
if (grantedAuthority.getAuthority().equals(ROLE_STUDENT)) {
isStudent = true;
break;
} else if (grantedAuthority.getAuthority().equals(ROLE_PROF)) {
isProf = true;
break;
}
}
if (isProf) return "/prof";
if (isStudent) return "/student";
throw new IllegalStateException();
}
示例7: EndpointRequest
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
public EndpointRequest(UriInfo uriInfo,
HttpServletRequest httpRequest,
MultivaluedMap<String,String> pathParameters,
InputStream body,
Authentication authentication) {
this.uriInfo = uriInfo;
this.httpRequest = httpRequest;
this.pathParameters = pathParameters;
this.body = body;
this.authentication = authentication;
if (authentication != null) {
for (GrantedAuthority authority: authentication.getAuthorities()) {
roles.add(authority.getAuthority());
}
}
}
示例8: isSwitched
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
public boolean isSwitched(Authentication authentication, String attribute) {
if (!IS_SWITCHED.equals(attribute)) {
return false;
}
Collection<? extends GrantedAuthority> authorities = authentication
.getAuthorities();
for (GrantedAuthority auth : authorities) {
if (auth instanceof SwitchUserGrantedAuthority) {
return true;
}
}
return false;
}
示例9: getAuthorities
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
public static List<String> getAuthorities() {
Authentication authentication = getAuthentication();
if (authentication == null) {
return Collections.EMPTY_LIST;
}
Collection<? extends GrantedAuthority> grantedAuthorityList = authentication
.getAuthorities();
List<String> authorities = new ArrayList<String>();
for (GrantedAuthority grantedAuthority : grantedAuthorityList) {
authorities.add(grantedAuthority.getAuthority());
}
return authorities;
}
示例10: decide
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if(null== configAttributes || configAttributes.size() <=0) {
return;
}
ConfigAttribute c;
String needRole;
for(Iterator<ConfigAttribute> iter = configAttributes.iterator(); iter.hasNext(); ) {
c = iter.next();
needRole = c.getAttribute();
for(GrantedAuthority ga : authentication.getAuthorities()) {
if(needRole.trim().equals(ga.getAuthority())) {
return;
}
}
}
throw new AccessDeniedException("no right");
}
示例11: decide
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if (configAttributes == null) {
return;
}
for (ConfigAttribute ca : configAttributes) {
String needRole = ca.getAttribute();
//ga 为用户所被赋予的权限。 needRole 为访问相应的资源应该具有的权限。
for (GrantedAuthority ga : authentication.getAuthorities()) {
if (needRole.trim().equals(ga.getAuthority().trim())) {
return;
}
}
}
throw new AccessDeniedException("没有权限进行操作!");
}
示例12: isUserAdmin
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
public Response isUserAdmin(HttpServletRequest request, HttpServletResponse response) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
@SuppressWarnings("unchecked")
Collection<GrantedAuthority> authorities = (Collection<GrantedAuthority>) auth.getAuthorities();
if (authorities!= null && authorities.contains(new SimpleGrantedAuthority(ApplicationProperties.get(PROP_JWALA_ROLE_ADMIN)))) {
return ResponseBuilder.ok(JSON_RESPONSE_TRUE);
}
}
return ResponseBuilder.ok(JSON_RESPONSE_FALSE);
}
示例13: extractAuthentication
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
public Authentication extractAuthentication(Map<String, ?> map) {
Authentication authentication = super.extractAuthentication(map);
if (map.containsKey(USER_ID) && map.containsKey(USERNAME) && map.containsKey(EMAIL)) {
UserEntity user = new UserEntity()
.setId((String) map.get(USER_ID))
.setEmail((String) map.get(EMAIL))
.setUsername((String) map.get(USERNAME));
return new UsernamePasswordAuthenticationToken(user, "N/A", authentication.getAuthorities());
}
throw new BadCredentialsException("Invalid token");
}
示例14: extractAuthentication
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
public Authentication extractAuthentication(Map<String, ?> map) {
Authentication authentication = super.extractAuthentication(map);
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
AuthenticatedUser user = new AuthenticatedUser(getUsername(map), getFistName(map), getLastName(map), authorities);
return new UsernamePasswordAuthenticationToken(user, authentication.getCredentials(), authorities);
}
开发者ID:SopraSteriaGroup,项目名称:initiatives_backend_auth,代码行数:8,代码来源:CustomUserAuthenticationConverter.java
示例15: getUser
import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
private User getUser(Authentication auth) {
Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
ArrayList<RoleImpl> erraiRoles = new ArrayList<RoleImpl>(authorities.size());
for (GrantedAuthority grantedAuthority : authorities) {
erraiRoles.add(new RoleImpl(grantedAuthority.getAuthority().replace("ROLE_", "")));
}
User user = new UserImpl(auth.getName(), erraiRoles);
return user;
}