当我们提到路径时,两个星号而不是一个星号之间的区别是什么?
之前我正在调试我的Spring 3项目.我试图添加一个.swf
<spring:url var="flashy" value="/resources/images/flash.swf"/>
我的web.xml的ResourceServlet看起来像
<servlet-name>Resource Servlet </servlet-name>
<url-pattern>/resources/*</url-pattern>
Run Code Online (Sandbox Code Playgroud)
但不幸的是我收到了这个错误:
WARN org.springframework.js.resources.ResourceServlet - An attempt to access a protected resource at /images/flash.swf was disallowed.
我发现它真的很奇怪,因为images文件夹中的所有图像都被访问了但是我的.swf怎么会受到"保护"?
后来,我决定改变/resources/*到/resources/**最后和它的工作.我的问题是......为什么?
我正在努力让CORS与Spring Security很好地配合,但它并不符合.我做了本文中描述的更改并更改此行applicationContext-security.xml已经有POST和GET请求适用于我的应用程序(暂时公开控制器方法,所以我可以测试CORS):
<intercept-url pattern="/**" access="isAuthenticated()" /><intercept-url pattern="/**" access="permitAll" />不幸的是,通过AJAX允许Spring Security登录的以下URL没有响应:http://localhost:8080/mutopia-server/resources/j_spring_security_check.我正在从AJAX请求http://localhost:80到http://localhost:8080.
在尝试访问时,j_spring_security_check我(pending)在Chrome中获取OPTIONS预检请求,并且AJAX调用返回HTTP状态代码0和消息"错误".
预检成功使用HTTP状态代码302,然后我仍然直接获得我的AJAX请求的错误回调,其中HTTP状态为0,消息为"error".


function get(url, json) {
var args = {
type: 'GET',
url: url,
// async: false,
// crossDomain: true,
xhrFields: {
withCredentials: false
},
success: function(response) {
console.debug(url, response);
},
error: function(xhr) {
console.error(url, xhr.status, xhr.statusText);
}
};
if (json) {
args.contentType = 'application/json'
}
$.ajax(args);
}
function …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 Spring Boot 应用程序中启用 CORS,但它根本不起作用。
我试过了
@CrossOrigin 注解我不知道此时如何解决这个问题,也不知道 CORS 不起作用的问题是什么。
我的代码
控制器
@RestController
public class DbController {
@Autowired
private IDAO conn;
@CrossOrigin
@GetMapping("/foo")
public List<Foo> getFoo() {
return conn.getFooFromDao();
}
}
Run Code Online (Sandbox Code Playgroud)
道
@Repository
public class DaoImpl implements IDAO {
@Autowired
private JdbcTemplate temp;
public List<Foo> getFooFromDao() {
List<Foo> data = new ArrayList<>();
String sql = "SELECT fooName FROM BigFoo ORDER BY fooName ASC;";
data.addAll(temp.query(sql, new BeanPropertyRowMapper(BigFoo.class)));
return data;
}
} …Run Code Online (Sandbox Code Playgroud) 我正在通过分解此GitHub示例中的三个互连应用程序来学习Spring Cloud和Spring OAuth2 .当我打开了/oauth/revoke-token在终端authserver应用程序,然后调用它的ui应用有http://localhost:9999/uaa/logout,调试日志为authserver应用程序提供了以下错误信息,而拒绝退出请求:
Request 'OPTIONS /logout' doesn't match 'POST /logout
Run Code Online (Sandbox Code Playgroud)
在应用程序调用注销功能时,需要对示例GitHub应用程序中的代码进行哪些具体更改才能使全局注销成功?uihello.js
初始努力:
到目前为止我所做的更改包括:
将以下@Bean定义添加到AuthserverApplication.java:
@Bean
public TokenStore tokenStore() {return new InMemoryTokenStore();}
Run Code Online (Sandbox Code Playgroud)
demo在authserver应用程序包中添加以下控制器类:
@Configuration
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
@Autowired
TokenStore tokenStore;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore);
}
@RequestMapping(value = "/oauth/revoke-token", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public void logout(HttpServletRequest …Run Code Online (Sandbox Code Playgroud) spring spring-security spring-boot spring-cloud spring-oauth2
最近我在我的Springboot和基于Angualr2的应用程序中引入了JWT身份验证.在那里我尝试通过在我的Angualr代码中传递如下的JWT令牌来执行POST请求
save(jobId: number, taskId: number, note: Note) {
return this.http.post(environment.APIENDPOINT + '/jobs/' + jobId + '/tasks/' + taskId + '/notes', note, this.setHeaders()).map((response: Response) => response.json());
}Run Code Online (Sandbox Code Playgroud)
private setHeaders() {
// create authorization header with jwt token
let currentUser = JSON.parse(localStorage.getItem('currentUser'));
console.log("Current token---"+ currentUser.token);
if (currentUser && currentUser.token) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('authorization','Bearer '+ currentUser.token);
let r = new RequestOptions({ headers: headers })
return r;
}
}Run Code Online (Sandbox Code Playgroud)
但是在服务器端它返回状态代码401.问题是在Springboot端它检查授权头如下,它返回null
String authToken = request.getHeader("authorization ");
Run Code Online (Sandbox Code Playgroud)
然后,我查看了请求标头,并在Access-Control-Request-Headers下具有授权标头,如下所示.但它对服务器端是不可见的.
然后我进一步阅读并发现这可能是CORS配置的问题.所以我修改了我的CORS配置过滤器以使addExposedHeader如下所示
@Bean
public …Run Code Online (Sandbox Code Playgroud) cors ×3
spring ×3
spring-boot ×3
java ×2
angular ×1
httprequest ×1
javascript ×1
resources ×1
spring-cloud ×1
url-pattern ×1
web ×1