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


Java ConfigAttribute类代码示例

本文整理汇总了Java中org.springframework.security.access.ConfigAttribute的典型用法代码示例。如果您正苦于以下问题:Java ConfigAttribute类的具体用法?Java ConfigAttribute怎么用?Java ConfigAttribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConfigAttribute类属于org.springframework.security.access包,在下文中一共展示了ConfigAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decide

import org.springframework.security.access.ConfigAttribute; //导入依赖的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

示例2: decide

import org.springframework.security.access.ConfigAttribute; //导入依赖的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

示例3: decide

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
@Override
public void decide(Authentication authentication, Object o, Collection<ConfigAttribute> collection)
        throws AccessDeniedException, InsufficientAuthenticationException {
    if (collection == null) {
        return;
    }
    String needRole;
    //遍历需要的角色,如果一样,则通过
    CustomerUserDetail userDetail = (CustomerUserDetail) authentication.getPrincipal();
    List<Role> userRoleList = securityService.getUserRoleList(userDetail.getUsername(), userDetail.getAccountType());
    for (ConfigAttribute configAttribute : collection) {
        needRole = configAttribute.getAttribute();
        for (Role role : userRoleList) {
            if (needRole.equals(role.getRoleCode())) {
                return;
            }
        }
    }
    throw new AccessDeniedException("Cannot Access!");
}
 
开发者ID:DomKing,项目名称:busi-support,代码行数:21,代码来源:CustomerAccessDecisionManager.java

示例4: getAttributes

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
@Override
public Collection<ConfigAttribute> getAttributes(Object o) throws IllegalArgumentException {
    String url = ((FilterInvocation) o).getRequestUrl();

    logger.debug("request url is  " + url);

    if (resourceMap == null) {
        resourceMap = loadResourceMatchAuthority();
    }

    for (String resURL : resourceMap.keySet()) {
        if (pathMatcher.match(resURL, url)) {
            return resourceMap.get(resURL);
        }
    }
    return resourceMap.get(url);
}
 
开发者ID:DomKing,项目名称:busi-support,代码行数:18,代码来源:CustomerSecurityMetadataSource.java

