KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > security > realm > factory > JResourceLDAPFactory


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: JResourceLDAPFactory.java,v 1.3 2004/05/25 15:13:28 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.security.realm.factory;
28
29 //import java
30
import java.util.Hashtable JavaDoc;
31
32 //import javax
33
import javax.naming.Context JavaDoc;
34 import javax.naming.Name JavaDoc;
35 import javax.naming.Reference JavaDoc;
36
37 //import objectweb.util
38
import org.objectweb.util.monolog.api.BasicLevel;
39
40 /**
41  * This class provides an implementation of a JResource JNDI factory for
42  * managing users
43  * @author Florent Benoit
44  */

45 public class JResourceLDAPFactory extends JResourceFactory {
46
47     /**
48      * The Java type for which this factory knows how to create objects.
49      */

50     private static final String JavaDoc FACTORY_TYPE = "org.objectweb.jonas.security.realm.factory.JResourceLDAP";
51
52     /**
53      * Creates a javax.mail.Session object using the location or reference
54      * information specified.
55      * @param obj the possibly null object containing location or reference
56      * information that can be used in creating an object.
57      * @param name the name of this object relative to nameCtx, or null if no
58      * name is specified.
59      * @param nameCtx the context relative to which the name parameter is
60      * specified, or null if name is relative to the default initial
61      * context.
62      * @param environment the possibly null environment that is used in creating
63      * the object.
64      * @return a newly created javax.mail.Session object with the specific
65      * configuration; null if an object cannot be created.
66      * @throws Exception if this object factory encountered an exception while
67      * attempting to create an object, and no other object factories are
68      * to be tried.
69      */

70     public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc environment) throws Exception JavaDoc {
71
72         // Get the reference
73
Reference JavaDoc ref = (Reference JavaDoc) obj;
74
75         // Get the class name
76
String JavaDoc clname = ref.getClassName();
77
78         // Check the class name
79
if (!ref.getClassName().equals(FACTORY_TYPE)) {
80             getLogger().log(BasicLevel.ERROR, "Cannot create object : required type is '" + FACTORY_TYPE
81                     + "', but found type is '" + clname + "'.");
82             return (null);
83         }
84
85         String JavaDoc jResName = (String JavaDoc) ref.get("name").getContent();
86         String JavaDoc initialContextFactory = (String JavaDoc) ref.get("initialContextFactory").getContent();
87         String JavaDoc providerUrl = (String JavaDoc) ref.get("providerUrl").getContent();
88         String JavaDoc securityAuthentication = (String JavaDoc) ref.get("securityAuthentication").getContent();
89         String JavaDoc securityPrincipal = (String JavaDoc) ref.get("securityPrincipal").getContent();
90         String JavaDoc securityCredentials = (String JavaDoc) ref.get("securityCredentials").getContent();
91         String JavaDoc securityProtocol = (String JavaDoc) ref.get("securityProtocol").getContent();
92         String JavaDoc language = (String JavaDoc) ref.get("language").getContent();
93         String JavaDoc referral = (String JavaDoc) ref.get("referral").getContent();
94         String JavaDoc stateFactories = (String JavaDoc) ref.get("stateFactories").getContent();
95         String JavaDoc authenticationMode = (String JavaDoc) ref.get("authenticationMode").getContent();
96         String JavaDoc userPasswordAttribute = (String JavaDoc) ref.get("userPasswordAttribute").getContent();
97         String JavaDoc userRolesAttribute = (String JavaDoc) ref.get("userRolesAttribute").getContent();
98         String JavaDoc roleNameAttribute = (String JavaDoc) ref.get("roleNameAttribute").getContent();
99         String JavaDoc baseDN = (String JavaDoc) ref.get("baseDN").getContent();
100         String JavaDoc userDN = (String JavaDoc) ref.get("userDN").getContent();
101         String JavaDoc userSearchFilter = (String JavaDoc) ref.get("userSearchFilter").getContent();
102         String JavaDoc roleDN = (String JavaDoc) ref.get("roleDN").getContent();
103         String JavaDoc roleSearchFilter = (String JavaDoc) ref.get("roleSearchFilter").getContent();
104         String JavaDoc algorithm = (String JavaDoc) ref.get("algorithm").getContent();
105
106         // Create and return a new object
107
JResourceLDAP jResourceLDAP = new JResourceLDAP();
108         jResourceLDAP.setName(jResName);
109         jResourceLDAP.setInitialContextFactory(initialContextFactory);
110         jResourceLDAP.setProviderUrl(providerUrl);
111         jResourceLDAP.setSecurityAuthentication(securityAuthentication);
112         jResourceLDAP.setSecurityPrincipal(securityPrincipal);
113         jResourceLDAP.setSecurityCredentials(securityCredentials);
114         jResourceLDAP.setSecurityProtocol(securityProtocol);
115         jResourceLDAP.setLanguage(language);
116         jResourceLDAP.setReferral(referral);
117         jResourceLDAP.setStateFactories(stateFactories);
118         jResourceLDAP.setAuthenticationMode(authenticationMode);
119         jResourceLDAP.setUserPasswordAttribute(userPasswordAttribute);
120         jResourceLDAP.setUserRolesAttribute(userRolesAttribute);
121         jResourceLDAP.setRoleNameAttribute(roleNameAttribute);
122         jResourceLDAP.setBaseDN(baseDN);
123         jResourceLDAP.setUserDN(userDN);
124         jResourceLDAP.setUserSearchFilter(userSearchFilter);
125         jResourceLDAP.setRoleDN(roleDN);
126         jResourceLDAP.setRoleSearchFilter(roleSearchFilter);
127         jResourceLDAP.setAlgorithm(algorithm);
128
129         return jResourceLDAP;
130     }
131
132 }
Popular Tags