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());
}
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;
}
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);
}
}
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;
}
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();
}
Aggregations