i18n 支持

This commit is contained in:
zhou-hao
2021-06-21 18:21:20 +08:00
parent 208f9b34dd
commit e664d68023
22 changed files with 218 additions and 45 deletions

View File

@@ -36,7 +36,7 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
private ResourcesDefinition resources = new ResourcesDefinition();
private DimensionsDefinition dimensions = new DimensionsDefinition();
private String message = "权限不足,拒绝访问";
private String message = "error.access_denied";
private Phased phased;

View File

@@ -22,7 +22,7 @@ import javax.servlet.http.HttpServletResponse;
@AllArgsConstructor
public class TwoFactorHandlerInterceptorAdapter extends HandlerInterceptorAdapter {
private TwoFactorValidatorManager validatorManager;
private final TwoFactorValidatorManager validatorManager;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
@@ -45,9 +45,9 @@ public class TwoFactorHandlerInterceptorAdapter extends HandlerInterceptorAdapte
code = request.getHeader(factor.parameter());
}
if (StringUtils.isEmpty(code)) {
throw new NeedTwoFactorException(factor.message(), factor.provider());
throw new NeedTwoFactorException("assert.need_two_factor_verify", factor.provider());
} else if (!validator.verify(code, factor.timeout())) {
throw new NeedTwoFactorException("验证码错误", factor.provider());
throw new NeedTwoFactorException(factor.message(), factor.provider());
}
}
return super.preHandle(request, response, handler);

View File

@@ -85,8 +85,8 @@ public class AuthorizationController {
String username_ = (String) parameters.get("username");
String password_ = (String) parameters.get("password");
Assert.hasLength(username_, "用户名不能为空");
Assert.hasLength(password_, "密码不能为空");
Assert.hasLength(username_, "assert.username_must_not_be_empty");
Assert.hasLength(password_, "assert.password_must_not_be_empty");
Function<String, Object> parameterGetter = parameters::get;
return Mono.defer(() -> {
@@ -101,7 +101,7 @@ public class AuthorizationController {
.publish(eventPublisher)
.then(authenticationManager
.authenticate(Mono.just(new PlainTextUsernamePasswordAuthenticationRequest(username, password)))
.switchIfEmpty(Mono.error(() -> new AuthenticationException(AuthenticationException.ILLEGAL_PASSWORD,"密码错误")))
.switchIfEmpty(Mono.error(() -> new AuthenticationException(AuthenticationException.ILLEGAL_PASSWORD)))
.flatMap(auth -> {
//触发授权成功事件
AuthorizationSuccessEvent event = new AuthorizationSuccessEvent(auth, parameterGetter);