1 19 20 package com.sslexplorer.policyframework; 21 22 import com.sslexplorer.core.CoreEvent; 23 import com.sslexplorer.core.CoreEventConstants; 24 import com.sslexplorer.core.CoreServlet; 25 import com.sslexplorer.security.SessionInfo; 26 27 28 34 public class PolicyResourceType extends DefaultResourceType { 35 36 39 public PolicyResourceType() { 40 super( 41 PolicyConstants.POLICY_RESOURCE_TYPE_ID, "policyframework", PolicyConstants.SYSTEM_CLASS); 42 } 43 44 47 public Resource getResourceById(int resourceId) throws Exception { 48 return PolicyDatabaseFactory.getInstance().getPolicy(resourceId); 49 } 50 51 54 public Resource getResourceByName(String resourceName, SessionInfo session) throws Exception { 55 return PolicyDatabaseFactory.getInstance().getPolicyByName(resourceName, session.getUser().getRealm().getResourceId()); 56 } 57 58 59 62 public Resource removeResource(int resourceId, SessionInfo session) throws Exception { 63 try { 64 if(resourceId == PolicyDatabaseFactory.getInstance().getEveryonePolicyIDForRealm(session.getUser().getRealm())) { 65 throw new Exception ("Cannot remove 'Everyone' policy."); 66 } 67 Policy resource = 68 PolicyDatabaseFactory.getInstance().deletePolicy(resourceId); 69 CoreServlet.getServlet().fireCoreEvent(addPolicyAttributes( 70 new ResourceDeleteEvent(this, CoreEventConstants.DELETE_POLICY, resource, session, 71 CoreEvent.STATE_SUCCESSFUL), ((Policy)resource))); 72 return resource; 73 } catch (Exception e) { 74 CoreServlet.getServlet().fireCoreEvent( 75 new ResourceDeleteEvent(this, CoreEventConstants.DELETE_POLICY, session, e)); 76 throw e; 77 } 78 } 79 80 83 public void updateResource(Resource resource, SessionInfo session) throws Exception { 84 try { 85 PolicyDatabaseFactory.getInstance().updatePolicy((Policy)resource); 86 CoreEvent coreEvent = addPolicyAttributes(new ResourceChangeEvent(this, CoreEventConstants.UPDATE_POLICY, resource, session, 87 CoreEvent.STATE_SUCCESSFUL), ((Policy)resource)); 88 89 CoreServlet.getServlet().fireCoreEvent(coreEvent); 90 91 } catch (Exception e) { 92 CoreServlet.getServlet().fireCoreEvent( 93 new ResourceChangeEvent(this, CoreEventConstants.UPDATE_POLICY, session, e)); 94 throw e; 95 } 96 } 97 98 CoreEvent addPolicyAttributes(CoreEvent evt, Policy shortcut) { 99 return evt; 100 } 101 102 } 103 | Popular Tags |