mirror of https://github.com/jeecgboot/jeecg-boot
sas版本,swagger接口测试token无效返回下载文件,应该返回401错误json
parent
7ff70930ef
commit
52cd43d17c
|
@ -75,6 +75,7 @@ public class JwtUtil {
|
||||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
||||||
// issues/I4YH95浏览器显示乱码问题
|
// issues/I4YH95浏览器显示乱码问题
|
||||||
httpServletResponse.setHeader("Content-type", "text/html;charset=UTF-8");
|
httpServletResponse.setHeader("Content-type", "text/html;charset=UTF-8");
|
||||||
|
response.setContentType("application/json;charset=UTF-8");
|
||||||
Result jsonResult = new Result(code, errorMsg);
|
Result jsonResult = new Result(code, errorMsg);
|
||||||
jsonResult.setSuccess(false);
|
jsonResult.setSuccess(false);
|
||||||
OutputStream os = null;
|
OutputStream os = null;
|
||||||
|
|
|
@ -8,6 +8,8 @@ import com.nimbusds.jose.jwk.source.JWKSource;
|
||||||
import com.nimbusds.jose.proc.SecurityContext;
|
import com.nimbusds.jose.proc.SecurityContext;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.system.util.JwtUtil;
|
||||||
import org.jeecg.config.security.app.AppGrantAuthenticationConvert;
|
import org.jeecg.config.security.app.AppGrantAuthenticationConvert;
|
||||||
import org.jeecg.config.security.app.AppGrantAuthenticationProvider;
|
import org.jeecg.config.security.app.AppGrantAuthenticationProvider;
|
||||||
import org.jeecg.config.security.password.PasswordGrantAuthenticationConvert;
|
import org.jeecg.config.security.password.PasswordGrantAuthenticationConvert;
|
||||||
|
@ -64,6 +66,7 @@ import java.util.stream.Collectors;
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@EnableMethodSecurity
|
@EnableMethodSecurity
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
@ -87,14 +90,15 @@ public class SecurityConfig {
|
||||||
.authenticationProvider(new SocialGrantAuthenticationProvider(authorizationService, tokenGenerator())))
|
.authenticationProvider(new SocialGrantAuthenticationProvider(authorizationService, tokenGenerator())))
|
||||||
//开启OpenID Connect 1.0(其中oidc为OpenID Connect的缩写)。 访问 /.well-known/openid-configuration即可获取认证信息
|
//开启OpenID Connect 1.0(其中oidc为OpenID Connect的缩写)。 访问 /.well-known/openid-configuration即可获取认证信息
|
||||||
.oidc(Customizer.withDefaults());
|
.oidc(Customizer.withDefaults());
|
||||||
http
|
|
||||||
//将需要认证的请求,重定向到login页面行登录认证。
|
//将需要认证的请求,抛出异常,不跳转页面
|
||||||
.exceptionHandling((exceptions) -> exceptions
|
http.exceptionHandling(exceptions -> exceptions
|
||||||
.defaultAuthenticationEntryPointFor(
|
.authenticationEntryPoint((request, response, authException) -> {
|
||||||
new LoginUrlAuthenticationEntryPoint("/sys/login"),
|
// 记录详细的异常信息
|
||||||
new MediaTypeRequestMatcher(MediaType.TEXT_HTML)
|
log.error("接口访问失败,请求路径:{},错误信息:{}", request.getRequestURI(), authException.getMessage(), authException);
|
||||||
)
|
JwtUtil.responseError(response,401,authException.getMessage());
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
@ -195,6 +199,12 @@ public class SecurityConfig {
|
||||||
return config;
|
return config;
|
||||||
}))
|
}))
|
||||||
.csrf(AbstractHttpConfigurer::disable)
|
.csrf(AbstractHttpConfigurer::disable)
|
||||||
|
// 添加异常处理
|
||||||
|
.exceptionHandling(exceptions -> exceptions
|
||||||
|
.authenticationEntryPoint((request, response, authException) -> {
|
||||||
|
log.error("接口访问失败,请求路径:{},错误信息:{}", request.getRequestURI(), authException.getMessage(), authException);
|
||||||
|
JwtUtil.responseError(response,401,authException.getMessage());
|
||||||
|
}))
|
||||||
.oauth2ResourceServer(oauth2 -> oauth2.jwt(jwt -> jwt.jwtAuthenticationConverter(jeecgAuthenticationConvert)));
|
.oauth2ResourceServer(oauth2 -> oauth2.jwt(jwt -> jwt.jwtAuthenticationConverter(jeecgAuthenticationConvert)));
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue