Commit 0000a36f authored by hongguangwu's avatar hongguangwu

Merge remote-tracking branch 'origin/MVP1.7.5' into MVP1.7.5

parents 261130fd 48bb65f7
...@@ -86,10 +86,10 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { ...@@ -86,10 +86,10 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@SneakyThrows @SneakyThrows
protected void configure(HttpSecurity http) { protected void configure(HttpSecurity http) {
http.addFilterBefore(getPasswordDecoderFilter(),PasswordDecoderFilter.class) http.addFilterBefore(getPasswordDecoderFilter(),PasswordDecoderFilter.class)
.formLogin().loginPage("/token/login").loginProcessingUrl("/token/form") //.formLogin().loginPage("/token/login").loginProcessingUrl("/token/form")
.failureHandler(authenticationFailureHandler()).and().logout() //.failureHandler(authenticationFailureHandler()).and().logout()
.logoutSuccessHandler(logoutSuccessHandler()).deleteCookies("JSESSIONID").invalidateHttpSession(true) //.logoutSuccessHandler(logoutSuccessHandler()).deleteCookies("JSESSIONID").invalidateHttpSession(true)
.and() //.and()
.authorizeRequests().antMatchers("/**/login","/token/**", "/actuator/**", "/mobile/**", "/oauth/token","/weixin/callback","/oauth/**", "/wxLogin").permitAll() .authorizeRequests().antMatchers("/**/login","/token/**", "/actuator/**", "/mobile/**", "/oauth/token","/weixin/callback","/oauth/**", "/wxLogin").permitAll()
.anyRequest().authenticated().and().csrf().disable(); .anyRequest().authenticated().and().csrf().disable();
} }
......
...@@ -41,7 +41,7 @@ public class WxLoginAuthenticationFilter extends AbstractAuthenticationProcessin ...@@ -41,7 +41,7 @@ public class WxLoginAuthenticationFilter extends AbstractAuthenticationProcessin
private WxConfig wxConfig; private WxConfig wxConfig;
public WxLoginAuthenticationFilter() { public WxLoginAuthenticationFilter() {
super(new AntPathRequestMatcher(SPRING_SECURITY_RESTFUL_LOGIN_URL, "GET")); super(new AntPathRequestMatcher(SPRING_SECURITY_RESTFUL_LOGIN_URL, "POST"));
} }
/** /**
* *
...@@ -54,16 +54,15 @@ public class WxLoginAuthenticationFilter extends AbstractAuthenticationProcessin ...@@ -54,16 +54,15 @@ public class WxLoginAuthenticationFilter extends AbstractAuthenticationProcessin
@Override @Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
if (!postOnly && !request.getMethod().equals("GET")) { if (postOnly && !request.getMethod().equals("POST")) {
throw new AuthenticationServiceException( throw new AuthenticationServiceException(
"Authentication method not supported: " + request.getMethod()); "Authentication method not supported: " + request.getMethod());
} }
AbstractAuthenticationToken authRequest; AbstractAuthenticationToken authRequest;
String code = obtainParameter(request, "code"); String code = obtainParameter(request, "code");
if (Common.isEmpty(code)) { if (Common.isEmpty(code)) {
throw new AuthenticationServiceException("未获取到授权码"); throw new AuthenticationServiceException("未获取到授权码:"+code);
} }
// String result = restTemplate.getForObject(String.format(SecurityConstants.WX_GET_ACCOSS_TOKEN, wxConfig.getCorpid(), wxConfig.getCorpsecret()), String.class); // String result = restTemplate.getForObject(String.format(SecurityConstants.WX_GET_ACCOSS_TOKEN, wxConfig.getCorpid(), wxConfig.getCorpsecret()), String.class);
// if (Common.isEmpty(result)) { // if (Common.isEmpty(result)) {
// throw new AuthenticationServiceException("微信授权失败"); // throw new AuthenticationServiceException("微信授权失败");
......
...@@ -2,6 +2,7 @@ package com.yifu.cloud.plus.v1.yifu.auth.handler; ...@@ -2,6 +2,7 @@ package com.yifu.cloud.plus.v1.yifu.auth.handler;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.yifu.cloud.plus.v1.yifu.auth.constants.SecurityConstants; import com.yifu.cloud.plus.v1.yifu.auth.constants.SecurityConstants;
...@@ -164,6 +165,7 @@ public class YifuClientLoginSuccessHandler implements AuthenticationSuccessHandl ...@@ -164,6 +165,7 @@ public class YifuClientLoginSuccessHandler implements AuthenticationSuccessHandl
private void backResult(HttpServletResponse response, R result) throws IOException { private void backResult(HttpServletResponse response, R result) throws IOException {
response.setCharacterEncoding(CharsetUtil.UTF_8); response.setCharacterEncoding(CharsetUtil.UTF_8);
response.setContentType(CommonConstants.CONTENT_TYPE); response.setContentType(CommonConstants.CONTENT_TYPE);
response.setStatus(HttpStatus.HTTP_OK);
PrintWriter printWriter = response.getWriter(); PrintWriter printWriter = response.getWriter();
printWriter.append(objectMapper.writeValueAsString(result)); printWriter.append(objectMapper.writeValueAsString(result));
} }
......
...@@ -2,6 +2,7 @@ package com.yifu.cloud.plus.v1.yifu.auth.handler; ...@@ -2,6 +2,7 @@ package com.yifu.cloud.plus.v1.yifu.auth.handler;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.yifu.cloud.plus.v1.yifu.auth.constants.SecurityConstants; import com.yifu.cloud.plus.v1.yifu.auth.constants.SecurityConstants;
...@@ -81,7 +82,7 @@ public class YifuWxLoginSuccessHandler implements AuthenticationSuccessHandler { ...@@ -81,7 +82,7 @@ public class YifuWxLoginSuccessHandler implements AuthenticationSuccessHandler {
scope.add("server"); scope.add("server");
TokenRequest tokenRequest = new TokenRequest(MapUtil.newHashMap(), "auth",scope, "password"); TokenRequest tokenRequest = new TokenRequest(MapUtil.newHashMap(), "auth",scope, "password");
//校验scope //校验scope
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(null); ClientDetails clientDetails = clientDetailsService.loadClientByClientId("auth");
new DefaultOAuth2RequestValidator().validateScope(tokenRequest, clientDetails); new DefaultOAuth2RequestValidator().validateScope(tokenRequest, clientDetails);
OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(clientDetails); OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(clientDetails);
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request, authentication); OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request, authentication);
...@@ -122,8 +123,10 @@ public class YifuWxLoginSuccessHandler implements AuthenticationSuccessHandler { ...@@ -122,8 +123,10 @@ public class YifuWxLoginSuccessHandler implements AuthenticationSuccessHandler {
private void backResult(HttpServletResponse response, R result) throws IOException { private void backResult(HttpServletResponse response, R result) throws IOException {
response.setCharacterEncoding(CharsetUtil.UTF_8); response.setCharacterEncoding(CharsetUtil.UTF_8);
response.setContentType(CommonConstants.CONTENT_TYPE); response.setContentType(CommonConstants.CONTENT_TYPE);
response.setStatus(HttpStatus.HTTP_OK);
PrintWriter printWriter = response.getWriter(); PrintWriter printWriter = response.getWriter();
printWriter.append(objectMapper.writeValueAsString(result)); printWriter.append(objectMapper.writeValueAsString(result));
log.info("登录成功返回结果1111111:"+objectMapper.writeValueAsString(result));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment