com.hfg.ldap.LDAP_Config Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.ldap;
import com.hfg.security.CredentialsMgr;
import com.hfg.security.LoginCredentials;
import com.hfg.util.BooleanUtil;
import com.hfg.util.CompareUtil;
import com.hfg.util.StringUtil;
import com.hfg.xml.XMLNode;
import com.hfg.xml.XMLTag;
//------------------------------------------------------------------------------
/**
Container for LDAP settings.
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------
public class LDAP_Config
{
private String mDomain;
private String mDomainCommonName;
private String mServerURL;
private String mCredentialsMgrKey;
private LoginCredentials mPrincipalCredentials;
private String mPrincipalFieldName;
private String mUserContext;
private Boolean mIsActiveDirectory;
private LDAPClient.ReferralHandling mReferralHandling;
private static final String LDAP_CONFIG_TAG = "LDAP_Config";
private static final String DOMAIN_TAG = "Domain";
private static final String CRED_MGR_KEY_TAG = "CredMgrKey";
private static final String USER_CONTEXT_TAG = "UserContext";
private static final String PRINCIPAL_FIELD_NAME_TAG = "PrincipalFieldName";
private static final String REFERRAL_HANDLING_TAG = "ReferralHandling";
private static final String ACTIVE_DIRECTORY_TAG = "ActiveDirectory";
private static final String URL_ATT = "url";
private static final String COMMON_NAME_ATT = "commonName";
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//------------------------------------------------------------------------
public LDAP_Config()
{
}
//------------------------------------------------------------------------
public LDAP_Config(XMLTag inXMLTag)
{
inXMLTag.verifyTagName(LDAP_CONFIG_TAG);
setServerURL(inXMLTag.getAttributeValue(URL_ATT));
XMLNode subtag = inXMLTag.getOptionalSubtagByName(DOMAIN_TAG);
if (subtag != null)
{
setDomain(subtag.getUnescapedContent());
setDomainCommonName(subtag.getAttributeValue(COMMON_NAME_ATT));
}
subtag = inXMLTag.getOptionalSubtagByName(USER_CONTEXT_TAG);
if (subtag != null)
{
setUserContext(subtag.getUnescapedContent());
}
subtag = inXMLTag.getOptionalSubtagByName(PRINCIPAL_FIELD_NAME_TAG);
if (subtag != null)
{
setPrincipalFieldName(subtag.getUnescapedContent());
}
subtag = inXMLTag.getOptionalSubtagByName(REFERRAL_HANDLING_TAG);
if (subtag != null)
{
setReferralHandling(LDAPClient.ReferralHandling.valueOf(subtag.getUnescapedContent()));
}
subtag = inXMLTag.getOptionalSubtagByName(CRED_MGR_KEY_TAG);
if (subtag != null)
{
setCredentialsMgrKey(subtag.getUnescapedContent());
}
subtag = inXMLTag.getOptionalSubtagByName(ACTIVE_DIRECTORY_TAG);
if (subtag != null)
{
setIsActiveDirectory(BooleanUtil.valueOf(subtag.getUnescapedContent()));
}
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//------------------------------------------------------------------------
public LDAP_Config setDomain(String inValue)
{
mDomain = inValue;
return this;
}
//------------------------------------------------------------------------
public String getDomain()
{
return mDomain;
}
//------------------------------------------------------------------------
public LDAP_Config setDomainCommonName(String inValue)
{
mDomainCommonName = inValue;
return this;
}
//------------------------------------------------------------------------
public String getDomainCommonName()
{
return mDomainCommonName;
}
//------------------------------------------------------------------------
public LDAP_Config setServerURL(String inValue)
{
mServerURL = inValue;
return this;
}
//------------------------------------------------------------------------
public String getServerURL()
{
return mServerURL;
}
//------------------------------------------------------------------------
public LDAP_Config setCredentialsMgrKey(String inValue)
{
mCredentialsMgrKey = inValue;
return this;
}
//------------------------------------------------------------------------
public String getCredentialsMgrKey()
{
return mCredentialsMgrKey;
}
//------------------------------------------------------------------------
public LDAP_Config setPrincipalCredentials(LoginCredentials inValue)
{
mPrincipalCredentials = inValue;
return this;
}
//------------------------------------------------------------------------
public LoginCredentials getPrincipalCredentials()
{
if (null == mPrincipalCredentials
&& getCredentialsMgrKey() != null)
{
mPrincipalCredentials = new CredentialsMgr().get(getCredentialsMgrKey());
}
return mPrincipalCredentials;
}
//------------------------------------------------------------------------
public LDAP_Config setPrincipalFieldName(String inValue)
{
mPrincipalFieldName = inValue;
return this;
}
//------------------------------------------------------------------------
public String getPrincipalFieldName()
{
return mPrincipalFieldName;
}
//------------------------------------------------------------------------
public LDAP_Config setUserContext(String inValue)
{
mUserContext = inValue;
return this;
}
//------------------------------------------------------------------------
public String getUserContext()
{
return mUserContext;
}
//------------------------------------------------------------------------
public LDAP_Config setIsActiveDirectory(Boolean inValue)
{
mIsActiveDirectory = inValue;
return this;
}
//------------------------------------------------------------------------
public Boolean isActiveDirectory()
{
return mIsActiveDirectory;
}
//------------------------------------------------------------------------
public LDAP_Config setReferralHandling(LDAPClient.ReferralHandling inValue)
{
mReferralHandling = inValue;
return this;
}
//------------------------------------------------------------------------
public LDAPClient.ReferralHandling getReferralHandling()
{
return mReferralHandling;
}
//--------------------------------------------------------------------------
@Override
public boolean equals(Object inObj2)
{
return (inObj2 != null
&& inObj2 instanceof LDAP_Config
&& 0 == CompareUtil.compare(getServerURL(), ((LDAP_Config) inObj2).getServerURL()));
}
//--------------------------------------------------------------------------
public XMLNode toXMLTag()
{
XMLNode node = new XMLTag(LDAP_CONFIG_TAG);
if (getServerURL() != null)
{
node.setAttribute(URL_ATT, getServerURL());
}
if (StringUtil.isSet(getDomain()))
{
XMLNode domainTag = new XMLTag(DOMAIN_TAG);
domainTag.setContent(getDomain());
if (getDomainCommonName() != null)
{
domainTag.setAttribute(COMMON_NAME_ATT, getDomainCommonName());
}
node.addSubtag(domainTag);
}
if (StringUtil.isSet(getUserContext()))
{
XMLNode subtag = new XMLTag(USER_CONTEXT_TAG);
subtag.setContent(getUserContext());
node.addSubtag(subtag);
}
if (StringUtil.isSet(getPrincipalFieldName()))
{
XMLNode subtag = new XMLTag(PRINCIPAL_FIELD_NAME_TAG);
subtag.setContent(getPrincipalFieldName());
node.addSubtag(subtag);
}
if (getReferralHandling() != null)
{
XMLNode subtag = new XMLTag(REFERRAL_HANDLING_TAG);
subtag.setContent(getReferralHandling().name());
node.addSubtag(subtag);
}
// Note that we don't serialize the credentials themselves
if (getCredentialsMgrKey() != null)
{
XMLNode subtag = new XMLTag(CRED_MGR_KEY_TAG);
subtag.setContent(getCredentialsMgrKey());
node.addSubtag(subtag);
}
if (isActiveDirectory() != null)
{
XMLNode subtag = new XMLTag(ACTIVE_DIRECTORY_TAG);
subtag.setContent(isActiveDirectory() ? "true" : "false");
node.addSubtag(subtag);
}
return node;
}
}