ServiceBase.java revision e6c3a72a023407f5d1fface64356e1cc81f1af31
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: ServiceBase.java,v 1.2 2009/01/28 05:34:58 ww203982 Exp $
*
* Portions Copyrighted 2012-2016 ForgeRock AS.
*/
/**
* This is the base class for Server related functionality.
* Any class that needs server specific methods can use this base
* class.
*/
/**
* Helper method to return Admin token when the configuration
* properties is initialized.
*
* @return Admin Token.
*/
protected static SSOToken getAdminSSOToken() {
if (adminToken == null) {
}
return adminToken;
}
/**
* Helper method to load the config using the boot file
*
* @param bootPath filename location of the boot file
* @return properties of the configured server.
*/
throws Exception {
if (adminToken != null) {
try {
adminToken = null;
"ServiceBase.loadConfigFromBootfile : " +
"Exception in clearing cache", sre);
}
}
}
return cProp;
}
/**
* Helper method to retrive the boot servers from the boot file
*
* @param path filename location of the boot file
* @return map of the boot directory servers
*/
throws IOException, UnsupportedEncodingException {
return getBootfileContent(path);
}
/**
* Helper method to retrive the boot instance from the boot list
*
* @param bServers Map of available boot servers
* @return <code>true</code> if server is bootable
*/
protected boolean isServerBootable(
) {
boolean match = false;
if (isDSRunning(dsInstance)) {
if (isValidSuffix(dsInstance)) {
match = true;
}
}
}
return match;
}
throws IOException, UnsupportedEncodingException {
dsprotocol = "ldaps";
} else
dsprotocol = "ldap";
}
}
}
return bootList;
}
throws UnsupportedEncodingException {
while (st.hasMoreTokens()) {
}
return map;
}
/**
* Method to check if the server instance is running
*
* @param sName server instance name
* @return <code>true</code> if server instance is running
*/
boolean isSvrRunning = false;
try {
);
uc.getInputStream()));
isSvrRunning = true;
} catch (MalformedURLException mfe) {
"ServiceBase.isServerRunning : " +
"Exception in getting server URL", mfe);
} catch (IOException ioe) {
"ServiceBase.isServerRunning : " +
"Exception in connecting to server URL", ioe);
}
return isSvrRunning;
}
/**
* Method to check if the server instance is running
*
* @param url server instance URL
* @return <code>true</code> if server instance is running
*/
boolean isSvrRunning = false;
try {
uc.getInputStream()));
isSvrRunning = true;
} catch (MalformedURLException mfe) {
"ServiceBase.isServerRunning : " +
"Exception in getting server URL", mfe);
} catch (IOException ioe) {
"ServiceBase.isServerRunning : " +
"Exception in connecting to server URL", ioe);
}
return isSvrRunning;
}
/**
* Method to connect to server instance
*
* @param svrName server instance name
* @return <code>true</code> if server instance can be connected
*/
boolean connect = false;
try {
}
svrConn.getInputStream()));
connect = true;
"ServiceBase.connectToServer : ", ssle);
throw ssle;
"ServiceBase.connectToServer : ", ex);
throw ex;
}
return connect;
}
/**
* Helper method to construct the URL from properties.
*
* @param prop properties of the server instance
* @return string representing the URL of the instance
*/
return propURL;
}
/**
* Helper method to construct the URL from properties.
*
* @param mProp map of server instance properties
* @return string representing the URL of the instance
*/
return propURL;
}
/**
* Read the properties file and initialize the
* Map with the properties.
*
* @param pName name of resource bundle to load the properties
* @return map of properties loaded from a resource bundle
*/
}
return propMap;
}
/**
* Read the properties file and initialize the
* Map with the properties.
*
* @param prop object containing properties
* @return map of properties loaded from properties object
*/
}
return propMap;
}
/**
* Method to check if the host name is valid
*
* @param hName name of the host
* @return <code>true</code> if host name can be resolved
*/
boolean valid = false;
try {
valid = true;
"ServiceBase.isValidHost: " + e);
}
return valid;
}
/**
* Method to check if the port is valid
*
* @param port Port of the host
* @return <code>true</code> if host name can be resolved
*/
boolean valid = false;
try {
valid = true;
} catch (NumberFormatException nfe) {
"ServiceBase.isValidPort: " + nfe);
}
return valid;
}
/**
* Helper method to clear the cache
*/
boolean valid = true;
try {
svcMgr.clearCache();
"ServiceBase.doRefresh: " + sms);
valid = false;
}
return valid;
}
/**
* Returns a LDAP connection to the directory host.
*
* @param dsHostName name of the sever where DS is installed
* @param dsPort port at which the directory server is listening
* @param dsProtocol protocol used by directory server
* @param dsManager admin user name for directory server
* @param dsAdminPwd admin password used by admin user name
* @return LDAP connection
*/
protected static Connection getLDAPConnection(String dsHostName, int dsPort, String dsProtocol, String dsManager,
String dsAdminPwd) {
try {
// All connections will use authentication
}
return factory.getConnection();
return null;
}
}
/**
* Returns a LDAP connection to the directory host.
*
* @param paramMap Map containing directory specific information
* @return LDAP connection
*/
}
/**
* Check if Directory Server has the suffix.
*
* @return <code>true</code> if specified suffix exists.
*/
try (ConnectionEntryReader reader = ld.search(LDAPRequests.newSearchRequest(suffix, SearchScope.BASE_OBJECT,
} catch (LdapException e) {
return false;
}
}
/**
* Check if Directory Server is running.
*
* @return <code>true</code> if directory is running.
*/
protected static boolean isDSServerUp(String dsHostName, int dsPort, String dsProtocol, String dsManager,
String dsAdminPwd) {
return true;
}
}
return false;
}
/**
* Check if config Directory Server is running.
*
* @return <code>true</code> if config directory is running.
*/
boolean dsRunning = false;
"ServiceBase.isDSRunning : " +
"Cannot connect to Directory Server :" +
} else {
dsRunning = true;
}
return dsRunning;
}
/**
* Check if Directory Server has the given suffix.
*
* @return <code>true</code> if suffix is valid.
*/
boolean validSuffix = false;
validSuffix = true;
} else {
"ServiceBase.isValidateSuffix : " +
"Cannot connect to Directory Server :" +
" with suffix" + DS_BASE_DN);
}
}
return validSuffix;
}
/**
* Validates the directory server port and returns as an int value.
*
* @return port of directory server.
*/
int port = 0;
try {
} catch (NumberFormatException e) {
"ServiceBase.getPort: " +
"Exception in getting port information", e);
}
return port;
}
}