1 41 42 package org.jahia.services.acl; 43 44 import org.jahia.services.usermanager.JahiaGroup; 45 import org.jahia.services.usermanager.JahiaUser; 46 47 import java.security.Principal ; 48 import java.security.acl.Group ; 49 50 51 60 public final class ACLResource { 61 62 63 74 public static boolean checkPermission (ACLResourceInterface res, 75 Principal p, 76 int perm) { 77 return checkAccess (res, p, perm); 78 } 79 80 81 82 92 public static boolean checkAdminAccess (ACLResourceInterface res, Principal p) { 93 return checkAccess (res, p, JahiaBaseACL.ADMIN_RIGHTS); 94 } 95 96 97 107 public static boolean checkReadAccess (ACLResourceInterface res, Principal p) { 108 return checkAccess (res, p, JahiaBaseACL.READ_RIGHTS); 109 } 110 111 112 122 public static boolean checkWriteAccess (ACLResourceInterface res, Principal p) { 123 return checkAccess (res, p, JahiaBaseACL.WRITE_RIGHTS); 124 } 125 126 136 private static boolean checkAccess (ACLResourceInterface res, 137 Principal p, 138 int permission) { 139 140 if ((p == null) || (res == null) || (res.getACL () == null)) 141 return false; 142 143 boolean result = false; 145 try { 146 if (isGroup (p)) { 147 result = res.getACL ().getPermission ((JahiaGroup) p, permission); 148 } else { 149 result = res.getACL ().getPermission ((JahiaUser) p, permission); 150 } 151 } catch (JahiaACLException ex) { 152 } 154 return result; 155 } 156 157 165 private static boolean isGroup (Principal p) { 166 167 return (p instanceof Group); 168 } 169 170 } 171 172 | Popular Tags |