Created
September 9, 2017 23:09
-
-
Save Deviad/c228535d25870d333ec1b7b1ae2c3948 to your computer and use it in GitHub Desktop.
AOP implementation of a filter to create an ACL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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