Search in sources :

Example 81 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project appng by appNG.

the class HashPassword method savePasswordForSubject.

static String savePasswordForSubject(CliEnvironment cle, AuthSubject subject, String password) throws BusinessException {
    try {
        String passwordPolicyClass = cle.getPlatformConfig().getString(Platform.Property.PASSWORD_POLICY, ConfigurablePasswordPolicy.class.getName());
        PasswordPolicy passwordPolicy = (PasswordPolicy) PasswordPolicy.class.getClassLoader().loadClass(passwordPolicyClass).newInstance();
        passwordPolicy.configure(cle.getPlatformConfig());
        ValidationResult validationResult = passwordPolicy.validatePassword(subject.getAuthName(), null, password.toCharArray());
        if (!validationResult.isValid()) {
            ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
            messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name());
            messageSource.setBasenames("messages-core");
            messageSource.setFallbackToSystemLocale(false);
            List<String> messages = Arrays.asList(validationResult.getMessages()).stream().map(p -> messageSource.getMessage(p.getMessageKey(), p.getMessageArgs(), Locale.ENGLISH)).collect(Collectors.toList());
            throw new BusinessException(StringUtils.join(messages, System.lineSeparator()));
        }
        PasswordHandler passwordHandler = cle.getCoreService().getDefaultPasswordHandler(subject);
        passwordHandler.applyPassword(password);
        return subject.getDigest();
    } catch (ReflectiveOperationException e) {
        throw new BusinessException(e);
    }
}
Also used : Arrays(java.util.Arrays) Parameters(com.beust.jcommander.Parameters) Parameter(com.beust.jcommander.Parameter) BusinessException(org.appng.api.BusinessException) Platform(org.appng.api.Platform) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) StandardCharsets(java.nio.charset.StandardCharsets) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) List(java.util.List) SubjectImpl(org.appng.core.domain.SubjectImpl) PasswordPolicy(org.appng.api.auth.PasswordPolicy) PasswordHandler(org.appng.core.security.PasswordHandler) Locale(java.util.Locale) CliEnvironment(org.appng.cli.CliEnvironment) AuthSubject(org.appng.api.model.AuthSubject) ExecutableCliCommand(org.appng.cli.ExecutableCliCommand) BufferedReader(java.io.BufferedReader) ConfigurablePasswordPolicy(org.appng.core.security.ConfigurablePasswordPolicy) ValidationResult(org.appng.api.auth.PasswordPolicy.ValidationResult) BusinessException(org.appng.api.BusinessException) PasswordHandler(org.appng.core.security.PasswordHandler) PasswordPolicy(org.appng.api.auth.PasswordPolicy) ConfigurablePasswordPolicy(org.appng.core.security.ConfigurablePasswordPolicy) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) ValidationResult(org.appng.api.auth.PasswordPolicy.ValidationResult) ConfigurablePasswordPolicy(org.appng.core.security.ConfigurablePasswordPolicy)

Example 82 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project appng by appNG.

the class CallableActionTest method initApplication.

