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.snip.Snip; 32 import org.snipsnap.user.Roles; 33 import org.snipsnap.user.Security; 34 import org.snipsnap.user.User; 35 36 import java.security.GeneralSecurityException ; 37 38 44 public class ACLInterceptor extends InterceptorSupport { 45 private Roles roles; 46 47 public ACLInterceptor() { 48 super(); 49 roles = new Roles(); 50 roles.add("Editor"); 51 } 52 53 public Object invoke(Invocation invocation) throws Throwable { 54 String name = invocation.getMethod().getName(); 56 User user = Application.get().getUser(); 57 Snip snip = (Snip) invocation.getTarget(); 58 if (invocation.getMethod().getName().startsWith("set")) { 59 if (user != null && !user.isAdmin()) { if (!(Security.checkPermission("Edit", user, snip) 64 || Security.hasRoles(user, snip, roles))) { 65 throw new GeneralSecurityException (snip.getName() + ": " + user + " is not allowed to modify object"); 67 } 68 } 69 } else if ("getContent".equals(name) || "getXMLContent".equals(name)) { 70 String snipName = snip.getName(); 71 if (user != null && ("SnipSnap/config".equals(snipName) || snipName.startsWith("SnipSnap/blacklist")) && !user.isAdmin()) { 72 return "content protected"; 73 } 74 } 75 return invocation.next(); 76 } 77 } 78 | Popular Tags |