本文整理汇总了Java中org.springframework.security.access.AccessDecisionVoter类的典型用法代码示例。如果您正苦于以下问题:Java AccessDecisionVoter类的具体用法?Java AccessDecisionVoter怎么用?Java AccessDecisionVoter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AccessDecisionVoter类属于org.springframework.security.access包,在下文中一共展示了AccessDecisionVoter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decide
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void decide(Authentication authentication, Object object,Collection<ConfigAttribute> configAttributes)throws AccessDeniedException, InsufficientAuthenticationException {
if((authentication.getPrincipal() instanceof IUser)){
IUser loginUser=(IUser)authentication.getPrincipal();
if(loginUser.isAdministrator())return;
}
int result=10;
for (AccessDecisionVoter<Object> voter : getDecisionVoters()) {
result = voter.vote(authentication, object, configAttributes);
if(result==AccessDecisionVoter.ACCESS_ABSTAIN){
continue;
}
if(result==AccessDecisionVoter.ACCESS_DENIED){
throw new AccessDeniedException("Access is denied");
}
if(result==AccessDecisionVoter.ACCESS_GRANTED){
break;
}
}
if(result==AccessDecisionVoter.ACCESS_ABSTAIN && configAttributes.size()>0){
throw new AccessDeniedException("Access is denied");
}
}
示例2: decide
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
public boolean decide(Authentication authentication,Collection<ConfigAttribute> configAttributes){
if((authentication.getPrincipal() instanceof IUser)){
IUser loginUser=(IUser)authentication.getPrincipal();
if(loginUser.isAdministrator())return true;
}
int result=10;
for (AccessDecisionVoter<Object> voter : decisionVoters) {
result = voter.vote(authentication,null, configAttributes);
if(result==AccessDecisionVoter.ACCESS_ABSTAIN){
continue;
}
if(result==AccessDecisionVoter.ACCESS_DENIED){
return false;
}
if(result==AccessDecisionVoter.ACCESS_GRANTED){
break;
}
}
if(result==AccessDecisionVoter.ACCESS_ABSTAIN && configAttributes.size()>0){
return false;
}else{
return true;
}
}
示例3: userHasProperties
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
/**
* Ensures that a user who has all the properties is granted ACCESS_GRANTED
*/
@Test
public void userHasProperties()
{
final Map<String, String> properties = CollectionUtil.newMap();
properties.put("USERNAME", "username");
properties.put("PASSWORD", "password");
userDetails.setProperties(properties);
final int decision = decisionVoter.vote(token, this,
CollectionUtil.<ConfigAttribute> newList());
assertThat(new Integer(decision), is(new Integer(
AccessDecisionVoter.ACCESS_GRANTED)));
}
示例4: configureUrlAuthorization
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
@Override
protected void configureUrlAuthorization(
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry expressionInterceptUrlRegistry)
{
@SuppressWarnings("rawtypes")
List<AccessDecisionVoter> listOfVoters = new ArrayList<AccessDecisionVoter>();
listOfVoters.add(new WebExpressionVoter());
listOfVoters.add(new MolgenisAccessDecisionVoter());
expressionInterceptUrlRegistry.accessDecisionManager(new AffirmativeBased(listOfVoters));
expressionInterceptUrlRegistry.antMatchers("/").permitAll()
// DAS datasource uses the database, unauthenticated users can
// not see any data
.antMatchers("/das/**").permitAll()
.antMatchers("/myDas/**").permitAll()
.antMatchers("/annotators/**").authenticated()
.antMatchers("/charts/**").authenticated();
}
示例5: accessDecisionManager
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
@Bean
public AccessDecisionManager accessDecisionManager() {
List<AccessDecisionVoter<? extends Object>> decisionVoters = new ArrayList<>();
decisionVoters.add(new RoleVoter());
decisionVoters.add(new AuthenticatedVoter());
decisionVoters.add(webExpressionVoter());
return new AffirmativeBased(decisionVoters);
}
示例6: accessDecisionManager
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
@Description("ConsensusBased AccessDecisionManager for Authorization voting")
@Bean
public AccessDecisionManager accessDecisionManager(
CustomWebSecurityExpressionHandler customWebSecurityExpressionHandler) {
List<AccessDecisionVoter<? extends Object>> decisionVoters
= Arrays.asList(
// new AuthenticatedVoter(),
// new RoleVoter(),
new WebExpressionVoter(){{
setExpressionHandler(customWebSecurityExpressionHandler);
}}
);
return new ConsensusBased(decisionVoters);
}
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:15,代码来源:CustomAuthorizationConfig.java
示例7: accessDecisionManager2
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
public AccessDecisionManager accessDecisionManager2(
CustomWebSecurityExpressionHandler customWebSecurityExpressionHandler) {
List<AccessDecisionVoter<? extends Object>> decisionVoters
= Arrays.asList(
new AuthenticatedVoter(),
new RoleVoter(),
new WebExpressionVoter(){{
setExpressionHandler(customWebSecurityExpressionHandler);
}}
);
return new UnanimousBased(decisionVoters);
}
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:13,代码来源:CustomAuthorizationConfig.java
示例8: accessDecisionManager
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
@Description("AccessDecisionManager for Authorization voting")
@Bean
public AccessDecisionManager accessDecisionManager(
CustomWebSecurityExpressionHandler customWebSecurityExpressionHandler) {
List<AccessDecisionVoter<? extends Object>> decisionVoters
= Arrays.asList(
new WebExpressionVoter(){{
setExpressionHandler(customWebSecurityExpressionHandler);
}}
);
return new ConsensusBased(decisionVoters);
}
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:13,代码来源:CustomAuthorizationConfig.java
示例9: accessDecisionManager
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
@Description("ConsensusBased AccessDecisionManager for Authorization voting")
@Bean
public AccessDecisionManager accessDecisionManager(
CustomWebSecurityExpressionHandler customWebSecurityExpressionHandler) {
List<AccessDecisionVoter<? extends Object>> decisionVoters
= Arrays.asList(
new WebExpressionVoter(){{
setExpressionHandler(customWebSecurityExpressionHandler);
}}
);
return new ConsensusBased(decisionVoters);
}
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:13,代码来源:CustomAuthorizationConfig.java
示例10: shellAccessDecisionManager
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
@Bean
public AccessDecisionManager shellAccessDecisionManager() {
List<AccessDecisionVoter<?>> voters = new ArrayList<AccessDecisionVoter<?>>();
RoleVoter voter = new RoleVoter();
voter.setRolePrefix("");
voters.add(voter);
return new UnanimousBased(voters);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:CrshAutoConfigurationTests.java
示例11: checkUrlAccessExpression
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
private void checkUrlAccessExpression() {
log.debug("check if URL access expressions are allowed");
String[] names = context.getBeanDefinitionNames();
for (String name : names) {
if (context.getBean(name) instanceof AbstractAccessDecisionManager) {
for (AccessDecisionVoter v : ((AbstractAccessDecisionManager) context.getBean(name)).getDecisionVoters()) {
if (v instanceof WebExpressionVoter) {
log.debug("parse urlAccess as EL expression");
urlAccessExpression = true;
return;
}
}
}
}
log.debug("parse urlAccess as simple expression");
urlAccessExpression = false;
}
示例12: filterInvocationInterceptor
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
@Bean
public FilterSecurityInterceptor filterInvocationInterceptor(){
List<AccessDecisionVoter> vote = new ArrayList<AccessDecisionVoter>(Arrays.asList(new WebExpressionVoter()));
AffirmativeBased voters = new AffirmativeBased(vote);
voters.setAllowIfAllAbstainDecisions(false);
FilterSecurityInterceptor bean = new FilterSecurityInterceptor();
bean.setAuthenticationManager(authenticationManager());
bean.setAccessDecisionManager(voters);
bean.setSecurityMetadataSource(securityMetadataSource);
bean.setMessageSource(messageSource);
return bean;
}
示例13: accessDecisionManager
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
/**
* Overridden to remove role prefix for the role voter. The application does not require any other access decision voters in the default configuration.
*/
/*
* rawtypes must be suppressed because AffirmativeBased constructor takes in a raw typed list of AccessDecisionVoters
*/
@SuppressWarnings("rawtypes")
@Override
protected AccessDecisionManager accessDecisionManager()
{
List<AccessDecisionVoter<?>> decisionVoters = new ArrayList<>();
RoleVoter decisionVoter = new RoleVoter();
decisionVoter.setRolePrefix("");
decisionVoters.add(decisionVoter);
return new AffirmativeBased(decisionVoters);
}
示例14: accessDecisionManager
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
/***
* 对应的方法决策器
*/
@Override
protected AccessDecisionManager accessDecisionManager() {
AccessDecisionManager decisionManager = super.accessDecisionManager();
@SuppressWarnings("unchecked")
List<AccessDecisionVoter<? extends Object>> decisionVoters = (List<AccessDecisionVoter<? extends Object>>)ReflectUtils.getFieldValue(decisionManager, "decisionVoters");
decisionVoters.add(new MethodWebExpressionVoter());
return decisionManager;
}
示例15: getAffirmativeBased
import org.springframework.security.access.AccessDecisionVoter; //导入依赖的package包/类
/**
* Gets the affirmative based.
*
* @return the affirmative based
*/
@Bean(name = "httpRequestAccessDecisionManager")
public AffirmativeBased getAffirmativeBased() {
List<AccessDecisionVoter<? extends Object>> decisionVoters = new ArrayList<>();
decisionVoters.add(getRoleVoter());
AffirmativeBased based = new AffirmativeBased(decisionVoters);
based.setAllowIfAllAbstainDecisions(false);
return based;
}