public ApplicationRequest initApplication(boolean withDataSource) {
    MockitoAnnotations.initMocks(this);
    permissionProcessor = new DefaultPermissionProcessor(subject, site, application);
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("testmessages");
    RequestSupportImpl requestSupport = new RequestSupportImpl();
    requestSupport.setMessageSource(messageSource);
    requestSupport.setEnvironment(environment);
    ApplicationRequest applicationRequest = new ApplicationRequest(request, new DummyPermissionProcessor(subject, site, application), requestSupport);
    applicationRequest.setApplicationConfig(applicationConfigProvider);
    applicationRequest.setValidationProvider(new DefaultValidationProvider());
    Mockito.when(config.getParams()).thenReturn(new Params());
    Mockito.when(config.getLinkpanel()).thenReturn(new ArrayList<>());
    MetaData metaData = new MetaData();
    metaData.setBindClass(Object.class.getName());
    Mockito.when(config.getMetaData()).thenReturn(metaData);
    Mockito.when(action.getConfig()).thenReturn(config);
    Mockito.when(action.getBean()).thenReturn(bean);
    Mockito.when(action.getId()).thenReturn(MY_ACTION);
    Mockito.when(actionRef.getEventId()).thenReturn(MY_EVENT);
    Mockito.when(actionRef.getId()).thenReturn(MY_ACTIONREF);
    Mockito.when(actionRef.getParams()).thenReturn(new Params());
    if (withDataSource) {
        Mockito.when(action.getDatasource()).thenReturn(datasourceRef);
        Mockito.when(datasourceRef.getId()).thenReturn(MY_DATASOURCE);
        Mockito.when(datasourceRef.getParams()).thenReturn(new Params());
        Mockito.when(datasource.getConfig()).thenReturn(config);
        Mockito.when(datasource.getBean()).thenReturn(bean);
        Mockito.when(application.getBean(TEST_BEAN, DataProvider.class)).thenReturn(dataProvider);
        Mockito.when(applicationConfigProvider.getDatasource(MY_DATASOURCE)).thenReturn(datasource);
    }
    Mockito.when(bean.getId()).thenReturn(TEST_BEAN);
    Mockito.when(environment.getLocale()).thenReturn(Locale.GERMAN);
    Mockito.when(event.getConfig()).thenReturn(config);
    Mockito.when(event.getId()).thenReturn(MY_EVENT);
    Mockito.when(application.getBean(TEST_BEAN, ActionProvider.class)).thenReturn(actionProvider);
    Mockito.when(application.getBean(MessageSource.class)).thenReturn(messageSource);
    Mockito.when(applicationConfigProvider.getAction(MY_EVENT, MY_ACTIONREF)).thenReturn(action);
    Mockito.when(applicationConfigProvider.getEvent(MY_EVENT)).thenReturn(event);
    ApplicationRootConfig applicationRootConfig = new ApplicationRootConfig();
    applicationRootConfig.setConfig(new ApplicationConfig());
    Mockito.when(applicationConfigProvider.getApplicationRootConfig()).thenReturn(applicationRootConfig);
    return applicationRequest;
}
Also used : ApplicationRootConfig(org.appng.xml.platform.ApplicationRootConfig) ApplicationConfig(org.appng.xml.platform.ApplicationConfig) DefaultValidationProvider(org.appng.api.support.validation.DefaultValidationProvider) MetaData(org.appng.xml.platform.MetaData) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Params(org.appng.xml.platform.Params)

Example 83 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project appng by appNG.

the class AbstractTest method getMessageSource.

public static MessageSource getMessageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("testmessages");
    return messageSource;
}
Also used : ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource)

Example 84 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project edison-microservice by otto-de.

the class ValidationConfiguration method edisonValidationMessageSource.

@Bean
public ResourceBundleMessageSource edisonValidationMessageSource() {
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasename("ValidationMessages");
    source.setUseCodeAsDefaultMessage(true);
    return source;
}
Also used : ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Bean(org.springframework.context.annotation.Bean) LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)

Example 85 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project alf.io by alfio-event.

the class FormattersTest method getFormattedDates.

@Test
void getFormattedDates() {
    var messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("alfio.i18n.public");
    ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault());
    ContentLanguage.ALL_LANGUAGES.forEach(cl -> FORMATTER_CODES.forEach(code -> Formatters.formatDateForLocale(now, code, messageSource, (a, b) -> Assertions.assertNotNull(b), cl, true)));
}
Also used : Test(org.junit.jupiter.api.Test) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) List(java.util.List) ZonedDateTime(java.time.ZonedDateTime) Assertions(org.junit.jupiter.api.Assertions) ContentLanguage(alfio.model.ContentLanguage) ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)179 Bean (org.springframework.context.annotation.Bean)99 Before (org.junit.Before)16 MessageSourceAccessor (org.springframework.context.support.MessageSourceAccessor)13 LocalValidatorFactoryBean (org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)9 ValidatorFactory (javax.validation.ValidatorFactory)6 ResourceBundleMessageInterpolator (org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator)6 PlatformResourceBundleLocator (org.hibernate.validator.resourceloading.PlatformResourceBundleLocator)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 IOException (java.io.IOException)5 List (java.util.List)5 Locale (java.util.Locale)5 ReaderFactoryByMap (net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap)5 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)5 MessageSource (org.springframework.context.MessageSource)5 ArrayList (java.util.ArrayList)4 N2oApplicationBuilder (net.n2oapp.framework.config.N2oApplicationBuilder)4 N2oEnvironment (net.n2oapp.framework.config.compile.pipeline.N2oEnvironment)4 PersisterFactoryByMap (net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap)4