use of org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException in project directory-ldap-api by apache.
the class WrappedPartialResultException method wrap.
/**
* Wraps a LDAP exception into a NaingException
*
* @param t The original exception
* @throws NamingException The wrapping JNDI exception
*/
public static void wrap(Throwable t) throws NamingException {
if (t instanceof NamingException) {
throw (NamingException) t;
}
NamingException ne;
if ((t instanceof LdapAffectMultipleDsaException) || (t instanceof LdapAliasDereferencingException) || (t instanceof LdapLoopDetectedException) || (t instanceof LdapAliasException) || (t instanceof LdapOperationErrorException) || (t instanceof LdapOtherException)) {
ne = new NamingException(t.getLocalizedMessage());
} else if (t instanceof LdapAttributeInUseException) {
ne = new AttributeInUseException(t.getLocalizedMessage());
} else if (t instanceof LdapAuthenticationException) {
ne = new AuthenticationException(t.getLocalizedMessage());
} else if (t instanceof LdapAuthenticationNotSupportedException) {
ne = new AuthenticationNotSupportedException(t.getLocalizedMessage());
} else if (t instanceof LdapContextNotEmptyException) {
ne = new ContextNotEmptyException(t.getLocalizedMessage());
} else if (t instanceof LdapEntryAlreadyExistsException) {
ne = new NameAlreadyBoundException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidAttributeTypeException) {
ne = new InvalidAttributeIdentifierException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidAttributeValueException) {
ne = new InvalidAttributeValueException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidDnException) {
ne = new InvalidNameException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidSearchFilterException) {
ne = new InvalidSearchFilterException(t.getLocalizedMessage());
} else if (t instanceof LdapNoPermissionException) {
ne = new NoPermissionException(t.getLocalizedMessage());
} else if (t instanceof LdapNoSuchAttributeException) {
ne = new NoSuchAttributeException(t.getLocalizedMessage());
} else if (t instanceof LdapNoSuchObjectException) {
ne = new NameNotFoundException(t.getLocalizedMessage());
} else if (t instanceof LdapProtocolErrorException) {
ne = new CommunicationException(t.getLocalizedMessage());
} else if (t instanceof LdapReferralException) {
ne = new WrappedReferralException((LdapReferralException) t);
} else if (t instanceof LdapPartialResultException) {
ne = new WrappedPartialResultException((LdapPartialResultException) t);
} else if (t instanceof LdapSchemaViolationException) {
ne = new SchemaViolationException(t.getLocalizedMessage());
} else if (t instanceof LdapServiceUnavailableException) {
ne = new ServiceUnavailableException(t.getLocalizedMessage());
} else if (t instanceof LdapTimeLimitExceededException) {
ne = new TimeLimitExceededException(t.getLocalizedMessage());
} else if (t instanceof LdapUnwillingToPerformException) {
ne = new OperationNotSupportedException(t.getLocalizedMessage());
} else {
ne = new NamingException(t.getLocalizedMessage());
}
ne.setRootCause(t);
throw ne;
}
use of org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException in project directory-fortress-core by apache.
the class ConfigDAO method create.
/**
* @param name
* @param props
* @return
* @throws org.apache.directory.fortress.core.CreateException
*/
Properties create(String name, Properties props) throws CreateException {
LdapConnection ld = null;
String dn = getDn(name);
LOG.info("create dn [{}]", dn);
try {
Entry myEntry = new DefaultEntry(dn);
myEntry.add(SchemaConstants.OBJECT_CLASS_AT, CONFIG_OBJ_CLASS);
ld = getAdminConnection();
myEntry.add(SchemaConstants.CN_AT, name);
loadProperties(props, myEntry, GlobalIds.PROPS);
add(ld, myEntry);
} catch (LdapEntryAlreadyExistsException e) {
String warning = "create config dn [" + dn + "] caught LdapEntryAlreadyExistsException=" + e.getMessage() + " msg=" + e.getMessage();
throw new CreateException(GlobalErrIds.FT_CONFIG_ALREADY_EXISTS, warning, e);
} catch (LdapException e) {
String error;
error = "create config dn [" + dn + "] caught LDAPException=" + e.getMessage();
LOG.error(error, e);
throw new CreateException(GlobalErrIds.FT_CONFIG_CREATE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return props;
}
use of org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException in project directory-fortress-core by apache.
the class UserDAO method create.
/**
* Add new user entity to LDAP
*
* @param entity
* @return
* @throws CreateException
*/
User create(User entity) throws CreateException {
LdapConnection ld = null;
try {
entity.setInternalId();
String dn = getDn(entity.getUserId(), entity.getContextId());
Entry myEntry = new DefaultEntry(dn);
myEntry.add(SchemaConstants.OBJECT_CLASS_AT, getUserObjectClass());
// myEntry.add( SchemaConstants.OBJECT_CLASS_AT, USER_OBJ_CLASS );
myEntry.add(GlobalIds.FT_IID, entity.getInternalId());
myEntry.add(SchemaConstants.UID_AT, entity.getUserId());
// CN is required on inetOrgPerson object class, if caller did not set, use the userId:
if (StringUtils.isEmpty(entity.getCn())) {
entity.setCn(entity.getUserId());
}
myEntry.add(SchemaConstants.CN_AT, entity.getCn());
// SN is required on inetOrgPerson object class, if caller did not set, use the userId:
if (StringUtils.isEmpty(entity.getSn())) {
entity.setSn(entity.getUserId());
}
myEntry.add(SchemaConstants.SN_AT, entity.getSn());
if (StringUtils.isNotEmpty(entity.getPassword())) {
myEntry.add(SchemaConstants.USER_PASSWORD_AT, entity.getPassword());
} else if (!Config.getInstance().getBoolean(GlobalIds.USER_CREATION_PASSWORD_FIELD, false)) {
myEntry.add(SchemaConstants.USER_PASSWORD_AT, new String());
}
myEntry.add(SchemaConstants.DISPLAY_NAME_AT, entity.getCn());
if (StringUtils.isNotEmpty(entity.getTitle())) {
myEntry.add(SchemaConstants.TITLE_AT, entity.getTitle());
}
if (StringUtils.isNotEmpty(entity.getEmployeeType())) {
myEntry.add(EMPLOYEE_TYPE, entity.getEmployeeType());
}
// These are multi-valued attributes, use the util function to load.
// These items are optional. The utility function will return quietly if item list is empty:
loadAttrs(entity.getPhones(), myEntry, SchemaConstants.TELEPHONE_NUMBER_AT);
loadAttrs(entity.getMobiles(), myEntry, MOBILE);
loadAttrs(entity.getEmails(), myEntry, SchemaConstants.MAIL_AT);
// The following attributes are optional:
if (entity.isSystem() != null) {
myEntry.add(SYSTEM_USER, entity.isSystem().toString().toUpperCase());
}
// If password policy is set and either openldap or apacheds in use:
if ((Config.getInstance().isOpenldap() || Config.getInstance().isApacheds()) && StringUtils.isNotEmpty(entity.getPwPolicy())) {
myEntry.add(OPENLDAP_POLICY_SUBENTRY, PolicyDAO.getPolicyDn(entity));
}
if (StringUtils.isNotEmpty(entity.getOu())) {
myEntry.add(SchemaConstants.OU_AT, entity.getOu());
}
if (StringUtils.isNotEmpty(entity.getDescription())) {
myEntry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
}
// props are optional as well:
// Add "initial" property here.
entity.addProperty("initAttrArrays", "");
loadProperties(entity.getProperties(), myEntry, GlobalIds.PROPS);
// map the userid to the name field in constraint:
entity.setName(entity.getUserId());
myEntry.add(GlobalIds.CONSTRAINT, ConstraintUtil.setConstraint(entity));
loadAddress(entity.getAddress(), myEntry);
if (ArrayUtils.isNotEmpty(entity.getJpegPhoto())) {
myEntry.add(JPEGPHOTO, entity.getJpegPhoto());
}
ld = getAdminConnection();
add(ld, myEntry, entity);
entity.setDn(dn);
} catch (LdapEntryAlreadyExistsException e) {
String error = "create userId [" + entity.getUserId() + "] failed, already exists in directory";
throw new CreateException(GlobalErrIds.USER_ADD_FAILED_ALREADY_EXISTS, error, e);
} catch (LdapException e) {
String error = "create userId [" + entity.getUserId() + "] caught LDAPException=" + e.getMessage();
throw new CreateException(GlobalErrIds.USER_ADD_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
Aggregations