相关疑难解决方法(0)

请求的资源错误上没有"Access-Control-Allow-Origin"标头

我正在尝试获取新闻网站的Feed.我以为我会使用google的feed API将feedburner Feed转换为json.以下网址将以json格式从Feed返回10个帖子.http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http://feeds.feedburner.com/mathrubhumi

我使用以下代码来获取上面的url的内容

$.ajax({
  type: "GET",
  dataType: "jsonp",
  url: "http://ajax.googleapis.com/ajax/services/feed/load",
  data: {
    "v": "1.0",
    "num": "10",
    "q": "http://feeds.feedburner.com/mathrubhumi"
  },
  success: function(result) {
    //.....
  }
});
Run Code Online (Sandbox Code Playgroud)

但它没有工作,我收到以下错误

XMLHttpRequest无法加载 http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http%3A%2F%2Ffeeds.feedburner.com%2Fmathrubhumi.请求的资源上不存在"Access-Control-Allow-Origin"标头.原产地" :HTTP //本地主机,因此"是不允许访问.

我该如何解决?

javascript ajax jquery json cors

89
推荐指数
3
解决办法
44万
查看次数

CORS弹簧靴和angularjs无法正常工作

我试图在另一个应用程序(spring-boot应用程序)上调用REST端点(angularjs).应用程序在以下主机和端口上运行.

  • REST应用程序,使用spring boot, http://localhost:8080
  • HTML应用程序,使用angularjs, http://localhost:50029

我也在使用spring-securityspring-boot应用程序.从HTML应用程序,我可以对REST应用程序进行身份验证,但此后,我仍然无法访问任何REST端点.例如,我有一个如下定义的angularjs服务.

adminServices.factory('AdminService', ['$resource', '$http', 'conf', function($resource, $http, conf) {
    var s = {};
    s.isAdminLoggedIn = function(data) {
        return $http({
            method: 'GET',
            url: 'http://localhost:8080/api/admin/isloggedin',
            withCredentials: true,
            headers: {
                'X-Requested-With': 'XMLHttpRequest'
            }
        });
    };
    s.login = function(username, password) {
        var u = 'username=' + encodeURI(username);
        var p = 'password=' + encodeURI(password);
        var r = 'remember_me=1';
        var data = u + '&' + p + '&' + r;

        return $http({
            method: 'POST',
            url: 'http://localhost:8080/login',
            data: …
Run Code Online (Sandbox Code Playgroud)

rest spring-mvc cors angularjs spring-boot

71
推荐指数
7
解决办法
12万
查看次数

你能完全禁用Spring中的CORS支持吗?

正如描述的CORS预检要求失败,因为一个标准的头,如果你发送请求到OPTIONS与端点OriginAccess-Control-Request-Method设置,那么他们得到的Spring框架截获头,和你的方法没有得到执行.接受的解决方案是使用@CrossOrigin注释来阻止Spring返回a 403.但是,我使用Swagger Codegen生成我的API代码,所以我只想禁用它并OPTIONS手动实现我的响应.

那么你可以在Spring中禁用CORS拦截吗?

java spring spring-mvc swagger-codegen

18
推荐指数
7
解决办法
3万
查看次数

访问被拒绝(用户是匿名的);重定向到身份验证入口点

我正在尝试将 spring oauth2(基于 Java 的配置而不是引导)与 angular 6 集成,

我的 WebSecurityConfigurerAdapter.java 文件是:

package com.novowash.authentication;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.approval.ApprovalStore;
import org.springframework.security.oauth2.provider.approval.TokenApprovalStore;
import org.springframework.security.oauth2.provider.approval.TokenStoreUserApprovalHandler;
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class OAuth2SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private ClientDetailsService clientDetailsService;

    @Autowired
    NovoAuthenticationProvider novoAuthenticationProvider;

    @Autowired
    UserDetailsServiceImpl userDetailsServiceImpl;

    @Autowired
    private PasswordEncoder userPasswordEncoder;


    @Autowired
    @Qualifier("dataSource") …
Run Code Online (Sandbox Code Playgroud)

spring angular

10
推荐指数
1
解决办法
2万
查看次数

Spring Oauth2 中的 CORS 错误

我正在使用 Spring 安全性和 Oauth2。但是我是 Spring Oauth2 的新手,当前端访问资源时出现 CORS 错误。

我正在使用以下过滤器来允许其他域访问资源:

@Component
@Order(Integer.MAX_VALUE)
public class SimpleCORSFilter implements Filter {

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;
        response.setHeader("Access-Control-Allow-Credentials", "True");
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
        chain.doFilter(req, res);
    }


    public void init(FilterConfig filterConfig) {}
    public void destroy() {}

}
Run Code Online (Sandbox Code Playgroud)

我编写了以下代码以允许在我的 SecurityConfiguration.java 中使用公共资源。

@Override
protected void configure(HttpSecurity http) throws Exception {
             http
        .authorizeRequests().antMatchers("/social/facebook/**","/register/**","/public/**").permitAll().and()
        .authorizeRequests().antMatchers("/user/**").hasRole("USER").and() …
Run Code Online (Sandbox Code Playgroud)

spring oauth spring-mvc spring-security cors

5
推荐指数
2
解决办法
7696
查看次数

Spring Security中的相同站点Cookie

在Spring Security中可以设置Same-site Cookie标志吗?请参阅:https : //tools.ietf.org/html/draft-west-first-party-cookies-07 ,如果没有,请问是否有增加支持的路线图?某些浏览器(例如Chrome)已经支持。TH

security cookies spring-security jsessionid csrf-protection

5
推荐指数
5
解决办法
4253
查看次数

Tomcat 8 和 Spring Security Cors

我正在尝试配置 Spring Security 以使其支持 CORS。感谢这篇文章Spring security CORS Filter,我已经使用 Spring Boot 使用以下配置代码使其在我的本地主机上工作:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.cors()
        .and()
        .antMatcher("/api/**")
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .authorizeRequests()
        .antMatchers(HttpMethod.POST, "/api/login").permitAll()
        .antMatchers(HttpMethod.GET, "/api/websocket/**").permitAll()
        .antMatchers("/api/**").authenticated()
        .and()
        .addFilterBefore(new JWTLoginFilter("/api/login", HttpMethod.POST, authenticationManager(), tokenAuthenticationService, myUserService), UsernamePasswordAuthenticationFilter.class)
        .addFilterBefore(new JWTAuthenticationFilter(tokenAuthenticationService), UsernamePasswordAuthenticationFilter.class)
        .csrf().disable();
    }

@Bean
public CorsConfigurationSource corsConfigurationSource() {
    final CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowedOrigins(ImmutableList.of("*"));
    configuration.setAllowedMethods(ImmutableList.of("HEAD",
            "GET", "POST", "PUT", "DELETE", "PATCH"));
    // setAllowCredentials(true) is important, otherwise:
    // The value of the …
Run Code Online (Sandbox Code Playgroud)

java spring tomcat

5
推荐指数
1
解决办法
3443
查看次数