Search in sources :

Example 51 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class CaptchaUtility method checkIfCaptchaConfigEnabled.

public static boolean checkIfCaptchaConfigEnabled(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
    final Configuration config = pwmRequest.getPwmApplication().getConfig();
    final PasswordData privateKey = config.readSettingAsPassword(PwmSetting.RECAPTCHA_KEY_PRIVATE);
    final String publicKey = config.readSettingAsString(PwmSetting.RECAPTCHA_KEY_PUBLIC);
    return (privateKey != null && publicKey != null && !publicKey.isEmpty());
}
Also used : Configuration(password.pwm.config.Configuration)

Example 52 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class UrlShortenerService method init.

public void init(final PwmApplication pwmApplication) throws PwmUnrecoverableException {
    this.pwmApplication = pwmApplication;
    final Configuration config = this.pwmApplication.getConfig();
    final String classNameString = config.readSettingAsString(PwmSetting.URL_SHORTENER_CLASS);
    if (classNameString != null && classNameString.length() > 0) {
        final Properties sConfig = new Properties();
        final List<String> sConfigList = config.readSettingAsStringArray(PwmSetting.URL_SHORTENER_PARAMETERS);
        // Parse configuration
        if (sConfigList != null) {
            for (final String p : sConfigList) {
                final List<String> pl = Arrays.asList(p.split("=", 2));
                if (pl.size() == 2) {
                    sConfig.put(pl.get(0), pl.get(1));
                }
            }
        }
        try {
            final Class<?> theClass = Class.forName(classNameString);
            theShortener = (BasicUrlShortener) theClass.newInstance();
            theShortener.setConfiguration(sConfig);
        } catch (java.lang.IllegalAccessException e) {
            LOGGER.error("Illegal access to class " + classNameString + ": " + e.toString());
        } catch (java.lang.InstantiationException e) {
            LOGGER.error("Cannot instantiate class " + classNameString + ": " + e.toString());
        } catch (java.lang.ClassNotFoundException e) {
            LOGGER.error("Class " + classNameString + " not found: " + e.getMessage());
        }
    }
    status = PwmService.STATUS.OPEN;
}
Also used : Configuration(password.pwm.config.Configuration) Properties(java.util.Properties)

Example 53 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class OAuthMachine method redirectUserToOAuthServer.

public void redirectUserToOAuthServer(final PwmRequest pwmRequest, final String nextUrl, final UserIdentity userIdentity, final String forgottenPasswordProfile) throws PwmUnrecoverableException, IOException {
    LOGGER.trace(pwmRequest, "preparing to redirect user to oauth authentication service, setting nextUrl to " + nextUrl);
    pwmRequest.getPwmSession().getSessionStateBean().setOauthInProgress(true);
    final Configuration config = pwmRequest.getConfig();
    final String state = makeStateStringForRequest(pwmRequest, nextUrl, forgottenPasswordProfile);
    final String redirectUri = figureOauthSelfEndPointUrl(pwmRequest);
    final String code = config.readAppProperty(AppProperty.OAUTH_ID_REQUEST_TYPE);
    final Map<String, String> urlParams = new LinkedHashMap<>();
    urlParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_CLIENT_ID), settings.getClientID());
    urlParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_RESPONSE_TYPE), code);
    urlParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_STATE), state);
    urlParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_REDIRECT_URI), redirectUri);
    if (userIdentity != null) {
        final String parametersValue = figureUsernameGrantParam(pwmRequest, userIdentity);
        if (!StringUtil.isEmpty(parametersValue)) {
            urlParams.put("parameters", parametersValue);
        }
    }
    final String redirectUrl = PwmURL.appendAndEncodeUrlParameters(settings.getLoginURL(), urlParams);
    try {
        pwmRequest.sendRedirect(redirectUrl);
        pwmRequest.getPwmSession().getSessionStateBean().setOauthInProgress(true);
        LOGGER.debug(pwmRequest, "redirecting user to oauth id server, url: " + redirectUrl);
    } catch (PwmUnrecoverableException e) {
        final String errorMsg = "unexpected error redirecting user to oauth page: " + e.toString();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) Configuration(password.pwm.config.Configuration) PwmHttpClientConfiguration(password.pwm.http.client.PwmHttpClientConfiguration) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LinkedHashMap(java.util.LinkedHashMap)

Example 54 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class OAuthMachine method makeOAuthResolveRequest.

OAuthResolveResults makeOAuthResolveRequest(final PwmRequest pwmRequest, final String requestCode) throws PwmUnrecoverableException {
    final Configuration config = pwmRequest.getConfig();
    final String requestUrl = settings.getCodeResolveUrl();
    final String grantType = config.readAppProperty(AppProperty.OAUTH_ID_ACCESS_GRANT_TYPE);
    final String redirectUri = figureOauthSelfEndPointUrl(pwmRequest);
    final String clientID = settings.getClientID();
    final Map<String, String> requestParams = new HashMap<>();
    requestParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_CODE), requestCode);
    requestParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_GRANT_TYPE), grantType);
    requestParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_REDIRECT_URI), redirectUri);
    requestParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_CLIENT_ID), clientID);
    final PwmHttpClientResponse restResults = makeHttpRequest(pwmRequest, "oauth code 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(resolveResultValues.get(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_REFRESH_TOKEN)));
    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 code resolver response from server at " + requestUrl + ", error: " + 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)

Example 55 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class OAuthMachine method makeOAuthGetAttributeRequest.

String makeOAuthGetAttributeRequest(final PwmRequest pwmRequest, final String accessToken) throws PwmUnrecoverableException {
    final Configuration config = pwmRequest.getConfig();
    final String requestUrl = settings.getAttributesUrl();
    final Map<String, String> requestParams = new HashMap<>();
    requestParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_ACCESS_TOKEN), accessToken);
    requestParams.put(config.readAppProperty(AppProperty.HTTP_PARAM_OAUTH_ATTRIBUTES), settings.getDnAttributeName());
    final PwmHttpClientResponse restResults = makeHttpRequest(pwmRequest, "OAuth getattribute", settings, requestUrl, requestParams);
    return restResults.getBody();
}
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)

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