首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >403使用带有Spring安全性的Vaadin的CSRF令牌错误

403使用带有Spring安全性的Vaadin的CSRF令牌错误
EN

Stack Overflow用户
提问于 2017-06-01 07:46:24
回答 1查看 1.6K关注 0票数 2

我试图在vaadin应用程序中实现spring安全性,但是我遇到了一个问题,在登录到页面之后,它显示了一个错误:

{“状态”:403,“错误”:“禁止”,“消息”:“无法验证所提供的CSRF令牌,因为找不到会话。”,“路径”:“/”}

我尝试了很多事情,但都没有成功,下面是我的标准安全配置类:

代码语言:javascript
复制
//SecurityConfig.java    
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
            .withUser("user")
            .password("password")
            .roles("USER");
    }
}

控制器类:

代码语言:javascript
复制
//HomeController.java
@RestController
public class HomeController {

    @GetMapping("/")
    public String index() {
        return "Welcome to the home page!";
    }

@GetMapping("/error")
public String error(){
    return "Error!";
}

}

和Vaadin UI类

代码语言:javascript
复制
//VaadinUI.java
@SpringUI
public class VaadinUI extends UI {
    VerticalLayout layout = new VerticalLayout();

    com.vaadin.ui.Label label = new com.vaadin.ui.Label("Witaj");

    @Autowired
    public VaadinUI() {}

   @Override
   protected void init(VaadinRequest request) {
       setContent(layout);
       layout.addComponent(label);
   }

}

还有我的pom.xml

代码语言:javascript
复制
//pom.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>example.com</groupId>
        <artifactId>LDAPSpringInitializr</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>

        <name>LDAPSpringInitializr</name>
        <description>Demo project for Spring Boot</description>

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.3.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
            <vaadin.version>8.0.5</vaadin.version>
        </properties>

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-ldap</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-spring-boot-starter</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>

            <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>

        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>vaadin-bom</artifactId>
                    <version>${vaadin.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>


    </project>

如何将Vaadin与弹簧安全结合起来?稍后,我希望将spring安全性与LDAP连接起来。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-01 07:55:36

我不太熟悉Vaadin,但这篇文章https://vaadin.com/blog/-/blogs/filter-based-spring-security-in-vaadin-applications建议Vaadin已经提供了CSRF保护,所以您可以通过

代码语言:javascript
复制
@Override
protected void configure(final HttpSecurity httpSecurity) throws Exception {
    httpSecurity.csrf().disable();
}

在你的SecurityConfig里。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44301518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档