use of org.forgerock.opendj.ldap.LdapException in project OpenAM by OpenRock.
the class SMSRepositoryMig method migrate.
private static void migrate(ConnectionFactory factory, String host, int port, String binddn, String pw, String basedn, String flatfiledir) throws Exception {
// check args
if (port < 0 || binddn == null || binddn.length() == 0 || pw == null || pw.length() == 0 || basedn == null || basedn.length() == 0 || flatfiledir == null || flatfiledir.length() == 0) {
throw new IllegalArgumentException("SMSRepositoryMig: One or more invalid " + "arguments in constructor");
}
// Create the SMSFlatFileObject
SMSFlatFileObject smsFlatFileObject = new SMSFlatFileObject();
try (Connection conn = factory.getConnection()) {
// Loop through LDAP attributes, create SMS object for each.
ConnectionEntryReader res = conn.search(LDAPRequests.newSearchRequest("ou=services," + basedn, SearchScope.BASE_OBJECT, "(objectclass=*)", "*"));
while (res.hasNext()) {
if (res.isReference()) {
//ignore
res.readReference();
System.out.println("ERROR: LDAP Referral not supported.");
System.out.println("LDAPReferralException received");
} else {
SearchResultEntry entry;
try {
entry = res.readEntry();
createSMSEntry(smsFlatFileObject, entry.getName().toString(), entry.getAllAttributes());
} catch (LdapException e) {
System.out.println("ERROR: LDAP Exception encountered: " + e.toString());
e.printStackTrace();
}
}
}
}
}
use of org.forgerock.opendj.ldap.LdapException in project OpenAM by OpenRock.
the class SearchResultIterator method hasNext.
public boolean hasNext() {
try {
if (results.hasNext()) {
if (current == null) {
if (results.isReference()) {
debug.warning("SearchResultIterator: ignoring reference: {}", results.readReference());
return hasNext();
}
SearchResultEntry entry = results.readEntry();
String dn = entry.getName().toString();
if (hasExcludeDNs && excludeDNs.contains(dn)) {
return hasNext();
}
current = new SMSDataEntry(dn, SMSUtils.convertEntryToAttributesMap(entry));
}
return true;
}
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (errorCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
debug.message("SearchResultIterator: size limit exceeded");
} else {
debug.error("SearchResultIterator.hasNext", e);
}
} catch (SearchResultReferenceIOException e) {
debug.error("SearchResultIterator.hasNext: reference should be already handled", e);
return hasNext();
}
conn.close();
return false;
}
use of org.forgerock.opendj.ldap.LdapException in project OpenAM by OpenRock.
the class COSManager method removeDirectCOSAssignment.
/**
* Removes a Direct COS assignment from a target persistent object. The COS
* target persistent object could be a user, group, organization,
* organizationalunit, etc. The COS target object must be persistent before
* this method can be used.
*
* @param pObject
* The COS target persistent object.
* @param cosDef
* A COS definition.
* @param sMgr
* A SchemaManager object, which is used to determine object
* classes for attributes.
*
* @throws UMSException
* The exception thrown if any of the following occur: o an
* exception occurs determining the object class for the COS
* specifier. o an exception occurs determining the object class
* for the COS attributes. o there is an exception thrown rom
* the data layer.
*/
private void removeDirectCOSAssignment(PersistentObject pObject, DirectCOSDefinition cosDef, COSTemplate cosTemplate, SchemaManager sMgr) throws UMSException {
ArrayList aList;
AttrSet attrSet = new AttrSet();
try {
//
if (pObject.getAttribute(cosDef.getCOSSpecifier()) != null)
attrSet.add(new Attr(cosDef.getCOSSpecifier(), cosTemplate.getName()));
// Get cosSpecifier object class - should only be one.
// Include the cosSpecifier object class in the attribute
// set for removal (only if itt exists).
//
aList = (ArrayList) sMgr.getObjectClasses(cosDef.getCOSSpecifier());
String cosSpecObjectClass = (String) aList.get(0);
if (objectClassExists(cosSpecObjectClass, pObject)) {
attrSet.add(new Attr("objectclass", cosSpecObjectClass));
}
// Get the cos attributes from the definition (ex. mailquota).
// For each of the attributes, get the objectclass. Include the
// object classes in the attribute set for removal (if they exist).
//
String[] cosAttributes = cosDef.getCOSAttributes();
String cosAttribute = null;
for (int i = 0; i < cosAttributes.length; i++) {
// Only get the attribute - not the qualifier
//
StringTokenizer st = new StringTokenizer(cosAttributes[i]);
cosAttribute = st.nextToken();
aList = (ArrayList) sMgr.getObjectClasses(cosAttribute);
String cosAttributeObjectClass = (String) aList.get(0);
if (objectClassExists(cosAttributeObjectClass, pObject)) {
attrSet.add(new Attr("objectclass", cosAttributeObjectClass));
}
}
if (attrSet.size() > 0) {
pObject.modify(toModifications(ModificationType.DELETE, attrSet));
pObject.save();
}
} catch (UMSException e) {
LdapException le = (LdapException) e.getRootCause();
// Ignore anything that is not a COS generated attribute's object class
if (!ResultCode.OBJECTCLASS_VIOLATION.equals(le.getResult().getResultCode())) {
throw e;
}
}
}
use of org.forgerock.opendj.ldap.LdapException in project OpenAM by OpenRock.
the class ImportServiceConfiguration method getLDAPConnection.
private Connection getLDAPConnection() throws CLIException {
IOutput outputWriter = getOutputWriter();
if (isVerbose()) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-connecting-to-ds"));
}
try {
Connection conn;
DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
ServerGroup sg = dsCfg.getServerGroup("sms");
if (sg != null) {
conn = dsCfg.getNewConnectionFactory("sms", LDAPUser.Type.AUTH_ADMIN).getConnection();
} else {
throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
}
if (isVerbose()) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-connected-to-ds"));
}
return conn;
} catch (LDAPServiceException | LdapException e) {
throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
}
}
use of org.forgerock.opendj.ldap.LdapException in project OpenAM by OpenRock.
the class ImportServiceConfiguration method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
String xmlFile = getStringOptionValue(IArgument.XML_FILE);
String encryptSecret = getStringOptionValue(IArgument.ENCRYPT_SECRET);
try {
encryptSecret = CLIUtil.getFileContent(getCommandManager(), encryptSecret).trim();
} catch (CLIException clie) {
//There is no encryptSecret file
}
validateEncryptSecret(xmlFile, encryptSecret);
// disable notification
SystemProperties.initializeProperties(Constants.SMS_ENABLE_DB_NOTIFICATION, "true");
SystemProperties.initializeProperties("com.sun.am.event.connection.disable.list", "sm,aci,um");
// disable error debug messsage
SystemProperties.initializeProperties(Constants.SYS_PROPERTY_INSTALL_TIME, "true");
IOutput outputWriter = getOutputWriter();
try (Connection ldConnection = getLDAPConnection()) {
InitializeSystem initSys = CommandManager.initSys;
SSOToken ssoToken = initSys.getSSOToken(getAdminPassword());
DirectoryServerVendor.Vendor vendor = DirectoryServerVendor.getInstance().query(ldConnection);
if (!vendor.name.equals(DirectoryServerVendor.OPENDJ) && !vendor.name.equals(DirectoryServerVendor.OPENDS) && !vendor.name.equals(DirectoryServerVendor.ODSEE)) {
throw new CLIException(getResourceString("import-service-configuration-unknown-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
loadLDIF(vendor, ldConnection);
String ouServices = "ou=services," + initSys.getRootSuffix();
if (this.isOuServicesExists(ssoToken, ouServices)) {
System.out.print(getResourceString("import-service-configuration-prompt-delete") + " ");
String value = (new BufferedReader(new InputStreamReader(System.in))).readLine();
value = value.trim();
if (value.equalsIgnoreCase("y") || value.equalsIgnoreCase("yes")) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
deleteOuServicesDescendents(ssoToken, ouServices);
importData(xmlFile, encryptSecret, ssoToken);
}
} else {
outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
importData(xmlFile, encryptSecret, ssoToken);
}
} catch (SMSException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (LdapException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (LoginException e) {
throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
} catch (InvalidAuthContextException e) {
throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
}
}
Aggregations