From 0a73ba0b2330edc7dc66da7ddb1f43644c1f8681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Tue, 27 Mar 2018 23:31:18 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20#IILTZ=20Config=E5=8D=95=E8=AF=8D?= =?UTF-8?q?=E6=8B=BC=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PigWebResponseExceptionTranslator.java | 48 ------------------- .../config/ResourceServerConfiguration.java | 6 +-- 2 files changed, 3 insertions(+), 51 deletions(-) delete mode 100644 pig-auth/src/main/java/com/github/pig/auth/component/PigWebResponseExceptionTranslator.java diff --git a/pig-auth/src/main/java/com/github/pig/auth/component/PigWebResponseExceptionTranslator.java b/pig-auth/src/main/java/com/github/pig/auth/component/PigWebResponseExceptionTranslator.java deleted file mode 100644 index 3cf8b0e4..00000000 --- a/pig-auth/src/main/java/com/github/pig/auth/component/PigWebResponseExceptionTranslator.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.pig.auth.component; - -import org.apache.commons.lang.StringUtils; -import org.springframework.http.ResponseEntity; -import org.springframework.security.authentication.InternalAuthenticationServiceException; -import org.springframework.security.oauth2.common.exceptions.InvalidGrantException; -import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; -import org.springframework.security.oauth2.common.exceptions.UnsupportedResponseTypeException; -import org.springframework.security.oauth2.provider.error.DefaultWebResponseExceptionTranslator; -import org.springframework.stereotype.Component; - -/** - * @author lengleng - * @date 2017/12/29 - * spring security 异常转化器 - * 默认的国际化的异常信息在 spring-security-code下messages_zh_CN - * LdapAuthenticationProvider.badCredentials=坏的凭证 - * LdapAuthenticationProvider.credentialsExpired=用户凭证已过期 - * LdapAuthenticationProvider.disabled=用户已失效 - * LdapAuthenticationProvider.expired=用户帐号已过期 - * LdapAuthenticationProvider.locked=用户帐号已被锁定 - * LdapAuthenticationProvider.emptyUsername=用户名不允许为空 - * LdapAuthenticationProvider.onlySupports=仅仅支持UsernamePasswordAuthenticationToken - * PasswordComparisonAuthenticator.badCredentials=坏的凭证 - */ -@Component -public class PigWebResponseExceptionTranslator extends DefaultWebResponseExceptionTranslator { - - public static final String BAD_MSG = "坏的凭证"; - - /** - * @param e spring security内部异常 - * @return 经过处理的异常信息 - * @throws Exception 通用异常 - */ - @Override - public ResponseEntity translate(Exception e) throws Exception { - OAuth2Exception oAuth2Exception; - if (e instanceof InvalidGrantException && StringUtils.equals(BAD_MSG, e.getMessage())) { - oAuth2Exception = new InvalidGrantException("密码错误", e); - } else if (e instanceof InternalAuthenticationServiceException) { - oAuth2Exception = new InvalidGrantException("用户名不存在", e); - } else { - oAuth2Exception = new UnsupportedResponseTypeException("服务处理异常", e); - } - return super.translate(oAuth2Exception); - } -} diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/componet/config/ResourceServerConfiguration.java b/pig-gateway/src/main/java/com/github/pig/gateway/componet/config/ResourceServerConfiguration.java index 6ed8a7f9..af1f5ccf 100644 --- a/pig-gateway/src/main/java/com/github/pig/gateway/componet/config/ResourceServerConfiguration.java +++ b/pig-gateway/src/main/java/com/github/pig/gateway/componet/config/ResourceServerConfiguration.java @@ -1,6 +1,6 @@ package com.github.pig.gateway.componet.config; -import com.github.pig.common.bean.config.FilterUrlsPropertiesConifg; +import com.github.pig.common.bean.config.FilterUrlsPropertiesConfig; import com.github.pig.gateway.componet.filter.ValidateCodeFilter; import com.github.pig.gateway.componet.handler.PigAccessDeniedHandler; import org.springframework.beans.factory.annotation.Autowired; @@ -25,7 +25,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic @EnableResourceServer public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { @Autowired - private FilterUrlsPropertiesConifg filterUrlsPropertiesConifg; + private FilterUrlsPropertiesConfig filterUrlsPropertiesConfig; @Autowired private OAuth2WebSecurityExpressionHandler expressionHandler; @Autowired @@ -40,7 +40,7 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter http.headers().frameOptions().disable(); ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry = http .authorizeRequests(); - for (String url : filterUrlsPropertiesConifg.getAnon()) { + for (String url : filterUrlsPropertiesConfig.getAnon()) { registry.antMatchers(url).permitAll(); } registry.anyRequest()