KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > AuthenticationSchemeResourceType


1 package com.sslexplorer.security;
2
3 import java.util.Iterator JavaDoc;
4
5 import com.sslexplorer.core.CoreAttributeConstants;
6 import com.sslexplorer.core.CoreEvent;
7 import com.sslexplorer.core.CoreEventConstants;
8 import com.sslexplorer.core.CoreServlet;
9 import com.sslexplorer.policyframework.DefaultResourceType;
10 import com.sslexplorer.policyframework.PolicyConstants;
11 import com.sslexplorer.policyframework.Resource;
12 import com.sslexplorer.policyframework.ResourceChangeEvent;
13 import com.sslexplorer.policyframework.ResourceDeleteEvent;
14
15 /**
16  * Implementation of a {@link com.sslexplorer.policyframework.ResourceType} that
17  * is used for configured <i>Authentication Schemes</i>.
18  *
19  * @author Brett Smith <a HREF="mailto:brett@3sp.com">&lt;brett@3sp.com&gt;</a>
20  */

21 public class AuthenticationSchemeResourceType extends DefaultResourceType {
22
23     /**
24      * Constructor
25      */

26     public AuthenticationSchemeResourceType() {
27         super(PolicyConstants.AUTHENTICATION_SCHEMES_RESOURCE_TYPE_ID, "policyframework", PolicyConstants.SYSTEM_CLASS);
28     }
29
30     /*
31      * (non-Javadoc)
32      *
33      * @see com.sslexplorer.navigation.FavoriteResourceType#getResourceById(int)
34      */

35     public Resource getResourceById(int resourceId) throws Exception JavaDoc {
36         return SystemDatabaseFactory.getInstance().getAuthenticationSchemeSequence(resourceId);
37     }
38
39     /* (non-Javadoc)
40      * @see com.sslexplorer.policyframework.DefaultResourceType#getResourceByName(java.lang.String, com.sslexplorer.security.SessionInfo)
41      */

42     public Resource getResourceByName(String JavaDoc resourceName, SessionInfo session) throws Exception JavaDoc {
43         return SystemDatabaseFactory.getInstance().getAuthenticationSchemeSequence(resourceName, session.getUser().getRealm().getRealmID());
44     }
45
46     /*
47      * (non-Javadoc)
48      *
49      * @see com.sslexplorer.boot.policyframework.ResourceType#removeResource(int,
50      * com.sslexplorer.security.SessionInfo)
51      */

52     public Resource removeResource(int resourceId, SessionInfo session) throws Exception JavaDoc {
53         try {
54             AuthenticationScheme resource = SystemDatabaseFactory.getInstance().getAuthenticationSchemeSequence(
55                             resourceId);
56             SystemDatabaseFactory.getInstance().deleteAuthenticationSchemeSequence(resourceId);
57             CoreServlet.getServlet().fireCoreEvent(
58                             new ResourceDeleteEvent(this, CoreEventConstants.DELETE_AUTHENTICATION_SCHEME, resource, session,
59                                             CoreEvent.STATE_SUCCESSFUL));
60             return resource;
61         } catch (Exception JavaDoc e) {
62             CoreServlet.getServlet().fireCoreEvent(
63                             new ResourceDeleteEvent(this, CoreEventConstants.DELETE_AUTHENTICATION_SCHEME, null, session,
64                                             CoreEvent.STATE_UNSUCCESSFUL));
65             throw e;
66         }
67     }
68
69     /*
70      * (non-Javadoc)
71      *
72      * @see com.sslexplorer.boot.policyframework.ResourceType#updateResource(com.sslexplorer.boot.policyframework.Resource,
73      * com.sslexplorer.security.SessionInfo)
74      */

75     public void updateResource(Resource resource, SessionInfo session) throws Exception JavaDoc {
76         try {
77             SystemDatabaseFactory.getInstance()
78                             .updateAuthenticationSchemeSequence((AuthenticationScheme) resource);
79             CoreEvent evt = new ResourceChangeEvent(this, CoreEventConstants.UPDATE_AUTHENTICATION_SCHEME, resource,
80                                session, CoreEvent.STATE_SUCCESSFUL);
81             int authCounter = 1;
82             for(Iterator JavaDoc i = ((AuthenticationScheme) resource).modules();i.hasNext(); ) {
83                 String JavaDoc s = (String JavaDoc) i.next();
84                 AuthenticationSchemeResourceType.addAuthenticationModule(evt, s, authCounter);
85                 authCounter++;
86             }
87            CoreServlet.getServlet().fireCoreEvent(evt);
88         } catch (Exception JavaDoc e) {
89             CoreServlet.getServlet().fireCoreEvent(
90                 new ResourceChangeEvent(this, CoreEventConstants.UPDATE_AUTHENTICATION_SCHEME, session, e));
91             throw e;
92         }
93     }
94     
95     /**
96      * @param evt
97      * @param authenticationModule
98      * @param position
99      */

100     public static void addAuthenticationModule(CoreEvent evt, String JavaDoc authenticationModule, int position){
101         evt.addAttribute(CoreAttributeConstants.EVENT_ATTR_AUTHENTICATION_MODULE+position, authenticationModule);
102     }
103     
104 }
105
Popular Tags