Search in sources :

Example 11 with MotechSettings

use of org.motechproject.config.domain.MotechSettings in project motech by motech.

the class SettingServiceImpl method getPasswordValidator.

@Override
public PasswordValidator getPasswordValidator() {
    MotechSettings motechSettings = configurationService.getPlatformSettings();
    String validatorName = motechSettings.getPasswordValidator();
    PasswordValidator validator = null;
    if (StringUtils.isNotBlank(validatorName)) {
        LOGGER.debug("No password validator configured");
        validator = passwordValidatorManager.getValidator(validatorName);
    }
    if (validator == null) {
        validator = passwordValidatorManager.noneValidator();
    }
    // if min pass length configured, then decorate the validator
    int minPassLength = getMinPasswordLength();
    if (minPassLength > 0) {
        validator = new MinLengthValidatorDecorator(validator, minPassLength);
    }
    return validator;
}
Also used : MinLengthValidatorDecorator(org.motechproject.security.validator.impl.MinLengthValidatorDecorator) MotechSettings(org.motechproject.config.domain.MotechSettings) PasswordValidator(org.motechproject.security.validator.PasswordValidator)

Example 12 with MotechSettings

use of org.motechproject.config.domain.MotechSettings in project motech by motech.

the class PasswordRecoveryServiceTest method shouldSendRecoveryEmail.

@Test
public void shouldSendRecoveryEmail() {
    motechSettings = mock(MotechSettings.class);
    when(settingsFacade.getPlatformSettings()).thenReturn(motechSettings);
    when(motechSettings.getServerHost()).thenReturn("serverurl");
    when(motechSettings.getServerUrl()).thenReturn("http://serverurl");
    when(motechSettings.getLoginMode()).thenReturn(LoginMode.REPOSITORY);
    PasswordRecovery newRecovery = new PasswordRecovery();
    newRecovery.setUsername(USERNAME);
    newRecovery.setEmail(EMAIL);
    newRecovery.setToken(TOKEN);
    newRecovery.setExpirationDate(DateTime.now().plusHours(1));
    newRecovery.setLocale(Locale.ENGLISH);
    emailSenderInjected.sendRecoveryEmail(newRecovery);
    verify(eventRelay).sendEventMessage(any(emailEvent.getClass()));
}
Also used : MotechSettings(org.motechproject.config.domain.MotechSettings) PasswordRecovery(org.motechproject.security.domain.PasswordRecovery) Test(org.junit.Test)

Example 13 with MotechSettings

use of org.motechproject.config.domain.MotechSettings in project motech by motech.

the class StartupController method submitForm.

@RequestMapping(value = "/startup", method = RequestMethod.POST)
@ResponseBody
public List<String> submitForm(@RequestBody StartupForm startupSettings) throws IOException {
    ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI;
    StartupFormValidator startupFormValidator = startupFormValidatorFactory.getStartupFormValidator(startupSettings, userService);
    List<String> errors = startupFormValidator.validate(startupSettings, configurationService.getConfigSource());
    if (!errors.isEmpty()) {
        return errors;
    } else if (!startupManager.canLaunchBundles()) {
        if (ConfigSource.UI.equals(configSource)) {
            MotechSettings settings = startupManager.getDefaultSettings();
            settings.setLanguage(startupSettings.getLanguage());
            settings.setLoginModeValue(startupSettings.getLoginMode());
            settings.setProviderName(startupSettings.getProviderName());
            settings.setProviderUrl(startupSettings.getProviderUrl());
            configurationService.savePlatformSettings(settings);
            if (LoginMode.REPOSITORY.equals(LoginMode.valueOf(startupSettings.getLoginMode()))) {
                registerMotechAdmin(startupSettings);
            }
        } else {
            registerMotechAdmin(startupSettings);
        }
        startupManager.startup();
    }
    return errors;
}
Also used : ConfigSource(org.motechproject.config.core.domain.ConfigSource) MotechSettings(org.motechproject.config.domain.MotechSettings) StartupFormValidator(org.motechproject.server.web.validator.StartupFormValidator) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

MotechSettings (org.motechproject.config.domain.MotechSettings)13 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)2 StartupForm (org.motechproject.server.web.form.StartupForm)2 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 AdminSettings (org.motechproject.admin.settings.AdminSettings)1 Settings (org.motechproject.admin.settings.Settings)1 SettingsOption (org.motechproject.admin.settings.SettingsOption)1 ConfigLocation (org.motechproject.config.core.domain.ConfigLocation)1 ConfigSource (org.motechproject.config.core.domain.ConfigSource)1 PasswordRecovery (org.motechproject.security.domain.PasswordRecovery)1 PasswordValidator (org.motechproject.security.validator.PasswordValidator)1 MinLengthValidatorDecorator (org.motechproject.security.validator.impl.MinLengthValidatorDecorator)1 StartupFormValidator (org.motechproject.server.web.validator.StartupFormValidator)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1