KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.jdbc.authentication.SpecificAuthenticationServiceImpl
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.reference.SQLState;
25 import org.apache.derby.iapi.reference.ClassName;
26
27 import org.apache.derby.iapi.error.StandardException;
28 import org.apache.derby.iapi.jdbc.AuthenticationService;
29 import org.apache.derby.iapi.util.StringUtil;
30 import org.apache.derby.authentication.UserAuthenticator;
31
32 import org.apache.derby.iapi.services.property.PropertyUtil;
33
34 import java.util.Properties JavaDoc;
35
36 /**
37  * This authentication service is a specific/user defined User authentication
38  * level support.
39  * <p>
40  * It calls the specific User authentication scheme defined by the user/
41  * administrator.
42  *
43  * @author Francois
44  */

45 public class SpecificAuthenticationServiceImpl
46     extends AuthenticationServiceBase {
47
48     private String JavaDoc specificAuthenticationScheme;
49
50     //
51
// ModuleControl implementation (overriden)
52
//
53

54     /**
55      * Check if we should activate this authentication service.
56      */

57     public boolean canSupport(Properties JavaDoc properties) {
58
59         //
60
// we check 2 things:
61
// - if derby.connection.requireAuthentication system
62
// property is set to true.
63
// - if derby.authentication.provider is set and is not equal
64
// to LDAP or BUILTIN.
65
//
66
// and in that case we are the authentication service that should
67
// be run.
68
//
69
if (!requireAuthentication(properties))
70             return false;
71
72         specificAuthenticationScheme = PropertyUtil.getPropertyFromSet(
73                     properties,
74                     org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_PARAMETER);
75         if (
76              ((specificAuthenticationScheme != null) &&
77               (specificAuthenticationScheme.length() != 0) &&
78
79               (!((StringUtil.SQLEqualsIgnoreCase(specificAuthenticationScheme,
80                       org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_BUILTIN)) ||
81               (specificAuthenticationScheme.equalsIgnoreCase(
82                       org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_LDAP)) ))))
83             return true;
84         else
85             return false;
86     }
87
88     /**
89      * @see org.apache.derby.iapi.services.monitor.ModuleControl#boot
90      * @exception StandardException upon failure to load/boot the expected
91      * authentication service.
92      */

93     public void boot(boolean create, Properties JavaDoc properties)
94       throws StandardException {
95
96         // We need authentication
97
// setAuthentication(true);
98

99         // we call the super in case there is anything to get initialized.
100
super.boot(create, properties);
101
102         // We must retrieve and load the authentication scheme that we were
103
// told to. The class loader will report an exception if it could not
104
// find the class in the classpath.
105
//
106
// We must then make sure that the ImplementationScheme loaded,
107
// implements the published UserAuthenticator interface we
108
// provide.
109
//
110

111         Throwable JavaDoc t;
112         try {
113
114             Class JavaDoc sasClass = Class.forName(specificAuthenticationScheme);
115             if (!UserAuthenticator.class.isAssignableFrom(sasClass)) {
116                 throw StandardException.newException(SQLState.AUTHENTICATION_NOT_IMPLEMENTED,
117                     specificAuthenticationScheme, "org.apache.derby.authentication.UserAuthenticator");
118             }
119
120             UserAuthenticator aScheme = (UserAuthenticator) sasClass.newInstance();
121
122             // Set ourselves as being ready and loading the proper
123
// authentication scheme for this service
124
//
125
this.setAuthenticationService(aScheme);
126
127             return;
128
129         } catch (ClassNotFoundException JavaDoc cnfe) {
130             t = cnfe;
131         } catch (InstantiationException JavaDoc ie) {
132             t = ie;
133         } catch (IllegalAccessException JavaDoc iae) {
134             t = iae;
135         }
136         throw StandardException.newException(SQLState.AUTHENTICATION_SCHEME_ERROR, t,
137                     specificAuthenticationScheme);
138     }
139 }
140
Popular Tags