Created
July 7, 2011 11:49
-
-
Save igm/1069353 to your computer and use it in GitHub Desktop.
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
@Aspect | |
@Component | |
public class SecuredAspect { | |
@Pointcut("@annotation(annotation)") | |
@SuppressWarnings("unused") | |
private void secured(Secured annotation) { | |
} | |
@Around("secured(annotation)") | |
public Object aroundCachedMethods(ProceedingJoinPoint thisJoinPoint, Secured annotation) | |
throws Throwable { | |
boolean admin = annotation.admin(); | |
UserService userService = UserServiceFactory.getUserService(); | |
boolean userLoggedIn = userService.isUserLoggedIn(); | |
if (userLoggedIn) | |
if (admin && !userService.isUserAdmin()) | |
throw new UnauthorizedAccessException(); | |
else | |
return thisJoinPoint.proceed(); | |
else | |
throw new AccessDeniedException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment