Skip to content

Instantly share code, notes, and snippets.

<beans>
...
<bean class="security.SecurityAspect" />
<aop:aspectj-autoproxy />
</beans>
@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)
@igm
igm / Secured.java
Created July 7, 2011 11:48
Secured annotation
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface Secured {
Boolean admin() default false;
}
@igm
igm / MyController.java
Created July 7, 2011 11:46
Secured methods
@Controller
public class MyController {
@Secured(admin = true)
@RequestMapping(value="/show_users.html", method = RequestMethod.GET)
public String showAllUsers(Model model) {
...
}
...
}