SpringBoot 401 UnAuthorized即使没有安全性 [英] SpringBoot 401 UnAuthorized even with out security
本文介绍了SpringBoot 401 UnAuthorized即使没有安全性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我没有使用Spring Security但它要求我进行身份验证。
I did not use Spring Security but it is asking me to authenticate.
URL的例外情况( http:// localhost:8080 / SpringJob / ExecuteJob ):
Exception for URL(http://localhost:8080/SpringJob/ExecuteJob):
{
"timestamp": 1500622875056,
"status": 401,
"error": "Unauthorized",
"message": "Bad credentials",
"path": "/SPPA/ExecuteSPPAJob"
}
----below log details
2017-07-21 13:15:35.210 INFO 19828 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/SpringJob] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-07-21 13:15:35.210 [http-nio-8080-exec-1] INFO
o.a.c.c.C.[.[localhost].[/SpringJob]-Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-07-21 13:15:35.211 INFO 19828 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-07-21 13:15:35.211 [http-nio-8080-exec-1] INFO
o.s.web.servlet.DispatcherServlet-FrameworkServlet 'dispatcherServlet': initialization started
2017-07-21 13:15:35.494 INFO 19828 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 282 ms
2017-07-21 13:15:35.494 [http-nio-8080-exec-1] INFO
o.s.web.servlet.DispatcherServlet-FrameworkServlet 'dispatcherServlet': initialization completed in 282 ms
application-dev.xml
application-dev.xml
#Spring Boot based configurations
management.security.enabled: "false"
spring.autoconfigure.exclude: "org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration"
spring.batch.job.enabled: false
server.contextPath: /SpringJob
build.gradle snippet
build.gradle snippet
plugins {
id 'jacoco'
id 'org.sonarqube' version '2.5'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: "no.nils.wsdl2java"
apply plugin: 'jacoco'
apply plugin: "org.sonarqube"
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-batch")
compile("org.springframework.boot:spring-boot-starter-mail")
//compile("org.springframework.boot:spring-boot-devtools")
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
compile group: 'org.apache.cxf', name: 'cxf-spring-boot-starter-jaxws', version: '3.1.10'
compile group: 'org.apache.cxf', name: 'cxf-rt-ws-security', version: '3.1.10'
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
控制器
@Controller
@EnableAutoConfiguration
@EnableBatchProcessing
public class MyController {
@Autowired
JobLauncher jobLauncher;
@RequestMapping("/ExecuteJob")
@ResponseBody
public String callPrelegalJob(@RequestParam("user") String userName, @RequestParam("password") String password) {
log.info("Job is to be launched from controller...");
}
}
推荐答案
尝试在 application.properties
文件中添加以下行
Try to add below lines in your application.properties
file
security.basic.enable: false
security.ignored=/**
根据spring doc,使用 security.ignored =
According to spring doc, use security.ignored=
要从默认值中排除的以逗号分隔的路径列表安全
路径
Comma-separated list of paths to exclude from the default secured paths
这篇关于SpringBoot 401 UnAuthorized即使没有安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文