示例5: vote

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
public int vote(Authentication authentication, Object object,
        Collection<ConfigAttribute> configAttributes) {
    int result = ACCESS_ABSTAIN;

    for (ConfigAttribute configAttribute : configAttributes) {
        if (this.supports(configAttribute)) {
            result = ACCESS_DENIED;

            String text = getPermission(configAttribute);
            boolean authorized = permissionChecker.isAuthorized(text);

            if (authorized) {
                return ACCESS_GRANTED;
            }
        }
    }

    return result;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:20,代码来源:PermissionVoter.java

示例6: canCurrentUserAccessView

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
/**
 * @param viewClass
 * @return true si l'utilisateur peut accéder à la vue
 */
public boolean canCurrentUserAccessView(Class<? extends View> viewClass, Authentication auth) {
	if (auth == null) {
		return false;
	}
	MethodInvocation methodInvocation = MethodInvocationUtils.createFromClass(viewClass, "enter");
	Collection<ConfigAttribute> configAttributes = methodSecurityInterceptor.obtainSecurityMetadataSource()
			.getAttributes(methodInvocation);
	/* Renvoie true si la vue n'est pas sécurisée */
	if (configAttributes.isEmpty()) {
		return true;
	}
	/* Vérifie que l'utilisateur a les droits requis */
	try {
		methodSecurityInterceptor.getAccessDecisionManager().decide(auth, methodInvocation, configAttributes);
	} catch (InsufficientAuthenticationException | AccessDeniedException e) {
		return false;
	}
	return true;
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:24,代码来源:UserController.java

示例7: decide

import org.springframework.security.access.ConfigAttribute; //导入依赖的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

示例8: loadResourceDefine

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
@PostConstruct
private void loadResourceDefine() {
	//System.err.println(" ---------------MaxSecurityMetadataSource loadResourceDefine--------------- ");
	if (resourceMap == null) {
		resourceMap = new HashMap<String, Collection<ConfigAttribute>>();
		List<Resources> resources = authService.fetchAllResources();
		for (Resources resource : resources) {
			Collection<ConfigAttribute> configAttributes = new ArrayList<ConfigAttribute>();
			Set<Role> roles = resource.getRoles();
			for(Role r : roles) {
				ConfigAttribute configAttribute = new SecurityConfig(r.getRoleKey());
				configAttributes.add(configAttribute);
			}
			resourceMap.put(resource.getResUrl(), configAttributes);
		}
	}
}
 
开发者ID:Fetax,项目名称:Fetax-AI,代码行数:18,代码来源:MainSecurityMetadataSource.java

示例9: decide

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
@Override
public void decide(Authentication authentication, Object o, Collection<ConfigAttribute> collection)
        throws AccessDeniedException, InsufficientAuthenticationException {
    if (collection == null) {
        return;
    }
    String needRole;
    //遍历需要的角色,如果一样,则通过,避免角色信息变了,从数据库取
    CustomerUserDetail userDetail = (CustomerUserDetail) authentication.getPrincipal();
    List<Role> roleList = securityService.getUserRoleList(userDetail.getUsername(), userDetail.getAccountType());
    for (ConfigAttribute configAttribute : collection) {
        needRole = configAttribute.getAttribute();
        for (Role aRoleList : roleList) {
            if (aRoleList != null && needRole.equals(aRoleList.getRoleCode())) {
                return;
            }
        }
    }
    throw new AccessDeniedException("Cannot Access!");
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:21,代码来源:CustomerAccessDecisionManager.java

示例10: getAttributes

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
@Override
public Collection<ConfigAttribute> getAttributes(Object o) throws IllegalArgumentException {
    String url = ((FilterInvocation) o).getRequestUrl();

    if (!url.contains("/js/") && !url.contains("/html/") && !url.contains("/css/") && !url.contains("/images/")) {
        logger.debug("request url is  " + url);
    }

    if (resourceMap == null) {
        resourceMap = loadResourceMatchAuthority();
    }

    for (String resURL : resourceMap.keySet()) {
        if (pathMatcher.match(resURL, url)) {
            return resourceMap.get(resURL);
        }
    }
    return resourceMap.get(url);
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:20,代码来源:CustomerSecurityMetadataSource.java

示例11: decide

import org.springframework.security.access.ConfigAttribute; //导入依赖的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: RequestConfigMapping

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
public RequestConfigMapping(RequestMatcher matcher, Collection<ConfigAttribute> attributes) {
    if (matcher == null) {
        throw new IllegalArgumentException("matcher cannot be null");
    }
    Assert.notEmpty(attributes, "attributes cannot be null or emtpy");

    this.matcher = matcher;
    this.attributes = attributes;
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:10,代码来源:RequestConfigMapping.java

示例13: filter

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
	return exchange.getPrincipal()
		.filter(p -> p instanceof Authentication)
		.then( p-> Mono.just((Authentication) p))
		.filter(authentication -> {
			return authentication != null && authentication.isAuthenticated();
		})
		.then(authentication -> {
			return source.getConfigAttributes(exchange).as( (Function<? super Flux<ConfigAttribute>, Mono<Boolean>>) a -> {
				return accessDecisionManager.decide(authentication, exchange, a);
			});
		})
		.filter(t -> t)
		.otherwiseIfEmpty(Mono.defer(() -> {
			return entryPoint.commence(exchange, new AuthenticationCredentialsNotFoundException("Not Found"));
		}))
		.then(sc -> {
			return chain.filter(exchange);
		});
}
 
开发者ID:guilhebl,项目名称:item-shop-reactive-backend,代码行数:22,代码来源:AuthorizationWebFilter.java

示例14: decide

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
public Mono<Boolean> decide(Authentication authentication, Object object, Flux<ConfigAttribute> configAttributes) {
	return Mono
		.just(Tuples.of(authentication, object, configAttributes))
		.publishOn(Schedulers.elastic())
		.filter((Tuple3<Authentication, Object, Flux<ConfigAttribute>> t) -> {
			Authentication auth = t.getT1();
			return auth != null && auth.isAuthenticated();
		})
		.then((Function<Tuple3<Authentication, Object, Flux<ConfigAttribute>>, Mono<Boolean>>) t -> {
			List<ConfigAttribute> attrs = new ArrayList<>();
			t.getT3().toIterable().forEach(attrs::add);

			try {
				accessDecisionManager.decide(t.getT1(), t.getT2(), attrs);
				return Mono.just(true);
			} catch(AccessDeniedException fail) {
				return Mono.just(false);
			}
		});
}
 
开发者ID:guilhebl,项目名称:item-shop-reactive-backend,代码行数:21,代码来源:ReactiveAccessDecisionManagerAdapter.java

示例15: buildConfigAttributes

import org.springframework.security.access.ConfigAttribute; //导入依赖的package包/类
private void buildConfigAttributes(Role role,List<ConfigAttribute> list){
	for(RoleMember member:role.getRoleMembers()){
		SecurityConfigAttribute attribute=null;
		if(member.getUser()!=null){
			attribute=new SecurityConfigAttribute(AttributeType.user,member.isGranted(),role.getCompanyId());
			attribute.setMember(member.getUser());
		}
		if(member.getDept()!=null){
			attribute=new SecurityConfigAttribute(AttributeType.dept,member.isGranted(),role.getCompanyId());
			attribute.setMember(member.getDept());
		}
		if(member.getPosition()!=null){
			attribute=new SecurityConfigAttribute(AttributeType.position,member.isGranted(),role.getCompanyId());
			attribute.setMember(member.getPosition());
		}
		if(member.getGroup()!=null){
			attribute=new SecurityConfigAttribute(AttributeType.group,member.isGranted(),role.getCompanyId());
			attribute.setMember(member.getGroup());
		}
		list.add(attribute);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:23,代码来源:UrlMetadataSource.java


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