📄 aclresource.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .//////// NK 24.01.2002 - added in Jahia//package org.jahia.services.acl;import java.security.Principal;import java.security.acl.Group;import org.jahia.services.usermanager.JahiaGroup;import org.jahia.services.usermanager.JahiaUser;/** * Holds static methods to manipulate acl rights on any resource * that implements the ACLResourceInterface. * * They apply to a Principal that should be a JahiaUser or JahiaGroup * * @author Khue Nguyen * * @see ACLResourceInterface * @version 1.0 */public final class ACLResource{ private static final String CLASS_NAME = ACLResource.class.getName(); //-------------------------------------------------------------------------- /** * Check if the Principal has a given permission access on the specified resource. * * @param ACLResourceInterface res, a resource that implements the ACLResourceInterface. * @param Principal p, reference to a JahiaUser or JahiaGroup. * @param int perm, the permission. * @param siteID, the context used to retrieve the site's administrator group * * @return Return true if the Principal has a given permission for the specified res, * or false in any other case. */ public static boolean checkPermission ( ACLResourceInterface res, Principal p, int perm, int siteID) { if ( isGroup(p) ) return checkAccess(res,(JahiaGroup)p,perm, siteID); return checkAccess(res,(JahiaUser)p,perm, siteID); } //-------------------------------------------------------------------------- /** * Check if the Principal has administration access on the specified resource. * * @param ACLResourceInterface res, a resource that implements the ACLResourceInterface. * @param Principal p, reference to a JahiaUser or JahiaGroup. * @param siteID, the context used to retrieve the site's administrator group * * @return Return true if the Principal has admin access for the specified res, * or false in any other case. */ public static boolean checkAdminAccess (ACLResourceInterface res, Principal p, int siteID) { if ( isGroup(p) ) return checkAccess(res,(JahiaGroup)p,JahiaBaseACL.ADMIN_RIGHTS, siteID); return checkAccess(res,(JahiaUser)p,JahiaBaseACL.ADMIN_RIGHTS, siteID); } //-------------------------------------------------------------------------- /** * Check if the Principal has read access on the specified res. * * @param ACLResourceInterface res, a resource that implements the ACLResourceInterface. * @param Principal p, reference to a JahiaUser or JahiaGroup. * @param siteID, the context used to retrieve the site's administrator group * * @return Return true if the Principal has read access for the specified res, * or false in any other case. */ public static boolean checkReadAccess (ACLResourceInterface res, Principal p, int siteID) { if ( isGroup(p) ) return checkAccess(res,(JahiaGroup)p,JahiaBaseACL.READ_RIGHTS, siteID); return checkAccess(res,(JahiaUser)p,JahiaBaseACL.READ_RIGHTS, siteID); } //-------------------------------------------------------------------------- /** * Check if the Principal has Write access on the specified res. * * @param ACLResourceInterface res, a resource that implements the ACLResourceInterface. * @param Principal p, reference to a JahiaUser or JahiaGroup. * * @return Return true if the Principal has write access for the specified res, * or false in any other case. */ public static boolean checkWriteAccess (ACLResourceInterface res, Principal p, int siteID) { if ( isGroup(p) ) return checkAccess(res,(JahiaGroup)p,JahiaBaseACL.WRITE_RIGHTS, siteID); return checkAccess(res,(JahiaUser)p,JahiaBaseACL.WRITE_RIGHTS, siteID); } //-------------------------------------------------------------------------- /** * check ACL permissions * * @param ACLResourceInterface res, the resource * @param Principal p, reference to a JahiaUser or JahiaGroup. * @param int the permission * @param siteID, the context used to retrieve the site's administrator group * * @return boolean true if the user has the given permission on this resource */ private static boolean checkAccess ( ACLResourceInterface res, Principal p, int permission, int siteID ) { //JahiaConsole.println(CLASS_NAME+".checkAccess","Started"); if ( (p == null) || (res == null) || (res.getACL() == null) ) return false; // Test the access rights boolean result = false; try { if ( isGroup(p) ){ result = res.getACL().getPermission ((JahiaGroup)p, permission); } else { result = res.getACL().getPermission ((JahiaUser)p, permission, siteID); } } catch (JahiaACLException ex) { // if an error occured, just return false; } return result; } //-------------------------------------------------------------------------- /** * returns true if the principal is a Group * * @param Principal p, reference to a JahiaUser or JahiaGroup. * * @return boolean true if the Principal is a Group */ private static boolean isGroup ( Principal p ) { return ( p instanceof Group ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -