Skip to content

Instantly share code, notes, and snippets.

@igm
Created July 7, 2011 11:49
Show Gist options
  • Save igm/1069353 to your computer and use it in GitHub Desktop.
Save igm/1069353 to your computer and use it in GitHub Desktop.
@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