Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / jdbc / authentication / JNDIAuthenticationSchemeBase.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/jdbc/authentication/JNDIAuthenticationSchemeBase.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/jdbc/authentication/JNDIAuthenticationSchemeBase.java
new file mode 100644 (file)
index 0000000..24f7870
--- /dev/null
@@ -0,0 +1,128 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.jdbc.authentication.JNDIAuthenticationSchemeBase\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.jdbc.authentication;\r
+\r
+import org.apache.derby.iapi.services.context.ContextService;\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.store.access.AccessFactory;\r
+import org.apache.derby.iapi.store.access.TransactionController;\r
+\r
+import org.apache.derby.iapi.jdbc.AuthenticationService;\r
+import org.apache.derby.authentication.UserAuthenticator;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+import org.apache.derby.iapi.error.ExceptionSeverity;\r
+import org.apache.derby.iapi.reference.MessageId;\r
+import org.apache.derby.iapi.services.i18n.MessageService;\r
+\r
+import java.util.Properties;\r
+import java.util.Enumeration;\r
+import java.sql.SQLException;\r
+\r
+/**\r
+ * This is the base JNDI authentication scheme class.\r
+ *\r
+ * The generic environment JNDI properties for the selected JNDI\r
+ * scheme are retrieved here so that the user can set JNDI properties\r
+ * at the database or system level.\r
+ *\r
+ * @see org.apache.derby.authentication.UserAuthenticator \r
+ *\r
+ */\r
+\r
+public abstract class JNDIAuthenticationSchemeBase implements UserAuthenticator\r
+{\r
+       protected  final JNDIAuthenticationService authenticationService;\r
+       protected String providerURL;\r
+\r
+       private AccessFactory store;\r
+       protected Properties initDirContextEnv;\r
+\r
+       //\r
+       // Constructor\r
+       //\r
+       // We get passed some Users properties if the authentication service\r
+       // could not set them as part of System properties.\r
+       //\r
+       public JNDIAuthenticationSchemeBase(JNDIAuthenticationService as, Properties dbProperties) {\r
+\r
+                       this.authenticationService = as;\r
+\r
+                       //\r
+                       // Let's initialize the Directory Context environment based on\r
+                       // generic JNDI properties. Each JNDI scheme can then add its\r
+                       // specific scheme properties on top of it.\r
+                       //\r
+                       setInitDirContextEnv(dbProperties);\r
+\r
+                       // Specify the ones for this scheme if not already specified\r
+                       this.setJNDIProviderProperties();\r
+       }\r
+\r
+\r
+       /**\r
+        * To be OVERRIDEN by subclasses. This basically tests and sets\r
+        * default/expected JNDI properties for the JNDI provider scheme.\r
+        *\r
+        **/\r
+       abstract protected void setJNDIProviderProperties();\r
+\r
+       /**\r
+        * Construct the initial JNDI directory context environment Properties\r
+        * object. We retrieve JNDI environment properties that the user may\r
+        * have set at the database level.\r
+        *\r
+        **/\r
+       private void setInitDirContextEnv(Properties dbProps) {\r
+\r
+               //\r
+               // We retrieve JNDI properties set at the database level        \r
+               // if any. If dbProps == null, there are obviously no database\r
+               // properties to retrieve.\r
+               //\r
+               initDirContextEnv = new Properties();\r
+                \r
+               if(dbProps != null) {\r
+                       for (Enumeration keys = dbProps.propertyNames(); keys.hasMoreElements(); ) {\r
+\r
+                               String key = (String) keys.nextElement();\r
+\r
+                               if (key.startsWith("java.naming.")) {\r
+                                       initDirContextEnv.put(key, dbProps.getProperty(key));\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       protected static final SQLException getLoginSQLException(Exception e) {\r
+\r
+               String text = MessageService.getTextMessage(SQLState.LOGIN_FAILED, e);\r
+\r
+               SQLException sqle = new SQLException(\r
+                                                       text, SQLState.LOGIN_FAILED, ExceptionSeverity.SESSION_SEVERITY);\r
+\r
+               return sqle;\r
+       }\r
+\r
+}\r