Search in sources :

Example 6 with AffirmativeBased

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);
}
Also used : SecuredAnnotationSecurityMetadataSource(org.springframework.security.access.annotation.SecuredAnnotationSecurityMetadataSource) AspectJMethodSecurityInterceptor(org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor) AffirmativeBased(org.springframework.security.access.vote.AffirmativeBased) RoleVoter(org.springframework.security.access.vote.RoleVoter) AccessDecisionVoter(org.springframework.security.access.AccessDecisionVoter) ExpressionBasedPreInvocationAdvice(org.springframework.security.access.expression.method.ExpressionBasedPreInvocationAdvice) PreInvocationAuthorizationAdviceVoter(org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with AffirmativeBased

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;
        }
    };
}
Also used : DefaultWebSecurityExpressionHandler(org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler) ObjectPostProcessor(org.springframework.security.config.annotation.ObjectPostProcessor) AffirmativeBased(org.springframework.security.access.vote.AffirmativeBased) WebExpressionVoter(org.springframework.security.web.access.expression.WebExpressionVoter)

Example 8 with 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());
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) ConfigAttribute(org.springframework.security.access.ConfigAttribute) SecurityConfig(org.springframework.security.access.SecurityConfig) Authentication(org.springframework.security.core.Authentication) AffirmativeBased(org.springframework.security.access.vote.AffirmativeBased) ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) InetAddress(java.net.InetAddress)

Example 9 with AffirmativeBased

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;
}
Also used : MessageExpressionVoter(org.springframework.security.messaging.access.expression.MessageExpressionVoter) AffirmativeBased(org.springframework.security.access.vote.AffirmativeBased) ArrayList(java.util.ArrayList) AccessDecisionVoter(org.springframework.security.access.AccessDecisionVoter) ChannelSecurityInterceptor(org.springframework.security.messaging.access.intercept.ChannelSecurityInterceptor) Bean(org.springframework.context.annotation.Bean)

Example 10 with AffirmativeBased

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);
}
Also used : AffirmativeBased(org.springframework.security.access.vote.AffirmativeBased) ArrayList(java.util.ArrayList) RoleVoter(org.springframework.security.access.vote.RoleVoter) AccessDecisionVoter(org.springframework.security.access.AccessDecisionVoter)

Aggregations

AffirmativeBased (org.springframework.security.access.vote.AffirmativeBased)14 ArrayList (java.util.ArrayList)9 AccessDecisionVoter (org.springframework.security.access.AccessDecisionVoter)9 RoleVoter (org.springframework.security.access.vote.RoleVoter)8 Bean (org.springframework.context.annotation.Bean)4 PreInvocationAuthorizationAdviceVoter (org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter)4 ExpressionBasedPreInvocationAdvice (org.springframework.security.access.expression.method.ExpressionBasedPreInvocationAdvice)3 List (java.util.List)2 AccessDecisionManager (org.springframework.security.access.AccessDecisionManager)2 ConfigAttribute (org.springframework.security.access.ConfigAttribute)2 SecurityConfig (org.springframework.security.access.SecurityConfig)2 SecuredAnnotationSecurityMetadataSource (org.springframework.security.access.annotation.SecuredAnnotationSecurityMetadataSource)2 AspectJMethodSecurityInterceptor (org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor)2 AuthenticatedVoter (org.springframework.security.access.vote.AuthenticatedVoter)2 MessageExpressionVoter (org.springframework.security.messaging.access.expression.MessageExpressionVoter)2 ChannelSecurityInterceptor (org.springframework.security.messaging.access.intercept.ChannelSecurityInterceptor)2 WebExpressionVoter (org.springframework.security.web.access.expression.WebExpressionVoter)2 InetAddress (java.net.InetAddress)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1