当前位置: 首页>>代码示例>>Java>>正文


Java Authentication.getAuthorities方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:Recks11,项目名称:theLXGweb,代码行数:24,代码来源:UrlAuthenticationSuccessHandler.java

示例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!");
}
 
开发者ID:Fetax,项目名称:Fetax-AI,代码行数:26,代码来源:MainAccessDecisionManager.java

示例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");
}
 
开发者ID:finefuture,项目名称:data-migration,代码行数:19,代码来源:OwnAccessDecisionManager.java

示例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;
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:23,代码来源:CustomSuccessHandler.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:23,代码来源:AppAuthenticationFilter.java

示例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();
}
 
开发者ID:ericywl,项目名称:InfoSys-1D,代码行数:21,代码来源:ProfChoperAuthSuccessHandler.java

示例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());
		}
	}
}
 
开发者ID:marrow16,项目名称:Nasapi,代码行数:17,代码来源:EndpointRequest.java

示例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;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:17,代码来源:AuthenticatedVoter.java

示例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;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:19,代码来源:SpringSecurityUtils.java

示例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");
}
 
开发者ID:realxujiang,项目名称:itweet-boot,代码行数:20,代码来源:MyAccessDecisionManager.java

示例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("没有权限进行操作!");
}
 
开发者ID:jeikerxiao,项目名称:SpringBootStudy,代码行数:19,代码来源:DemoAccessDecisionManager.java

示例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);
}
 
开发者ID:cerner,项目名称:jwala,代码行数:13,代码来源:UserServiceRestImpl.java

示例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");
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:13,代码来源:UserAccessTokenAuthenticationConverter.java

示例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;
}
 
开发者ID:expansel,项目名称:errai-spring-server,代码行数:10,代码来源:SpringSecurityAuthenticationService.java


注:本文中的org.springframework.security.core.Authentication.getAuthorities方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。