001: /*
002:
003: Derby - Class org.apache.derby.impl.jdbc.authentication.SpecificAuthenticationServiceImpl
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.jdbc.authentication;
023:
024: import org.apache.derby.iapi.reference.SQLState;
025: import org.apache.derby.iapi.reference.ClassName;
026:
027: import org.apache.derby.iapi.error.StandardException;
028: import org.apache.derby.iapi.jdbc.AuthenticationService;
029: import org.apache.derby.iapi.util.StringUtil;
030: import org.apache.derby.authentication.UserAuthenticator;
031:
032: import org.apache.derby.iapi.services.property.PropertyUtil;
033:
034: import java.util.Properties;
035:
036: /**
037: * This authentication service is a specific/user defined User authentication
038: * level support.
039: * <p>
040: * It calls the specific User authentication scheme defined by the user/
041: * administrator.
042: *
043: * @author Francois
044: */
045: public class SpecificAuthenticationServiceImpl extends
046: AuthenticationServiceBase {
047:
048: private String specificAuthenticationScheme;
049:
050: //
051: // ModuleControl implementation (overriden)
052: //
053:
054: /**
055: * Check if we should activate this authentication service.
056: */
057: public boolean canSupport(Properties properties) {
058:
059: //
060: // we check 2 things:
061: // - if derby.connection.requireAuthentication system
062: // property is set to true.
063: // - if derby.authentication.provider is set and is not equal
064: // to LDAP or BUILTIN.
065: //
066: // and in that case we are the authentication service that should
067: // be run.
068: //
069: if (!requireAuthentication(properties))
070: return false;
071:
072: specificAuthenticationScheme = PropertyUtil
073: .getPropertyFromSet(
074: properties,
075: org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_PARAMETER);
076: if (((specificAuthenticationScheme != null)
077: && (specificAuthenticationScheme.length() != 0) &&
078:
079: (!((StringUtil
080: .SQLEqualsIgnoreCase(
081: specificAuthenticationScheme,
082: org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_BUILTIN)) || (specificAuthenticationScheme
083: .equalsIgnoreCase(org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_LDAP))))))
084: return true;
085: else
086: return false;
087: }
088:
089: /**
090: * @see org.apache.derby.iapi.services.monitor.ModuleControl#boot
091: * @exception StandardException upon failure to load/boot the expected
092: * authentication service.
093: */
094: public void boot(boolean create, Properties properties)
095: throws StandardException {
096:
097: // We need authentication
098: // setAuthentication(true);
099:
100: // we call the super in case there is anything to get initialized.
101: super .boot(create, properties);
102:
103: // We must retrieve and load the authentication scheme that we were
104: // told to. The class loader will report an exception if it could not
105: // find the class in the classpath.
106: //
107: // We must then make sure that the ImplementationScheme loaded,
108: // implements the published UserAuthenticator interface we
109: // provide.
110: //
111:
112: Throwable t;
113: try {
114:
115: Class sasClass = Class
116: .forName(specificAuthenticationScheme);
117: if (!UserAuthenticator.class.isAssignableFrom(sasClass)) {
118: throw StandardException
119: .newException(
120: SQLState.AUTHENTICATION_NOT_IMPLEMENTED,
121: specificAuthenticationScheme,
122: "org.apache.derby.authentication.UserAuthenticator");
123: }
124:
125: UserAuthenticator aScheme = (UserAuthenticator) sasClass
126: .newInstance();
127:
128: // Set ourselves as being ready and loading the proper
129: // authentication scheme for this service
130: //
131: this .setAuthenticationService(aScheme);
132:
133: return;
134:
135: } catch (ClassNotFoundException cnfe) {
136: t = cnfe;
137: } catch (InstantiationException ie) {
138: t = ie;
139: } catch (IllegalAccessException iae) {
140: t = iae;
141: }
142: throw StandardException.newException(
143: SQLState.AUTHENTICATION_SCHEME_ERROR, t,
144: specificAuthenticationScheme);
145: }
146: }
|