KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.jdbc.authentication.JNDIAuthenticationSchemeBase
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.services.context.ContextService;
25 import org.apache.derby.iapi.error.StandardException;
26
27 import org.apache.derby.iapi.store.access.AccessFactory;
28 import org.apache.derby.iapi.store.access.TransactionController;
29
30 import org.apache.derby.iapi.jdbc.AuthenticationService;
31 import org.apache.derby.authentication.UserAuthenticator;
32
33 import org.apache.derby.iapi.services.sanity.SanityManager;
34 import org.apache.derby.iapi.reference.SQLState;
35 import org.apache.derby.iapi.error.ExceptionSeverity;
36 import org.apache.derby.iapi.reference.MessageId;
37 import org.apache.derby.iapi.services.i18n.MessageService;
38
39 import java.util.Properties JavaDoc;
40 import java.util.Enumeration JavaDoc;
41 import java.sql.SQLException JavaDoc;
42
43 /**
44  * This is the base JNDI authentication scheme class.
45  *
46  * The generic environment JNDI properties for the selected JNDI
47  * scheme are retrieved here so that the user can set JNDI properties
48  * at the database or system level.
49  *
50  * @see org.apache.derby.authentication.UserAuthenticator
51  *
52  */

53
54 public abstract class JNDIAuthenticationSchemeBase implements UserAuthenticator
55 {
56     protected final JNDIAuthenticationService authenticationService;
57     protected String JavaDoc providerURL;
58
59     private AccessFactory store;
60     protected Properties JavaDoc initDirContextEnv;
61
62     //
63
// Constructor
64
//
65
// We get passed some Users properties if the authentication service
66
// could not set them as part of System properties.
67
//
68
public JNDIAuthenticationSchemeBase(JNDIAuthenticationService as, Properties JavaDoc dbProperties) {
69
70             this.authenticationService = as;
71
72             //
73
// Let's initialize the Directory Context environment based on
74
// generic JNDI properties. Each JNDI scheme can then add its
75
// specific scheme properties on top of it.
76
//
77
setInitDirContextEnv(dbProperties);
78
79             // Specify the ones for this scheme if not already specified
80
this.setJNDIProviderProperties();
81     }
82
83
84     /**
85      * To be OVERRIDEN by subclasses. This basically tests and sets
86      * default/expected JNDI properties for the JNDI provider scheme.
87      *
88      **/

89     abstract protected void setJNDIProviderProperties();
90
91     /**
92      * Construct the initial JNDI directory context environment Properties
93      * object. We retrieve JNDI environment properties that the user may
94      * have set at the database level.
95      *
96      **/

97     private void setInitDirContextEnv(Properties JavaDoc dbProps) {
98
99         //
100
// We retrieve JNDI properties set at the database level
101
// if any. If dbProps == null, there are obviously no database
102
// properties to retrieve.
103
//
104
initDirContextEnv = new Properties JavaDoc();
105                 
106         if(dbProps != null) {
107             for (Enumeration JavaDoc keys = dbProps.propertyNames(); keys.hasMoreElements(); ) {
108
109                 String JavaDoc key = (String JavaDoc) keys.nextElement();
110
111                 if (key.startsWith("java.naming.")) {
112                     initDirContextEnv.put(key, dbProps.getProperty(key));
113                 }
114             }
115         }
116     }
117     
118     protected static final SQLException JavaDoc getLoginSQLException(Exception JavaDoc e) {
119
120         String JavaDoc text = MessageService.getTextMessage(SQLState.LOGIN_FAILED, e);
121
122         SQLException JavaDoc sqle = new SQLException JavaDoc(
123                             text, SQLState.LOGIN_FAILED, ExceptionSeverity.SESSION_SEVERITY);
124
125         return sqle;
126     }
127
128 }
129
Popular Tags