Skip to content

Instantly share code, notes, and snippets.

@Deviad
Created September 9, 2017 23:09
Show Gist options
  • Save Deviad/c228535d25870d333ec1b7b1ae2c3948 to your computer and use it in GitHub Desktop.
Save Deviad/c228535d25870d333ec1b7b1ae2c3948 to your computer and use it in GitHub Desktop.
AOP implementation of a filter to create an ACL
package com.davidepugliese.springfood.security;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
public @interface Acl{
String value();
}
package com.davidepugliese.springfood.security;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class AclAspect {
@Pointcut("@annotation(Acl)" + "&& args(requiredAccess)")
public void accessControl(Acl requiredAccess) {
}
@Around(value = "accessControl(requiredAccess)", argNames = "joinPoint,requiredAccess")
public Object value(ProceedingJoinPoint joinPoint, Acl requiredAccess) throws Throwable {
System.out.println(">>>>" + requiredAccess);
final Object proceed = joinPoint.proceed();
return proceed;
}
}
package com.davidepugliese.springfood.security;
public class AuthenticationException extends RuntimeException {
public AuthenticationException(String message) {
super(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment