2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.core.service.support;
24 import javax.naming.*;
25 import javax.naming.directory.*;
26 import javax.naming.ldap.*;
28 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
29 import org.springframework.stereotype.Service;
32 * This class implements the J2EE service locator pattern. It provides lookup
33 * facilities for various services. Currenttly LDAP (pre-v3) is supported
35 @Service("serviceLocator")
36 public class ServiceLocatorImpl implements ServiceLocator {
38 //private static ServiceLocator locator; // The singleton instance
40 private Context context; // JNDI context (not currently in use)
41 private Context rootContext; // Java env root context (not currently in use)
42 private DirContext dirContext; // LDAP DIR context
43 private InitialLdapContext ldapContext; // LDAP context LDAPv3-style (not currently in use)
46 // cannot directly instantiate
47 public ServiceLocatorImpl() {}
49 /*public static ServiceLocator getLocator() {
51 locator = new ServiceLocator();
55 public Object clone() throws CloneNotSupportedException {
56 throw new CloneNotSupportedException();
60 // Get an LDAP directory context
61 public DirContext getDirContext(String initialContextFactory, String providerUrl, String securityPrincipal) {
63 if (dirContext == null) {
65 Properties properties = new Properties();
66 properties.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
67 properties.put(Context.PROVIDER_URL, providerUrl);
68 properties.put(Context.SECURITY_PRINCIPAL, securityPrincipal);
71 dirContext = new InitialDirContext(properties);
73 catch (NamingException ne) {
74 logger.error(EELFLoggerDelegate.errorLogger, "An error has occurred while creating an Initial Directory Context: " + ne.getMessage());
75 logger.error(EELFLoggerDelegate.errorLogger, "Explanation: " + ne.getExplanation());
82 // Get an LDAP directory context - LDAPv3-style
83 /*public InitialLdapContext getLdapContext() { //throws NamingException {
84 if (ldapContext == null) {
85 Properties properties = new Properties();
86 // @todo - need to parameterize context factoy class and url
87 properties.put(Context.INITIAL_CONTEXT_FACTORY, AttLdap.DIR_INITIAL_CONTEXT_FACTORY);
88 properties.put(Context.PROVIDER_URL, AttLdap.DIR_PROVIDER_URL);
89 properties.put(Context.SECURITY_PRINCIPAL, AttLdap.DIR_SECURITY_PRINCIPAL);
90 Control[] ctrl = null;
92 ldapContext = new InitialLdapContext(properties, ctrl);
94 catch (NamingException ne) {
95 // MJ FIX log exception?
102 /** Logger for this class and subclasses */
103 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ServiceLocatorImpl.class);