📄 ldaputil.java
字号:
* @return Text error message.
*/
public static String getLDAPErrorMessage(LDAPException le)
{
return MessageUtil.formatMessage("MSG_LDAP_ERROR",
MessageUtil.formatMessage("MSG_ERROR_LDAP_" +
le.getLDAPResultCode()));
}
/**
* Gets a new connection for user.
* @param userContext user context
*
* @return new connection (either applicative connection or user connection)
*/
public static LDAPConnection getUnboundConnection(UserContext userContext)
{
LDAPConnection currentLd = new LDAPConnection();
try
{
JBLdapConfig ldapConfig = userContext.getLdapConfig();
currentLd.connect(ldapConfig.getHost(), ldapConfig.getLdapPort());
currentLd.setOption(LDAPConnection.PROTOCOL_VERSION, new Integer("3"));
currentLd.setOption(LDAPConnection.BATCHSIZE, new Integer(0));
//DW/2574/BeginPatch
currentLd.setOption(LDAPConnection.REFERRALS, new Boolean(true));
LDAPFaareRebind rebind = null;
if (ldapConfig.isAppliConnectionType())
{
rebind = new LDAPFaareRebind(ldapConfig);
}
else
{
rebind = new LDAPFaareRebind(userContext);
}
currentLd.setOption(LDAPConnection.REFERRALS_REBIND_PROC, rebind);
//DW/2574/EndPatch
if (ldapConfig.getSizeLimit() != null)
{
currentLd.setOption(LDAPConnection.SIZELIMIT,
new Integer(ldapConfig.getSizeLimit()));
}
if (ldapConfig.getTimeLimit() != null)
{
currentLd.setOption(LDAPConnection.TIMELIMIT,
new Integer(ldapConfig.getTimeLimit()));
}
}
catch (Exception le)
{
_logger.error(MessageUtil.formatMessage("MSG_LDAP_ERROR",
le.getMessage()));
throw new RuntimeException("getConnection error");
}
return currentLd;
}
/**
* Gets applicative connection.
*
* @param userContext user context
*
* @return LDAP connection
*/
public static LDAPConnection getAppliConnection(UserContext userContext)
{
try
{
if ((appliLd == null) || !appliLd.isConnected())
{
_logger.info("New applicative connection");
JBLdapConfig ldapConfig = userContext.getLdapConfig();
appliLd = new LDAPConnection();
appliLd.connect(3, ldapConfig.getHost(),
ldapConfig.getLdapPort(), ldapConfig.getAppliDN(),
ldapConfig.getAppliPwd());
appliLd.setOption(LDAPConnection.BATCHSIZE, new Integer(0));
//DW/2574/BeginPatch
appliLd.setOption(LDAPConnection.REFERRALS, new Boolean(true));
LDAPFaareRebind rebind = new LDAPFaareRebind(ldapConfig);
appliLd.setOption(LDAPConnection.REFERRALS_REBIND_PROC, rebind);
//DW/2574/EndPatch
if (ldapConfig.getSizeLimit() != null)
{
appliLd.setOption(LDAPConnection.SIZELIMIT,
new Integer(ldapConfig.getSizeLimit()));
}
if (ldapConfig.getTimeLimit() != null)
{
appliLd.setOption(LDAPConnection.TIMELIMIT,
new Integer(ldapConfig.getTimeLimit()));
}
}
else
{
return appliLd;
}
}
catch (LDAPException le)
{
_logger.error(MessageUtil.formatMessage("MSG_LDAP_ERROR",
LdapUtil.getLDAPErrorMessage(le)));
throw new RuntimeException("getConnection error");
}
return appliLd;
}
/**
* Gets LDAP attribute name corresponding to a business bean attribute,
* as defined in faare_mapping.xml.
* @param jbAttName Attribute name
* @param jbName Object name
* @return LDAP attribute name
* @throws PersistenceException in case of null or unknown argument
*/
public static String convertJBAttrNameToLdapAttName(String jbAttName,
String jbName) throws PersistenceException
{
if (jbAttName == null)
{
throw new PersistenceException(MessageUtil.formatMessage(
"MSG_ARGUMENT_NULL", "jbAttName",
"convertJBAttrNameToLdapAttName", "PersistenceLDAP"));
}
if (jbName == null)
{
throw new PersistenceException(MessageUtil.formatMessage(
"MSG_ARGUMENT_NULL", "jbName",
"convertJBAttrNameToLdapAttName", "PersistenceLDAP"));
}
try
{
// fail-fast principle, just check if the class exist !
Class.forName(jbName);
JBClassDescriptor classDesc = PropertiesManager.getInstance()
.getPersistenceDescriptionMap()
.getClassDescriptor(jbName);
return classDesc.getSourceAttributeName(jbAttName);
}
catch (java.lang.ClassNotFoundException cnfe)
{
throw new PersistenceException(MessageUtil.formatMessage(
"MSG_MAPPING_CLASS_NOT_FOUND", jbName), cnfe);
}
}
/**
* Gets list of LDAP object classes corresponding to a business object,
* as defined in faare_mapping.xml.
* @param jbName object name
* @return Set of object classes
* @throws PersistenceException in case of null argument
*/
public static Set convertJBObjectNameToLdapObjectName(String jbName)
throws PersistenceException
{
if (jbName == null)
{
throw new PersistenceException(MessageUtil.formatMessage(
"MSG_ARGUMENT_NULL", "jbName",
"convertJBObjectNameToLdapObjectName", "PersistenceLDAP"));
}
JBClassDescriptor classDesc = PropertiesManager.getInstance()
.getPersistenceDescriptionMap()
.getClassDescriptor(jbName);
return classDesc.getMapTo().getLdapocSet();
}
/**
* Gets LDAP attribute corresponding to business bean attribute.
*
* @param fieldDesc business bean attribute descriptor.
* @param jbTop business bean object
*
* @return Filled LDAP attribute.
*
* @throws PersistenceException in case of null argument
*/
public static LDAPAttribute getLDAPAttrFromFieldDesc(
JBFieldDescriptor fieldDesc, JBTop jbTop) throws PersistenceException
{
if (fieldDesc == null)
{
throw new PersistenceException(MessageUtil.formatMessage(
"MSG_ARGUMENT_NULL", "fieldDesc",
"getLDAPAttrFromFieldDesc", "PersistenceLDAP"));
}
if (jbTop == null)
{
throw new PersistenceException(MessageUtil.formatMessage(
"MSG_ARGUMENT_NULL", "jbTop", "getLDAPAttrFromFieldDesc",
"PersistenceLDAP"));
}
_logger.debug("GETLDAPATTRFROMFIELDDESC pour : " + fieldDesc.getName());
LDAPAttribute ldapAttr = null;
/*D閠ection de l'attribut "collection" dans le fichier de mapping*/
boolean isCollection = fieldDesc.isACollection();
_logger.debug("GETLDAPATTRFROMFIELDDESC isCollection : " +
isCollection);
LazyCollection lazyCollection;
/*Premier type de lazy loadind*/
LazyJBTopCollection dwrc;
/*Deuxi鑝e type de lazy loading*/
LazyStringCollection rc;
Object o = null;
try
{
o = PropertyUtils.getProperty(jbTop, fieldDesc.getName());
_logger.debug("GETLDAPATTRFROMFIELDDESC o : " + o);
}
catch (Exception ex)
{
ex.printStackTrace();
_logger.error(ex.getMessage());
}
if (o != null)
{
if (!isCollection)
{ /*L'attribut 閠udi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -