use of com.novell.ldapchai.provider.ChaiProvider in project pwm by pwm-project.
the class HelpdeskServlet method restDeleteUserRequest.
@ActionHandler(action = "deleteUser")
private ProcessStatus restDeleteUserRequest(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
final HelpdeskProfile helpdeskProfile = getHelpdeskProfile(pwmRequest);
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final String userKey = pwmRequest.readParameterAsString(PwmConstants.PARAM_USERKEY, PwmHttpRequestWrapper.Flag.BypassValidation);
if (userKey.length() < 1) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_MISSING_PARAMETER, PwmConstants.PARAM_USERKEY + " parameter is missing");
setLastError(pwmRequest, errorInformation);
pwmRequest.respondWithError(errorInformation, false);
return ProcessStatus.Halt;
}
final UserIdentity userIdentity = UserIdentity.fromKey(userKey, pwmApplication);
LOGGER.info(pwmSession, "received deleteUser request by " + pwmSession.getUserInfo().getUserIdentity().toString() + " for user " + userIdentity.toString());
// check if user should be seen by actor
HelpdeskServletUtil.checkIfUserIdentityViewable(pwmRequest, helpdeskProfile, userIdentity);
// read the userID for later logging.
String userID = null;
try {
userID = pwmSession.getUserInfo().getUsername();
} catch (PwmUnrecoverableException e) {
LOGGER.warn(pwmSession, "unable to read username of deleted user while creating audit record");
}
// execute user delete operation
final ChaiProvider provider = helpdeskProfile.readSettingAsBoolean(PwmSetting.HELPDESK_USE_PROXY) ? pwmApplication.getProxyChaiProvider(userIdentity.getLdapProfileID()) : pwmSession.getSessionManager().getChaiProvider();
try {
provider.deleteEntry(userIdentity.getUserDN());
} catch (ChaiOperationException e) {
final String errorMsg = "error while attempting to delete user " + userIdentity.toString() + ", error: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
LOGGER.debug(pwmRequest, errorMsg);
pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
return ProcessStatus.Halt;
}
// mark the event log
{
// normally the audit record builder reads the userID while constructing the record, but because the target user is already deleted,
// it will be included here explicitly.
final AuditRecordFactory.AuditUserDefinition auditUserDefinition = new AuditRecordFactory.AuditUserDefinition(userID, userIdentity.getUserDN(), userIdentity.getLdapProfileID());
final HelpdeskAuditRecord auditRecord = new AuditRecordFactory(pwmRequest).createHelpdeskAuditRecord(AuditEvent.HELPDESK_DELETE_USER, pwmSession.getUserInfo().getUserIdentity(), null, auditUserDefinition, pwmSession.getSessionStateBean().getSrcAddress(), pwmSession.getSessionStateBean().getSrcHostname());
pwmApplication.getAuditManager().submit(auditRecord);
}
LOGGER.info(pwmSession, "user " + userIdentity + " has been deleted");
final RestResultBean restResultBean = RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown);
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
use of com.novell.ldapchai.provider.ChaiProvider in project pwm by pwm-project.
the class SetupResponsesServlet method generateResponseInfoBean.
private static ResponseInfoBean generateResponseInfoBean(final PwmRequest pwmRequest, final ChallengeSet challengeSet, final Map<Challenge, String> readResponses, final Map<Challenge, String> helpdeskResponses) throws ChaiUnavailableException, PwmDataValidationException, PwmUnrecoverableException {
final ChaiProvider provider = pwmRequest.getPwmSession().getSessionManager().getChaiProvider();
try {
final ResponseInfoBean responseInfoBean = new ResponseInfoBean(readResponses, helpdeskResponses, challengeSet.getLocale(), challengeSet.getMinRandomRequired(), challengeSet.getIdentifier(), null, null);
final ChaiResponseSet responseSet = ChaiCrFactory.newChaiResponseSet(readResponses, challengeSet.getLocale(), challengeSet.getMinRandomRequired(), provider.getChaiConfiguration(), challengeSet.getIdentifier());
responseSet.meetsChallengeSetRequirements(challengeSet);
final SetupResponsesBean setupResponsesBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, SetupResponsesBean.class);
final int minRandomRequiredSetup = setupResponsesBean.getResponseData().getMinRandomSetup();
if (minRandomRequiredSetup == 0) {
// if using recover style, then all readResponseSet must be supplied at this point.
if (responseSet.getChallengeSet().getRandomChallenges().size() < challengeSet.getRandomChallenges().size()) {
throw new ChaiValidationException("too few random responses", ChaiError.CR_TOO_FEW_RANDOM_RESPONSES);
}
}
return responseInfoBean;
} catch (ChaiValidationException e) {
final ErrorInformation errorInfo = convertChaiValidationException(e);
throw new PwmDataValidationException(errorInfo);
}
}
use of com.novell.ldapchai.provider.ChaiProvider in project ldapchai by ldapchai.
the class ReadUserData method main.
public static void main(final String[] args) {
String ldapURL = "ldap://ldaphost:389";
String ldapBindDN = "cn=admin,ou=ou,o=o";
String ldapBindPW = "password";
if (args.length == 3) {
ldapURL = args[0];
ldapBindDN = args[1];
ldapBindPW = args[2];
}
try {
// create provider factory
final ChaiProviderFactory chaiProviderFactory = ChaiProviderFactory.newProviderFactory();
// create a provider using the standard JNDI factory.
ChaiProvider chaiProvider = chaiProviderFactory.newProvider(ldapURL, ldapBindDN, ldapBindPW);
ChaiUser user = chaiProvider.getEntryFactory().newChaiUser(ldapBindDN);
// read the value of the bindDN's cn attribute, and print it to stdout.
Map<String, String> allUserAttributes = user.readStringAttributes(null);
System.out.println("UserDN: " + user.getEntryDN());
// Output each of the user's attributes, and one value for each attribute:
for (String key : allUserAttributes.keySet()) {
String value = allUserAttributes.get(key);
System.out.println(key + ": " + value);
}
// Detect the user's password and output the debug string
ChaiPasswordPolicy pwdPolicy = user.getPasswordPolicy();
System.out.println("PasswordPolicy = " + pwdPolicy);
System.out.println("PasswordModificationDate = " + user.readPasswordModificationDate());
System.out.println("PasswordExpirationDate = " + user.readPasswordExpirationDate());
System.out.println("PasswordExpired = " + user.isPasswordExpired());
System.out.println("PasswordLocked = " + user.isPasswordLocked());
// Read the user's group membership, and output each group DN.
System.out.println(user.getEntryDN() + " groups: ");
for (ChaiGroup group : user.getGroups()) {
System.out.println(group.getEntryDN());
}
System.out.println("");
} catch (ChaiException e) {
System.out.println("LDAP error: " + e.getMessage());
}
}
use of com.novell.ldapchai.provider.ChaiProvider in project ldapchai by ldapchai.
the class SimpleConnection method main.
public static void main(final String[] args) throws ChaiException {
final ChaiProviderFactory chaiProviderFactory = ChaiProviderFactory.newProviderFactory();
final ChaiProvider chaiProvider = chaiProviderFactory.newProvider("ldap://ldaphost:389", "cn=admin,ou=ou,o=o", "password");
// create a provider using the quick chai factory
final ChaiUser user = chaiProvider.getEntryFactory().newChaiUser("cn=admin,ou=ou,o=o");
// read the value of the bindDN's cn attribute, and print it to stdout.
final String cnValue = user.readStringAttribute("cn");
// output the CN of the user
System.out.println("cnValue = " + cnValue);
}
use of com.novell.ldapchai.provider.ChaiProvider in project ldapchai by ldapchai.
the class ChaiUtility method getRootDSE.
public static ChaiEntry getRootDSE(final ChaiProvider provider) throws ChaiUnavailableException {
final List<String> splitUrls = provider.getChaiConfiguration().bindURLsAsList();
final StringBuilder newUrlConfig = new StringBuilder();
boolean currentURLsHavePath = false;
for (final String splitUrl : splitUrls) {
final URI uri = URI.create(splitUrl);
final String newURI = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort();
newUrlConfig.append(newURI);
if (uri.getPath() != null && uri.getPath().length() > 0) {
currentURLsHavePath = true;
}
newUrlConfig.append(",");
}
final ChaiConfiguration rootDSEChaiConfig = ChaiConfiguration.builder(provider.getChaiConfiguration()).setSetting(ChaiSetting.BIND_URLS, newUrlConfig.toString()).build();
final ChaiProvider rootDseProvider = currentURLsHavePath ? provider.getProviderFactory().newProvider(rootDSEChaiConfig) : provider;
// can not call the VendorFactory here, because VendorFactory in turn calls this method to get the
// directory vendor. Instead, we will go directly to the Generic VendorFactory
final GenericEntryFactory genericEntryFactory = new GenericEntryFactory();
return genericEntryFactory.newChaiEntry("", rootDseProvider);
}
Aggregations