1 25 26 package org.snipsnap.interceptor.custom; 27 28 import org.snipsnap.app.Application; 29 import org.snipsnap.interceptor.InterceptorSupport; 30 import org.snipsnap.interceptor.Invocation; 31 import org.snipsnap.user.Roles; 32 import org.snipsnap.user.Security; 33 import org.snipsnap.user.User; 34 35 import java.security.GeneralSecurityException ; 36 37 public class BlogACLInterceptor extends InterceptorSupport { 38 private Roles roles; 39 40 public BlogACLInterceptor() { 41 super(); 42 roles = new Roles(); 43 roles.add("Editor"); 44 } 45 46 public Object invoke(Invocation invocation) throws Throwable { 47 if (invocation.getMethod().getName().startsWith("post")) { 48 User user = Application.get().getUser(); 49 if (!Security.hasRoles(user, null, roles)) { 50 throw new GeneralSecurityException ("Not allowed to post."); 52 } 53 } 54 return invocation.next(); 55 } 56 } 57 | Popular Tags |