Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / jdbc / authentication / SpecificAuthenticationServiceImpl.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/jdbc/authentication/SpecificAuthenticationServiceImpl.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/jdbc/authentication/SpecificAuthenticationServiceImpl.java
new file mode 100644 (file)
index 0000000..24aec3e
--- /dev/null
@@ -0,0 +1,142 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.jdbc.authentication.SpecificAuthenticationServiceImpl\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.reference.SQLState;\r
+import org.apache.derby.iapi.reference.ClassName;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.jdbc.AuthenticationService;\r
+import org.apache.derby.iapi.util.StringUtil;\r
+import org.apache.derby.authentication.UserAuthenticator;\r
+\r
+import org.apache.derby.iapi.services.property.PropertyUtil;\r
+\r
+import java.util.Properties;\r
+\r
+/**\r
+ * This authentication service is a specific/user defined User authentication\r
+ * level support.\r
+ * <p>\r
+ * It calls the specific User authentication scheme defined by the user/\r
+ * administrator.\r
+ *\r
+ */\r
+public class SpecificAuthenticationServiceImpl\r
+       extends AuthenticationServiceBase {\r
+\r
+       private String specificAuthenticationScheme;\r
+\r
+       //\r
+       // ModuleControl implementation (overriden)\r
+       //\r
+\r
+       /**\r
+        *  Check if we should activate this authentication service.\r
+        */\r
+       public boolean canSupport(Properties properties) {\r
+\r
+               //\r
+               // we check 2 things:\r
+               // - if derby.connection.requireAuthentication system\r
+               //   property is set to true.\r
+               // - if derby.authentication.provider is set and is not equal\r
+               //       to LDAP or BUILTIN.\r
+               //\r
+               // and in that case we are the authentication service that should\r
+               // be run.\r
+               //\r
+               if (!requireAuthentication(properties))\r
+                       return false;\r
+\r
+               specificAuthenticationScheme = PropertyUtil.getPropertyFromSet(\r
+                                       properties,\r
+                                       org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_PARAMETER);\r
+               if (\r
+                        ((specificAuthenticationScheme != null) &&\r
+                         (specificAuthenticationScheme.length() != 0) &&\r
+\r
+                         (!((StringUtil.SQLEqualsIgnoreCase(specificAuthenticationScheme,\r
+                                         org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_BUILTIN)) ||\r
+                         (specificAuthenticationScheme.equalsIgnoreCase(\r
+                                         org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_LDAP))  ))))\r
+                       return true;\r
+               else\r
+                       return false;\r
+       }\r
+\r
+       /**\r
+        * @see org.apache.derby.iapi.services.monitor.ModuleControl#boot\r
+        * @exception StandardException upon failure to load/boot the expected\r
+        * authentication service.\r
+        */\r
+       public void boot(boolean create, Properties properties)\r
+         throws StandardException {\r
+\r
+               // We need authentication\r
+               // setAuthentication(true);\r
+\r
+               // we call the super in case there is anything to get initialized.\r
+               super.boot(create, properties);\r
+\r
+               // We must retrieve and load the authentication scheme that we were\r
+               // told to. The class loader will report an exception if it could not\r
+               // find the class in the classpath.\r
+               //\r
+               // We must then make sure that the ImplementationScheme loaded,\r
+               // implements the published UserAuthenticator interface we\r
+               // provide.\r
+               //\r
+\r
+               Throwable t;\r
+               try {\r
+\r
+                       Class sasClass = Class.forName(specificAuthenticationScheme);\r
+                       //Added by Jeff Huang\r
+                       //TODO: FIXIT\r
+                       if (!UserAuthenticator.class.isAssignableFrom(sasClass)) {\r
+                               throw StandardException.newException(SQLState.AUTHENTICATION_NOT_IMPLEMENTED,\r
+                                       specificAuthenticationScheme, "org.apache.derby.authentication.UserAuthenticator");\r
+                       }\r
+\r
+                       UserAuthenticator aScheme = (UserAuthenticator) sasClass.newInstance();\r
+                       //Added by Jeff Huang\r
+                       //TODO: FIXIT\r
+                       \r
+                       // Set ourselves as being ready and loading the proper\r
+                       // authentication scheme for this service\r
+                       //\r
+                       this.setAuthenticationService(aScheme);\r
+\r
+                       return;\r
+\r
+               } catch (ClassNotFoundException cnfe) {\r
+                       t = cnfe;\r
+               } catch (InstantiationException ie) {\r
+                       t = ie;\r
+               } catch (IllegalAccessException iae) {\r
+                       t = iae;\r
+               }\r
+               throw StandardException.newException(SQLState.AUTHENTICATION_SCHEME_ERROR, t,\r
+                                       specificAuthenticationScheme);\r
+       }\r
+}\r