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