use of com.novell.ldapchai.ChaiEntry in project pwm by pwm-project.
the class LDAPStatusChecker method checkAdPasswordPolicyApi.
private static List<HealthRecord> checkAdPasswordPolicyApi(final PwmApplication pwmApplication) {
final boolean passwordPolicyApiEnabled = pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.AD_ENFORCE_PW_HISTORY_ON_SET);
if (!passwordPolicyApiEnabled) {
return Collections.emptyList();
}
if (pwmApplication.getHealthMonitor() != null) {
final Map<HealthMonitor.HealthMonitorFlag, Serializable> healthProperties = pwmApplication.getHealthMonitor().getHealthProperties();
if (healthProperties.containsKey(HealthMonitor.HealthMonitorFlag.AdPasswordPolicyApiCheck)) {
final List<HealthRecord> healthRecords = (List<HealthRecord>) healthProperties.get(HealthMonitor.HealthMonitorFlag.AdPasswordPolicyApiCheck);
return healthRecords;
}
}
LOGGER.trace(SessionLabel.HEALTH_SESSION_LABEL, "beginning check for ad api password policy (asn " + PwmConstants.LDAP_AD_PASSWORD_POLICY_CONTROL_ASN + ") support");
boolean errorReachingServer = false;
final ArrayList<HealthRecord> healthRecords = new ArrayList<>();
try {
for (final LdapProfile ldapProfile : pwmApplication.getConfig().getLdapProfiles().values()) {
final ChaiConfiguration profileChaiConfiguration = LdapOperationsHelper.createChaiConfiguration(pwmApplication.getConfig(), ldapProfile);
final Collection<ChaiConfiguration> replicaConfigs = ChaiUtility.splitConfigurationPerReplica(profileChaiConfiguration, Collections.emptyMap());
for (final ChaiConfiguration chaiConfiguration : replicaConfigs) {
final ChaiProvider loopProvider = pwmApplication.getLdapConnectionService().getChaiProviderFactory().newProvider(chaiConfiguration);
final ChaiEntry rootDSE = ChaiUtility.getRootDSE(loopProvider);
final Set<String> controls = rootDSE.readMultiStringAttribute("supportedControl");
final boolean asnSupported = controls.contains(PwmConstants.LDAP_AD_PASSWORD_POLICY_CONTROL_ASN);
if (!asnSupported) {
final String url = chaiConfiguration.getSetting(ChaiSetting.BIND_URLS);
final HealthRecord record = HealthRecord.forMessage(HealthMessage.LDAP_Ad_History_Asn_Missing, PwmSetting.AD_ENFORCE_PW_HISTORY_ON_SET.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE), url);
healthRecords.add(record);
LOGGER.warn(record.toDebugString(PwmConstants.DEFAULT_LOCALE, pwmApplication.getConfig()));
}
}
}
} catch (Exception e) {
errorReachingServer = true;
LOGGER.error(SessionLabel.HEALTH_SESSION_LABEL, "error during ad api password policy (asn " + PwmConstants.LDAP_AD_PASSWORD_POLICY_CONTROL_ASN + ") check: " + e.getMessage());
}
if (!errorReachingServer && pwmApplication.getHealthMonitor() != null) {
final Map<HealthMonitor.HealthMonitorFlag, Serializable> healthProperties = pwmApplication.getHealthMonitor().getHealthProperties();
healthProperties.put(HealthMonitor.HealthMonitorFlag.AdPasswordPolicyApiCheck, healthRecords);
}
return healthRecords;
}
use of com.novell.ldapchai.ChaiEntry in project pwm by pwm-project.
the class LDAPStatusChecker method checkBasicLdapConnectivity.
public List<HealthRecord> checkBasicLdapConnectivity(final PwmApplication pwmApplication, final Configuration config, final LdapProfile ldapProfile, final boolean testContextlessRoot) {
final List<HealthRecord> returnRecords = new ArrayList<>();
ChaiProvider chaiProvider = null;
try {
final DirectoryVendor directoryVendor;
try {
final String proxyDN = ldapProfile.readSettingAsString(PwmSetting.LDAP_PROXY_USER_DN);
final PasswordData proxyPW = ldapProfile.readSettingAsPassword(PwmSetting.LDAP_PROXY_USER_PASSWORD);
if (proxyDN == null || proxyDN.length() < 1) {
return Collections.singletonList(new HealthRecord(HealthStatus.WARN, HealthTopic.LDAP, "Missing Proxy User DN"));
}
if (proxyPW == null) {
return Collections.singletonList(new HealthRecord(HealthStatus.WARN, HealthTopic.LDAP, "Missing Proxy User Password"));
}
chaiProvider = LdapOperationsHelper.createChaiProvider(pwmApplication, SessionLabel.HEALTH_SESSION_LABEL, ldapProfile, config, proxyDN, proxyPW);
final ChaiEntry adminEntry = chaiProvider.getEntryFactory().newChaiEntry(proxyDN);
adminEntry.exists();
directoryVendor = chaiProvider.getDirectoryVendor();
} catch (ChaiException e) {
final ChaiError chaiError = ChaiErrors.getErrorForMessage(e.getMessage());
final PwmError pwmError = PwmError.forChaiError(chaiError);
final StringBuilder errorString = new StringBuilder();
final String profileName = ldapProfile.getIdentifier();
errorString.append("error connecting to ldap directory (").append(profileName).append("), error: ").append(e.getMessage());
if (chaiError != null && chaiError != ChaiError.UNKNOWN) {
errorString.append(" (");
errorString.append(chaiError.toString());
if (pwmError != null && pwmError != PwmError.ERROR_UNKNOWN) {
errorString.append(" - ");
errorString.append(pwmError.getLocalizedMessage(PwmConstants.DEFAULT_LOCALE, pwmApplication.getConfig()));
}
errorString.append(")");
}
returnRecords.add(new HealthRecord(HealthStatus.WARN, makeLdapTopic(ldapProfile, config), errorString.toString()));
pwmApplication.getLdapConnectionService().setLastLdapFailure(ldapProfile, new ErrorInformation(PwmError.ERROR_DIRECTORY_UNAVAILABLE, errorString.toString()));
return returnRecords;
} catch (Exception e) {
final HealthRecord record = HealthRecord.forMessage(HealthMessage.LDAP_No_Connection, e.getMessage());
returnRecords.add(record);
pwmApplication.getLdapConnectionService().setLastLdapFailure(ldapProfile, new ErrorInformation(PwmError.ERROR_DIRECTORY_UNAVAILABLE, record.getDetail(PwmConstants.DEFAULT_LOCALE, pwmApplication.getConfig())));
return returnRecords;
}
if (directoryVendor != null && directoryVendor == DirectoryVendor.ACTIVE_DIRECTORY) {
returnRecords.addAll(checkAd(pwmApplication, config, ldapProfile));
}
if (testContextlessRoot) {
for (final String loopContext : ldapProfile.readSettingAsStringArray(PwmSetting.LDAP_CONTEXTLESS_ROOT)) {
try {
final ChaiEntry contextEntry = chaiProvider.getEntryFactory().newChaiEntry(loopContext);
final Set<String> objectClasses = contextEntry.readObjectClass();
if (objectClasses == null || objectClasses.isEmpty()) {
final String errorString = "ldap context setting '" + loopContext + "' is not valid";
returnRecords.add(new HealthRecord(HealthStatus.WARN, makeLdapTopic(ldapProfile, config), errorString));
}
} catch (Exception e) {
final String errorString = "ldap root context '" + loopContext + "' is not valid: " + e.getMessage();
returnRecords.add(new HealthRecord(HealthStatus.WARN, makeLdapTopic(ldapProfile, config), errorString));
}
}
}
} finally {
if (chaiProvider != null) {
try {
chaiProvider.close();
} catch (Exception e) {
/* ignore */
}
}
}
return returnRecords;
}
use of com.novell.ldapchai.ChaiEntry in project pwm by pwm-project.
the class UserMatchViewerFunction method testIfLdapDNIsValid.
private void testIfLdapDNIsValid(final PwmApplication pwmApplication, final String baseDN, final String profileID) throws PwmOperationalException, PwmUnrecoverableException {
final Set<String> profileIDsToTest = new LinkedHashSet<>();
if (profileID == null || profileID.isEmpty()) {
profileIDsToTest.add(pwmApplication.getConfig().getDefaultLdapProfile().getIdentifier());
} else if (profileID.equals(PwmConstants.PROFILE_ID_ALL)) {
profileIDsToTest.addAll(pwmApplication.getConfig().getLdapProfiles().keySet());
} else {
profileIDsToTest.add(profileID);
}
for (final String loopID : profileIDsToTest) {
ChaiEntry chaiEntry = null;
try {
final ChaiProvider proxiedProvider = pwmApplication.getProxyChaiProvider(loopID);
chaiEntry = proxiedProvider.getEntryFactory().newChaiEntry(baseDN);
} catch (Exception e) {
LOGGER.error("error while testing entry DN for profile '" + profileID + "', error:" + profileID);
}
try {
if (chaiEntry != null && !chaiEntry.exists()) {
final String errorMsg = "entry DN '" + baseDN + "' is not valid for profile " + loopID;
throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_LDAP_DATA_ERROR, errorMsg));
}
} catch (ChaiUnavailableException e) {
throw PwmUnrecoverableException.fromChaiException(e);
}
}
}
use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.
the class JNDIProviderImpl method supportsSearchResultPaging.
private boolean supportsSearchResultPaging() throws ChaiUnavailableException, ChaiOperationException {
final String enableSettingStr = this.getChaiConfiguration().getSetting(ChaiSetting.LDAP_SEARCH_PAGING_ENABLE);
if ("auto".equalsIgnoreCase(enableSettingStr)) {
if (cachedPagingEnableSupport == null) {
final ChaiEntry rootDse = ChaiUtility.getRootDSE(this);
final Set<String> supportedControls = rootDse.readMultiStringAttribute("supportedControl");
cachedPagingEnableSupport = supportedControls.contains(PagedResultsControl.OID);
}
return cachedPagingEnableSupport;
}
return Boolean.parseBoolean(enableSettingStr);
}
use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.
the class OracleDSEntries method readPasswordPolicy.
static OracleDSPasswordPolicy readPasswordPolicy(final InetOrgPerson person) throws ChaiUnavailableException, ChaiOperationException {
ChaiEntry searchEntry = new OracleDSEntry(person.getEntryDN(), person.getChaiProvider());
OracleDSEntry discoveredPolicy = null;
int saftyCounter = 0;
while (saftyCounter < 50 && searchEntry != null && discoveredPolicy == null) {
saftyCounter++;
if (searchEntry.exists()) {
final String pwdPolicySubentryValue = searchEntry.readStringAttribute(ChaiConstant.ATTR_ORACLEDS_PASSWORD_SUB_ENTRY);
if (pwdPolicySubentryValue != null && !pwdPolicySubentryValue.isEmpty()) {
final OracleDSEntry policyEntry = new OracleDSEntry(pwdPolicySubentryValue, person.getChaiProvider());
if (policyEntry.exists()) {
discoveredPolicy = policyEntry;
}
}
}
searchEntry = searchEntry.getParentEntry();
}
if (discoveredPolicy != null) {
return new OracleDSPasswordPolicy(discoveredPolicy.getEntryDN(), person.getChaiProvider());
}
final OracleDSPasswordPolicy defaultPolicy = new OracleDSPasswordPolicy("cn=Password Policy,cn=config", person.getChaiProvider());
if (defaultPolicy.exists()) {
return defaultPolicy;
}
return defaultPolicy;
}
Aggregations