我正在使用Spring Boot后端构建Angular应用。我集成了Spring Security,并添加了FontAwesome依赖项,例如Angular package.json
"dependencies": {
.....
"font-awesome": "^4.7.0",
.....
}
问题是Spring Security一直阻止FA的图标检索。 我的Spring Security配置如下:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable().
authorizeRequests()
.antMatchers("/","/generate-token", "/signup","/config","/saveConfig/","/get/file/*").permitAll()
.antMatchers("/assets/**").permitAll()
.antMatchers("/*.js").permitAll()
.antMatchers("/*.css").permitAll()
.antMatchers("/fonts/*").permitAll()
.antMatchers("/resources/*").permitAll()
.anyRequest().authenticated()
.and()
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http
.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
}
如何在Spring Security中允许FontAwesome?
答案 0 :(得分:2)
您允许任何与'/ fonts / *'匹配的请求都是匿名的,您对awesome字体的请求与该URL模式不匹配,因此可以将FontAwesome移到fonts文件夹下。 或为FontAwesome添加规则
APICall = () => {
fetch(‘Your http URL’, {
method: 'PATCH',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
‘X-Auth-Token’: bearerToken,
},
body: JSON.stringify({
moto: this.state.moto
})
}).then((response) => response.json())
.then((responseJson) => {
if(responseJson.statuscode == 1) {
Alert.alert('Success');
} else {
Alert.alert(responseJson.message);
}
}).catch((error) => {
console.error(error);
});
}