1 19 20 package com.sslexplorer.policyframework; 21 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.apache.struts.util.MessageResources; 26 27 import com.sslexplorer.core.CoreAttributeConstants; 28 import com.sslexplorer.core.CoreEvent; 29 import com.sslexplorer.core.CoreEventConstants; 30 import com.sslexplorer.core.CoreServlet; 31 import com.sslexplorer.core.CoreUtil; 32 import com.sslexplorer.security.SessionInfo; 33 34 35 41 public class AccessRightsResourceType extends DefaultResourceType { 42 43 46 public AccessRightsResourceType() { 47 super(PolicyConstants.ACCESS_RIGHTS_RESOURCE_TYPE_ID, "policyframework", PolicyConstants.SYSTEM_CLASS); 48 } 49 50 53 public Resource getResourceById(int resourceId) throws Exception { 54 return PolicyDatabaseFactory.getInstance().getAccessRight(resourceId); 55 } 56 57 60 public Resource getResourceByName(String resourceName, SessionInfo session) throws Exception { 61 return PolicyDatabaseFactory.getInstance().getAccessRightsByName(resourceName, session.getUser().getRealm().getRealmID()); 62 } 63 64 67 public Resource removeResource(int resourceId, SessionInfo session) throws Exception { 68 try { 69 AccessRights resource = PolicyDatabaseFactory.getInstance().deleteAccessRights(resourceId); 70 AccessRights accessRights = (AccessRights)resource; 71 ResourceDeleteEvent event = new ResourceDeleteEvent(this, CoreEventConstants.DELETE_ACCESS_RIGHT, resource, session, CoreEvent.STATE_SUCCESSFUL); 72 event.addAttribute(CoreAttributeConstants.EVENT_ATTR_TYPE_ACCESS_RIGHT, getAccessRightType(session, accessRights.getAccessRightsClass())); 73 CoreServlet.getServlet().fireCoreEvent(addAccessRightsAttributes(event, accessRights)); 74 return resource; 75 } catch (Exception e) { 76 CoreServlet.getServlet().fireCoreEvent( 77 new ResourceDeleteEvent(this, CoreEventConstants.DELETE_ACCESS_RIGHT, session, e)); 78 throw e; 79 } 80 } 81 82 85 public void updateResource(Resource resource, SessionInfo session) throws Exception { 86 try { 87 AccessRights accessRights = (AccessRights)resource; 88 PolicyDatabaseFactory.getInstance().updateAccessRights(accessRights); 89 CoreEvent coreEvent = addAccessRightsAttributes(new ResourceChangeEvent(this, CoreEventConstants.UPDATE_ACCESS_RIGHT, resource, session, CoreEvent.STATE_SUCCESSFUL), accessRights); 90 91 List permissionsList = accessRights.getAccessRights(); 92 if (permissionsList != null) { 93 int j =0; 94 for (Iterator i = permissionsList.iterator(); i.hasNext();) { 95 j++; 96 AccessRight permission = (AccessRight)i.next(); 97 98 MessageResources mrPermission = CoreUtil.getMessageResources(session.getHttpSession(), permission.getPermission().getBundle()); 99 String permissionName = mrPermission.getMessage("permission."+permission.getPermission().getId()+".title"); 100 101 MessageResources mrResourceType = CoreUtil.getMessageResources(session.getHttpSession(), permission.getResourceType().getBundle()); 102 String resourceTypeName = mrResourceType.getMessage("resourceType."+permission.getResourceType().getResourceTypeId()+".title"); 103 104 coreEvent.addAttribute(CoreAttributeConstants.EVENT_ATTR_TYPE_PERMISSION + Integer.toString(j), permissionName + " " + resourceTypeName); 105 } 106 } 107 coreEvent.addAttribute(CoreAttributeConstants.EVENT_ATTR_TYPE_ACCESS_RIGHT, getAccessRightType(session, accessRights.getAccessRightsClass())); 108 CoreServlet.getServlet().fireCoreEvent(coreEvent); 109 } catch (Exception e) { 110 CoreServlet.getServlet().fireCoreEvent( 111 new ResourceChangeEvent(this, CoreEventConstants.UPDATE_ACCESS_RIGHT, session, e)); 112 throw e; 113 } 114 } 115 116 CoreEvent addAccessRightsAttributes(CoreEvent evt, AccessRights resource) { 117 return evt; 118 } 119 120 private static String getAccessRightType(SessionInfo session, String permissionClass) { 121 MessageResources messageResources = CoreUtil.getMessageResources(session.getHttpSession(), "policyframework"); 122 String accessRightType = messageResources.getMessage("permission.type." + permissionClass); 123 return accessRightType; 124 } 125 } | Popular Tags |