Search in sources :

Example 41 with Configuration

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);
}
Also used : Configuration(password.pwm.config.Configuration) Method(java.lang.reflect.Method)

Example 42 with 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);
    }
}
Also used : PwmApplication(password.pwm.PwmApplication) LoginInfoBean(password.pwm.bean.LoginInfoBean) Configuration(password.pwm.config.Configuration) UserIdentity(password.pwm.bean.UserIdentity) UserInfo(password.pwm.ldap.UserInfo) Test(org.junit.Test)

Example 43 with Configuration

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) Configuration(password.pwm.config.Configuration) StoredConfiguration(password.pwm.config.stored.StoredConfiguration) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiUser(com.novell.ldapchai.ChaiUser) UserIdentity(password.pwm.bean.UserIdentity) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 44 with Configuration

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);
}
Also used : Locale(java.util.Locale) Configuration(password.pwm.config.Configuration)

Example 45 with Configuration

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;
}
Also used : Configuration(password.pwm.config.Configuration) PwmHttpClientConfiguration(password.pwm.http.client.PwmHttpClientConfiguration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PwmHttpClientResponse(password.pwm.http.client.PwmHttpClientResponse) URISyntaxException(java.net.URISyntaxException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Aggregations

Configuration (password.pwm.config.Configuration)111 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)45 FormConfiguration (password.pwm.config.value.data.FormConfiguration)37 PwmApplication (password.pwm.PwmApplication)33 ErrorInformation (password.pwm.error.ErrorInformation)33 PwmOperationalException (password.pwm.error.PwmOperationalException)25 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)23 Locale (java.util.Locale)22 PwmSession (password.pwm.http.PwmSession)21 PwmException (password.pwm.error.PwmException)17 EmailItemBean (password.pwm.bean.EmailItemBean)16 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)16 UserInfo (password.pwm.ldap.UserInfo)15 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)14 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)13 MacroMachine (password.pwm.util.macro.MacroMachine)13 LinkedHashMap (java.util.LinkedHashMap)12 Instant (java.time.Instant)11 UserIdentity (password.pwm.bean.UserIdentity)10