Skip to content

Commit c68d22d

Browse files
committed
JWT Initial Creation
1 parent 208acbc commit c68d22d

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
</properties>
2020

2121
<dependencies>
22+
<dependency>
23+
<groupId>io.jsonwebtoken</groupId>
24+
<artifactId>jjwt</artifactId>
25+
<version>0.9.1</version>
26+
</dependency>
2227
<dependency>
2328
<groupId>org.springframework.boot</groupId>
2429
<artifactId>spring-boot-starter-data-jpa</artifactId>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.example.apiRest.controller;
2+
3+
import com.example.apiRest.dto.LoginDTO;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.*;
6+
import javax.validation.Valid;
7+
8+
@RestController
9+
@RequestMapping("/auth")
10+
public class AutenticationController {
11+
12+
@PostMapping
13+
public ResponseEntity<?> autenticate(@RequestBody @Valid LoginDTO loginDTO) {
14+
System.out.println(loginDTO.getEmail());
15+
System.out.println(loginDTO.getPassword());
16+
17+
return ResponseEntity.ok().build();
18+
}
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.example.apiRest.dto;
2+
3+
public class LoginDTO {
4+
5+
private String email;
6+
private String password;
7+
8+
public void setEmail(String email) {
9+
this.email = email;
10+
}
11+
12+
public void setPassword(String password) {
13+
this.password = password;
14+
}
15+
16+
public String getEmail() {
17+
return email;
18+
}
19+
20+
public String getPassword() {
21+
return password;
22+
}
23+
}

src/main/java/com/example/apiRest/security/SecurityConfiguration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.security.config.annotation.web.builders.WebSecurity;
99
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1010
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
11+
import org.springframework.security.config.http.SessionCreationPolicy;
1112
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
1213

1314
@EnableWebSecurity
@@ -28,9 +29,11 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
2829
protected void configure(HttpSecurity http) throws Exception {
2930
http.authorizeRequests()
3031
.antMatchers(HttpMethod.GET, "/api/v1/films").permitAll()
31-
.antMatchers(HttpMethod.GET, "/films/*").permitAll()
32+
.antMatchers(HttpMethod.GET, "/api/v1/films/*").permitAll()
33+
.antMatchers(HttpMethod.POST, "/auth").permitAll()
3234
.anyRequest().authenticated()
33-
.and().formLogin();
35+
.and().csrf().disable()
36+
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
3437
}
3538

3639
//configuracoes de recusross estaticos (js, css, imagens, etc...)

0 commit comments

Comments
 (0)