KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > PolicyResourceType


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

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 /**
29  * Implementation of a {@link com.sslexplorer.policyframework.ResourceType}
30  * for <i>Policy</i> resources.
31  *
32  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
33  */

34 public class PolicyResourceType extends DefaultResourceType {
35
36     /**
37      * Constructor
38      */

39     public PolicyResourceType() {
40         super(
41             PolicyConstants.POLICY_RESOURCE_TYPE_ID, "policyframework", PolicyConstants.SYSTEM_CLASS);
42     }
43
44     /* (non-Javadoc)
45      * @see com.sslexplorer.navigation.FavoriteResourceType#getResourceById(int)
46      */

47     public Resource getResourceById(int resourceId) throws Exception JavaDoc {
48         return PolicyDatabaseFactory.getInstance().getPolicy(resourceId);
49     }
50
51     /* (non-Javadoc)
52      * @see com.sslexplorer.policyframework.DefaultResourceType#getResourceByName(java.lang.String, com.sslexplorer.security.SessionInfo)
53      */

54     public Resource getResourceByName(String JavaDoc resourceName, SessionInfo session) throws Exception JavaDoc {
55         return PolicyDatabaseFactory.getInstance().getPolicyByName(resourceName, session.getUser().getRealm().getResourceId());
56     }
57
58
59     /* (non-Javadoc)
60      * @see com.sslexplorer.boot.policyframework.ResourceType#removeResource(int, com.sslexplorer.security.SessionInfo)
61      */

62     public Resource removeResource(int resourceId, SessionInfo session) throws Exception JavaDoc {
63         try {
64             if(resourceId == PolicyDatabaseFactory.getInstance().getEveryonePolicyIDForRealm(session.getUser().getRealm())) {
65                 throw new Exception JavaDoc("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 JavaDoc e) {
74             CoreServlet.getServlet().fireCoreEvent(
75                 new ResourceDeleteEvent(this, CoreEventConstants.DELETE_POLICY, session, e));
76             throw e;
77         }
78     }
79
80     /* (non-Javadoc)
81      * @see com.sslexplorer.boot.policyframework.ResourceType#updateResource(com.sslexplorer.boot.policyframework.Resource, com.sslexplorer.security.SessionInfo)
82      */

83     public void updateResource(Resource resource, SessionInfo session) throws Exception JavaDoc {
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 JavaDoc 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