001: /*
002:
003: Derby - Class org.apache.derby.impl.jdbc.authentication.JNDIAuthenticationService
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.error.StandardException;
025: import org.apache.derby.iapi.services.property.PropertyUtil;
026:
027: import org.apache.derby.iapi.jdbc.AuthenticationService;
028: import org.apache.derby.authentication.UserAuthenticator;
029:
030: import org.apache.derby.iapi.util.StringUtil;
031:
032: import java.util.Properties;
033:
034: /**
035: * This is the JNDI Authentication Service base class.
036: * <p>
037: * It instantiates the JNDI authentication scheme defined by the user/
038: * administrator. Cloudscape supports LDAP JNDI providers.
039: * <p>
040: * The user can configure its own JNDI provider by setting the
041: * system or database property derby.authentication.provider .
042: *
043: * @author Francois
044: */
045:
046: public class JNDIAuthenticationService extends
047: AuthenticationServiceBase {
048:
049: private String authenticationProvider;
050:
051: //
052: // constructor
053: //
054:
055: // call the super
056: public JNDIAuthenticationService() {
057: super ();
058: }
059:
060: //
061: // ModuleControl implementation (overriden)
062: //
063:
064: /**
065: * Check if we should activate the JNDI authentication service.
066: */
067: public boolean canSupport(Properties properties) {
068:
069: if (!requireAuthentication(properties))
070: return false;
071:
072: //
073: // we check 2 things:
074: //
075: // - if derby.connection.requireAuthentication system
076: // property is set to true.
077: // - if derby.authentication.provider is set to one
078: // of the JNDI scheme we support (i.e. LDAP).
079: //
080:
081: authenticationProvider = PropertyUtil
082: .getPropertyFromSet(
083: properties,
084: org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_PARAMETER);
085:
086: if ((authenticationProvider != null)
087: && (StringUtil
088: .SQLEqualsIgnoreCase(
089: authenticationProvider,
090: org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_LDAP)))
091: return true;
092:
093: return false;
094: }
095:
096: /**
097: * @see org.apache.derby.iapi.services.monitor.ModuleControl#boot
098: * @exception StandardException upon failure to load/boot the expected
099: * authentication service.
100: */
101: public void boot(boolean create, Properties properties)
102: throws StandardException {
103:
104: // We need authentication
105: // setAuthentication(true);
106:
107: // we call the super in case there is anything to get initialized.
108: super .boot(create, properties);
109:
110: // We must retrieve and load the authentication scheme that we were
111: // told to.
112:
113: // Set ourselves as being ready and loading the proper
114: // authentication scheme for this service
115: UserAuthenticator aJNDIAuthscheme;
116:
117: // we're dealing with LDAP
118: aJNDIAuthscheme = new LDAPAuthenticationSchemeImpl(this,
119: properties);
120: this.setAuthenticationService(aJNDIAuthscheme);
121: }
122: }
|