Skip to content

Commit

Permalink
fix(controller): show security message in English (#1218)
Browse files Browse the repository at this point in the history
* show security message in English

* jacoco ignore config and properties files

Co-authored-by: renyanda <781905270@qq.com>
  • Loading branch information
dreamlandliu and anda-ren authored Sep 16, 2022
1 parent 81157ae commit 7b04d0e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2022 Starwhale, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ai.starwhale.mlops.configuration.security;

import java.nio.charset.StandardCharsets;
import java.util.Locale;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;

@Configuration
public class SecurityMessageConfig {

@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.addBasenames("classpath:locales/messages", "classpath:org/springframework/security/messages");
messageSource.setDefaultEncoding(StandardCharsets.UTF_8.toString());
return messageSource;
}

@Bean
public LocaleResolver localeResolver() {
AcceptHeaderLocaleResolver resolver = new AcceptHeaderLocaleResolver();
resolver.setDefaultLocale(Locale.ENGLISH);
return resolver;
}

@Bean
public LocalValidatorFactoryBean validator() {
LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
bean.setValidationMessageSource(messageSource());
return bean;
}

}
2 changes: 2 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@
<exclude>**/ai/starwhale/mlops/datastore/*Wal.*</exclude>
<exclude>**/ai/starwhale/mlops/datastore/*Wal$*.*</exclude>
<exclude>**/ai/starwhale/mlops/datastore/Wal.*</exclude>
<exclude>**/ai/starwhale/mlops/**/*Config.*</exclude>
<exclude>**/ai/starwhale/mlops/**/*Properties.*</exclude>
</excludes>
</configuration>
<version>0.8.6</version>
Expand Down

0 comments on commit 7b04d0e

Please sign in to comment.