Search in sources :

Example 1 with AspectJMethodSecurityInterceptor

use of org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor in project spring-security by spring-projects.

the class PrePostSecured method setUp.

@Before
public final void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    interceptor = new AspectJMethodSecurityInterceptor();
    AccessDecisionVoter[] voters = new AccessDecisionVoter[] { new RoleVoter(), new PreInvocationAuthorizationAdviceVoter(new ExpressionBasedPreInvocationAdvice()) };
    adm = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>>asList(voters));
    interceptor.setAccessDecisionManager(adm);
    interceptor.setAuthenticationManager(authman);
    interceptor.setSecurityMetadataSource(new SecuredAnnotationSecurityMetadataSource());
    AnnotationSecurityAspect secAspect = AnnotationSecurityAspect.aspectOf();
    secAspect.setSecurityInterceptor(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) Before(org.junit.Before)

Example 2 with AspectJMethodSecurityInterceptor

use of org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor 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 3 with AspectJMethodSecurityInterceptor

use of org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor in project spring-security by spring-projects.

the class GlobalMethodSecurityConfiguration method methodSecurityInterceptor.

/**
	 * Creates the default MethodInterceptor which is a MethodSecurityInterceptor using
	 * the following methods to construct it.
	 * <ul>
	 * <li>{@link #accessDecisionManager()}</li>
	 * <li>{@link #afterInvocationManager()}</li>
	 * <li>{@link #authenticationManager()}</li>
	 * <li>{@link #methodSecurityMetadataSource()}</li>
	 * <li>{@link #runAsManager()}</li>
	 *
	 * </ul>
	 *
	 * <p>
	 * Subclasses can override this method to provide a different
	 * {@link MethodInterceptor}.
	 * </p>
	 *
	 * @return
	 * @throws Exception
	 */
@Bean
public MethodInterceptor methodSecurityInterceptor() throws Exception {
    this.methodSecurityInterceptor = isAspectJ() ? new AspectJMethodSecurityInterceptor() : new MethodSecurityInterceptor();
    methodSecurityInterceptor.setAccessDecisionManager(accessDecisionManager());
    methodSecurityInterceptor.setAfterInvocationManager(afterInvocationManager());
    methodSecurityInterceptor.setSecurityMetadataSource(methodSecurityMetadataSource());
    RunAsManager runAsManager = runAsManager();
    if (runAsManager != null) {
        methodSecurityInterceptor.setRunAsManager(runAsManager);
    }
    return this.methodSecurityInterceptor;
}
Also used : RunAsManager(org.springframework.security.access.intercept.RunAsManager) AspectJMethodSecurityInterceptor(org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor) AspectJMethodSecurityInterceptor(org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor) MethodSecurityInterceptor(org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor) Bean(org.springframework.context.annotation.Bean)

Example 4 with AspectJMethodSecurityInterceptor

use of org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor in project spring-security by spring-projects.

the class GlobalMethodSecurityConfiguration method methodSecurityInterceptor.

/**
 * Creates the default MethodInterceptor which is a MethodSecurityInterceptor using
 * the following methods to construct it.
 * <ul>
 * <li>{@link #accessDecisionManager()}</li>
 * <li>{@link #afterInvocationManager()}</li>
 * <li>{@link #authenticationManager()}</li>
 * <li>{@link #runAsManager()}</li>
 *
 * </ul>
 *
 * <p>
 * Subclasses can override this method to provide a different
 * {@link MethodInterceptor}.
 * </p>
 * @param methodSecurityMetadataSource the default
 * {@link MethodSecurityMetadataSource}.
 * @return the {@link MethodInterceptor}.
 */
@Bean
public MethodInterceptor methodSecurityInterceptor(MethodSecurityMetadataSource methodSecurityMetadataSource) {
    this.methodSecurityInterceptor = isAspectJ() ? new AspectJMethodSecurityInterceptor() : new MethodSecurityInterceptor();
    this.methodSecurityInterceptor.setAccessDecisionManager(accessDecisionManager());
    this.methodSecurityInterceptor.setAfterInvocationManager(afterInvocationManager());
    this.methodSecurityInterceptor.setSecurityMetadataSource(methodSecurityMetadataSource);
    RunAsManager runAsManager = runAsManager();
    if (runAsManager != null) {
        this.methodSecurityInterceptor.setRunAsManager(runAsManager);
    }
    return this.methodSecurityInterceptor;
}
Also used : RunAsManager(org.springframework.security.access.intercept.RunAsManager) AspectJMethodSecurityInterceptor(org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor) AspectJMethodSecurityInterceptor(org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor) MethodSecurityInterceptor(org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor) Bean(org.springframework.context.annotation.Bean)

Aggregations

AspectJMethodSecurityInterceptor (org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor)4 Bean (org.springframework.context.annotation.Bean)2 AccessDecisionVoter (org.springframework.security.access.AccessDecisionVoter)2 SecuredAnnotationSecurityMetadataSource (org.springframework.security.access.annotation.SecuredAnnotationSecurityMetadataSource)2 ExpressionBasedPreInvocationAdvice (org.springframework.security.access.expression.method.ExpressionBasedPreInvocationAdvice)2 RunAsManager (org.springframework.security.access.intercept.RunAsManager)2 MethodSecurityInterceptor (org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor)2 PreInvocationAuthorizationAdviceVoter (org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter)2 AffirmativeBased (org.springframework.security.access.vote.AffirmativeBased)2 RoleVoter (org.springframework.security.access.vote.RoleVoter)2 Before (org.junit.Before)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1