简体   繁体   English

Spring Oauth2 Angularjs登录不是Woking

[英]Spring Oauth2 Angularjs Login Not Woking

Currently I'm developing Spring OAuth2 security project with Angularjs. 目前我正在使用Angularjs开发Spring OAuth2安全项目。 I'm taking a token with oauth server and I'm parsing to headers but when I try to redirect to home page I'm thrown by "Full authentication is required to access this resource" but I loged in and client server gives an anonymousUser and access denied. 我正在使用oauth服务器的令牌,我正在解析为标题但是当我尝试重定向到主页时,我被抛出“需要完全身份验证才能访问此资源”但我插入并且客户端服务器提供了匿名用户并拒绝访问。

@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {

    web
            .ignoring()
            .antMatchers("/login.html")
            .antMatchers("/js/**")
            .antMatchers("/css/**")
            .antMatchers("/metronic/css/**")
            .antMatchers("/metronic/js/**")
            .antMatchers("/metronic/image/**")
            .antMatchers("/image/**")
            .antMatchers("/language/**")
            .antMatchers("/404.html")
            .antMatchers("/logout")
            .antMatchers("/kilitEkrani.html")
            .antMatchers("/metronic/css/fonts/**")
            .antMatchers("/metronic/fonts/**");

}

@Override
public void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests().antMatchers("/css/**", "/metronic/css/**").permitAll()
            .and().authorizeRequests().antMatchers("/metronic/image/**", "/image/**", "/metronic/css/fonts/**", "/metronic/fonts/**").permitAll()
            .and().authorizeRequests().antMatchers("/js/**", "/metronic/js/**").permitAll()
            .and().httpBasic().and().authorizeRequests()
            .antMatchers("/login.html", "/language/**", "/api/kullanici/user", "/logout", "/kilitEkrani.html", "/404.html").permitAll()
            .anyRequest().authenticated().and()
            .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class).csrf().csrfTokenRepository(csrfTokenRepository()).and()
            .logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .logoutSuccessUrl("/login.html")
            .permitAll().and().csrf().disable();
}

private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class
                    .getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}

private CsrfTokenRepository csrfTokenRepository() {
    HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
    repository.setHeaderName("X-XSRF-TOKEN");
    return repository;
}
}

This is my security config. 这是我的安全配置。 Am I missing something? 我错过了什么吗? Help please... 请帮助...

I think the problem is that you make use of basic authentication in the auth server. 我认为问题是您在auth服务器中使用基本身份验证。 You can try to disable the basic authentication and use form authentication instead. 您可以尝试禁用基本身份验证并使用表单身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM