Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable session on JWT demo #4

Open
havinhphu188 opened this issue Mar 20, 2020 · 0 comments
Open

Disable session on JWT demo #4

havinhphu188 opened this issue Mar 20, 2020 · 0 comments

Comments

@havinhphu188
Copy link

In your demo of JWT hibernate, It is necessary to disable the session, so that API can be truthly stateless. Otherwise, the cookies will be use to authenticate. That it can get the resource without using the token after login
https://github.com/loda-kun/spring-boot-learning/blob/master/spring-security-hibernate-jwt/src/main/java/me/loda/springsecurityhibernatejwt/WebSecurityConfig.java
@OverRide
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.cors() // Ngăn chặn request từ một domain khác
.and()
.authorizeRequests()
.antMatchers("/api/login").permitAll() // Cho phép tất cả mọi người truy cập vào địa chỉ này
.anyRequest().authenticated()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);; // Tất cả các request khác đều cần phải xác thực mới được truy cập

    // Thêm một lớp Filter kiểm tra jwt
    http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant