KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > jdbc > authentication > JNDIAuthenticationService


1 /*
2
3    Derby - Class org.apache.derby.impl.jdbc.authentication.JNDIAuthenticationService
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.jdbc.authentication;
23
24 import org.apache.derby.iapi.error.StandardException;
25 import org.apache.derby.iapi.services.property.PropertyUtil;
26
27 import org.apache.derby.iapi.jdbc.AuthenticationService;
28 import org.apache.derby.authentication.UserAuthenticator;
29
30 import org.apache.derby.iapi.util.StringUtil;
31
32 import java.util.Properties JavaDoc;
33
34 /**
35  * This is the JNDI Authentication Service base class.
36  * <p>
37  * It instantiates the JNDI authentication scheme defined by the user/
38  * administrator. Cloudscape supports LDAP JNDI providers.
39  * <p>
40  * The user can configure its own JNDI provider by setting the
41  * system or database property derby.authentication.provider .
42  *
43  * @author Francois
44  */

45
46 public class JNDIAuthenticationService
47     extends AuthenticationServiceBase {
48
49     private String JavaDoc authenticationProvider;
50
51     //
52
// constructor
53
//
54

55     // call the super
56
public JNDIAuthenticationService() {
57         super();
58     }
59
60     //
61
// ModuleControl implementation (overriden)
62
//
63

64     /**
65      * Check if we should activate the JNDI authentication service.
66      */

67     public boolean canSupport(Properties JavaDoc properties) {
68
69         if (!requireAuthentication(properties))
70             return false;
71
72         //
73
// we check 2 things:
74
//
75
// - if derby.connection.requireAuthentication system
76
// property is set to true.
77
// - if derby.authentication.provider is set to one
78
// of the JNDI scheme we support (i.e. LDAP).
79
//
80

81         authenticationProvider = PropertyUtil.getPropertyFromSet(
82                     properties,
83                         org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_PARAMETER);
84
85          if ( (authenticationProvider != null) &&
86                (StringUtil.SQLEqualsIgnoreCase(authenticationProvider,
87                     org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_LDAP)))
88             return true;
89
90         return false;
91     }
92
93     /**
94      * @see org.apache.derby.iapi.services.monitor.ModuleControl#boot
95      * @exception StandardException upon failure to load/boot the expected
96      * authentication service.
97      */

98     public void boot(boolean create, Properties JavaDoc properties)
99       throws StandardException {
100
101         // We need authentication
102
// setAuthentication(true);
103

104         // we call the super in case there is anything to get initialized.
105
super.boot(create, properties);
106
107         // We must retrieve and load the authentication scheme that we were
108
// told to.
109

110         // Set ourselves as being ready and loading the proper
111
// authentication scheme for this service
112
UserAuthenticator aJNDIAuthscheme;
113
114         // we're dealing with LDAP
115
aJNDIAuthscheme = new LDAPAuthenticationSchemeImpl(this, properties);
116         this.setAuthenticationService(aJNDIAuthscheme);
117     }
118 }
119
Popular Tags