use of org.springframework.security.access.vote.AffirmativeBased in project spring-security by spring-projects.
the class AnnotationSecurityAspectTests method setUp.
@BeforeEach
public final void setUp() {
MockitoAnnotations.initMocks(this);
this.interceptor = new AspectJMethodSecurityInterceptor();
AccessDecisionVoter[] voters = new AccessDecisionVoter[] { new RoleVoter(), new PreInvocationAuthorizationAdviceVoter(new ExpressionBasedPreInvocationAdvice()) };
this.adm = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>>asList(voters));
this.interceptor.setAccessDecisionManager(this.adm);
this.interceptor.setAuthenticationManager(this.authman);
this.interceptor.setSecurityMetadataSource(new SecuredAnnotationSecurityMetadataSource());
AnnotationSecurityAspect secAspect = AnnotationSecurityAspect.aspectOf();
secAspect.setSecurityInterceptor(this.interceptor);
}
use of org.springframework.security.access.vote.AffirmativeBased in project hub-alert by blackducksoftware.
the class AuthenticationHandler method createRoleProcessor.
private ObjectPostProcessor<AffirmativeBased> createRoleProcessor() {
return new ObjectPostProcessor<>() {
@Override
public <O extends AffirmativeBased> O postProcess(O affirmativeBased) {
WebExpressionVoter webExpressionVoter = new WebExpressionVoter();
DefaultWebSecurityExpressionHandler expressionHandler = new DefaultWebSecurityExpressionHandler();
expressionHandler.setRoleHierarchy(authorities -> {
String[] allAlertRoles = retrieveAllowedRoles();
return AuthorityUtils.createAuthorityList(allAlertRoles);
});
webExpressionVoter.setExpressionHandler(expressionHandler);
affirmativeBased.getDecisionVoters().add(webExpressionVoter);
return affirmativeBased;
}
};
}
use of org.springframework.security.access.vote.AffirmativeBased in project ranger by apache.
the class StandaloneSecurityHandler method login.
public void login(String userName, String password, ApplicationContext context) throws Exception {
// [1] Create AUTH Token
Authentication token = new UsernamePasswordAuthenticationToken(userName, password);
// [2] Authenticate User
AuthenticationManager am = (AuthenticationManager) context.getBean(AUTH_MANAGER_BEAN_NAME);
token = am.authenticate(token);
// [3] Check User Access
AffirmativeBased accessDecisionManager = (AffirmativeBased) context.getBean(ACCESS_DECISION_MANAGER_BEAN_NAME);
Collection<ConfigAttribute> list = new ArrayList<ConfigAttribute>();
SecurityConfig config = new SecurityConfig(RangerConstants.ROLE_SYS_ADMIN);
list.add(config);
accessDecisionManager.decide(token, null, list);
// [4] set token in spring context
SecurityContextHolder.getContext().setAuthentication(token);
// [5] Process Success login
InetAddress thisIp = InetAddress.getLocalHost();
sessionMgr.processStandaloneSuccessLogin(XXAuthSession.AUTH_TYPE_PASSWORD, thisIp.getHostAddress());
}
use of org.springframework.security.access.vote.AffirmativeBased in project spring-security by spring-projects.
the class AbstractSecurityWebSocketMessageBrokerConfigurer method inboundChannelSecurity.
@Bean
public ChannelSecurityInterceptor inboundChannelSecurity() {
ChannelSecurityInterceptor channelSecurityInterceptor = new ChannelSecurityInterceptor(inboundMessageSecurityMetadataSource());
MessageExpressionVoter<Object> voter = new MessageExpressionVoter<Object>();
voter.setExpressionHandler(getMessageExpressionHandler());
List<AccessDecisionVoter<? extends Object>> voters = new ArrayList<AccessDecisionVoter<? extends Object>>();
voters.add(voter);
AffirmativeBased manager = new AffirmativeBased(voters);
channelSecurityInterceptor.setAccessDecisionManager(manager);
return channelSecurityInterceptor;
}
use of org.springframework.security.access.vote.AffirmativeBased in project herd by FINRAOS.
the class AppSpringModuleConfig method accessDecisionManager.
/**
* 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);
}
Aggregations