use of password.pwm.config.Configuration in project pwm by pwm-project.
the class SyslogAuditServiceTest method invokeConvertAuditRecordToSyslogMessage.
private String invokeConvertAuditRecordToSyslogMessage(final AuditRecord record, final int maxMsgLength) throws Exception {
final Method method = SyslogAuditService.class.getDeclaredMethod("convertAuditRecordToSyslogMessage", AuditRecord.class, Configuration.class);
method.setAccessible(true);
final Configuration configuration = spy(new Configuration(StoredConfigurationImpl.newStoredConfiguration()));
when(configuration.readAppProperty(AppProperty.AUDIT_SYSLOG_MAX_MESSAGE_LENGTH)).thenReturn(Integer.toString(maxMsgLength));
return (String) method.invoke(null, record, configuration);
}
use of password.pwm.config.Configuration in project pwm by pwm-project.
the class MacroTest method testUserMacros.
@Test
public void testUserMacros() throws Exception {
final String userDN = "cn=test1,ou=test,o=org";
final MacroMachine macroMachine;
{
final PwmApplication pwmApplication = mock(PwmApplication.class);
when(pwmApplication.getApplicationMode()).thenReturn(PwmApplicationMode.RUNNING);
when(pwmApplication.getConfig()).thenReturn(new Configuration(StoredConfigurationImpl.newStoredConfiguration()));
final UserInfo userInfo = mock(UserInfo.class);
final UserIdentity userIdentity = new UserIdentity(userDN, "profile");
when(userInfo.getUserIdentity()).thenReturn(userIdentity);
when(userInfo.readStringAttribute("givenName")).thenReturn("Jason");
final LoginInfoBean loginInfoBean = mock(LoginInfoBean.class);
when(loginInfoBean.isAuthenticated()).thenReturn(true);
when(loginInfoBean.getUserIdentity()).thenReturn(userIdentity);
macroMachine = MacroMachine.forUser(pwmApplication, null, userInfo, loginInfoBean);
}
{
// userDN macro
final String goal = userDN;
final String expanded = macroMachine.expandMacros("@LDAP:dn@");
Assert.assertEquals(goal, expanded);
}
{
// userDN + urlEncoding macro
final String goal = "test cn%3Dtest1%2Cou%3Dtest%2Co%3Dorg";
final String expanded = macroMachine.expandMacros("test @Encode:urlPath:[[@LDAP:dn@]]@");
Assert.assertEquals(goal, expanded);
}
{
// user attribute macro
final String goal = "test Jason test";
final String expanded = macroMachine.expandMacros("test @LDAP:givenName@ test");
Assert.assertEquals(goal, expanded);
}
}
use of password.pwm.config.Configuration in project pwm by pwm-project.
the class NewUserProfile method getNewUserPasswordPolicy.
public PwmPasswordPolicy getNewUserPasswordPolicy(final PwmApplication pwmApplication, final Locale userLocale) throws PwmUnrecoverableException {
final Configuration config = pwmApplication.getConfig();
final long maxNewUserCacheMS = Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.CONFIG_NEWUSER_PASSWORD_POLICY_CACHE_MS));
if (newUserPasswordPolicyCacheTime != null && TimeDuration.fromCurrent(newUserPasswordPolicyCacheTime).isLongerThan(maxNewUserCacheMS)) {
newUserPasswordPolicyCacheTime = Instant.now();
newUserPasswordPolicyCache.clear();
}
final PwmPasswordPolicy cachedPolicy = newUserPasswordPolicyCache.get(userLocale);
if (cachedPolicy != null) {
return cachedPolicy;
}
final PwmPasswordPolicy thePolicy;
final LdapProfile defaultLdapProfile = config.getDefaultLdapProfile();
final String configuredNewUserPasswordDN = readSettingAsString(PwmSetting.NEWUSER_PASSWORD_POLICY_USER);
if (configuredNewUserPasswordDN == null || configuredNewUserPasswordDN.length() < 1) {
final String errorMsg = "the setting " + PwmSetting.NEWUSER_PASSWORD_POLICY_USER.toMenuLocationDebug(this.getIdentifier(), PwmConstants.DEFAULT_LOCALE) + " must have a value";
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, errorMsg));
} else {
final String lookupDN;
if ("TESTUSER".equalsIgnoreCase(configuredNewUserPasswordDN)) {
lookupDN = defaultLdapProfile.readSettingAsString(PwmSetting.LDAP_TEST_USER_DN);
if (lookupDN == null || lookupDN.isEmpty()) {
final String errorMsg = "setting " + PwmSetting.LDAP_TEST_USER_DN.toMenuLocationDebug(defaultLdapProfile.getIdentifier(), PwmConstants.DEFAULT_LOCALE) + " must be configured since setting " + PwmSetting.NEWUSER_PASSWORD_POLICY_USER.toMenuLocationDebug(this.getIdentifier(), PwmConstants.DEFAULT_LOCALE) + " is set to TESTUSER";
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, errorMsg));
}
} else {
lookupDN = configuredNewUserPasswordDN;
}
if (lookupDN.isEmpty()) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, "user ldap dn in setting " + PwmSetting.NEWUSER_PASSWORD_POLICY_USER.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE) + " can not be resolved"));
} else {
try {
final ChaiProvider chaiProvider = pwmApplication.getProxyChaiProvider(defaultLdapProfile.getIdentifier());
final ChaiUser chaiUser = chaiProvider.getEntryFactory().newChaiUser(lookupDN);
final UserIdentity userIdentity = new UserIdentity(lookupDN, defaultLdapProfile.getIdentifier());
thePolicy = PasswordUtility.readPasswordPolicyForUser(pwmApplication, null, userIdentity, chaiUser, userLocale);
} catch (ChaiUnavailableException e) {
throw new PwmUnrecoverableException(PwmError.forChaiError(e.getErrorCode()));
}
}
}
newUserPasswordPolicyCache.put(userLocale, thePolicy);
return thePolicy;
}
use of password.pwm.config.Configuration in project pwm by pwm-project.
the class ErrorInformation method toUserStr.
public String toUserStr(final PwmSession pwmSession, final PwmApplication pwmApplication) {
if (userStrOverride != null) {
return userStrOverride;
}
Configuration config = null;
Locale userLocale = null;
if (pwmSession != null && pwmApplication.getConfig() != null) {
config = pwmApplication.getConfig();
}
if (pwmSession != null) {
userLocale = pwmSession.getSessionStateBean().getLocale();
}
return toUserStr(userLocale, config);
}
use of password.pwm.config.Configuration in project pwm by pwm-project.
the class OAuthMachine method makeOAuthRefreshRequest.
private OAuthResolveResults makeOAuthRefreshRequest(final PwmRequest pwmRequest, final String refreshCode) throws PwmUnrecoverableException {
final Configuration config = pwmRequest.getConfig();
final String requestUrl = settings.getCodeResolveUrl();
final String grantType = config.readAppProperty(AppProperty.OAUTH_ID_REFRESH_GRANT_TYPE);
final Map<String, String> requestParams = new HashMap<>();
requestParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_REFRESH_TOKEN), refreshCode);
requestParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_GRANT_TYPE), grantType);
final PwmHttpClientResponse restResults = makeHttpRequest(pwmRequest, "OAuth refresh resolver", settings, requestUrl, requestParams);
final String resolveResponseBodyStr = restResults.getBody();
final Map<String, String> resolveResultValues = JsonUtil.deserializeStringMap(resolveResponseBodyStr);
final OAuthResolveResults oAuthResolveResults = new OAuthResolveResults();
oAuthResolveResults.setAccessToken(resolveResultValues.get(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_ACCESS_TOKEN)));
oAuthResolveResults.setRefreshToken(refreshCode);
oAuthResolveResults.setExpiresSeconds(0);
try {
oAuthResolveResults.setExpiresSeconds(Integer.parseInt(resolveResultValues.get(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_EXPIRES))));
} catch (Exception e) {
LOGGER.warn(pwmRequest, "error parsing oauth expires value in resolve request: " + e.getMessage());
}
return oAuthResolveResults;
}
Aggregations