Skip to content

Commit 224ddad

Browse files
committed
Auth users definitions
1 parent 4a1dc39 commit 224ddad

5 files changed

Lines changed: 22 additions & 11 deletions

File tree

pom.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@
7777
</exclusion>
7878
</exclusions>
7979
</dependency>
80-
<dependency>
81-
<groupId>javax.validation</groupId>
82-
<artifactId>validation-api</artifactId>
83-
<version>1.1.0.Final</version>
84-
</dependency>
80+
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation -->
81+
<dependency>
82+
<groupId>org.springframework.boot</groupId>
83+
<artifactId>spring-boot-starter-validation</artifactId>
84+
<!-- <version>2.3.0</version>-->
85+
</dependency>
86+
8587
<dependency>
8688
<groupId>org.glassfish</groupId>
8789
<artifactId>javax.el</artifactId>

src/main/java/com/example/apiRest/controller/FilmsController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.example.apiRest.dto.DetailsFilmsDTOResponse;
44
import com.example.apiRest.dto.FilmsDTO;
55
import com.example.apiRest.dto.FilmsDTOResponse;
6-
import com.example.apiRest.model.Films;
76
import com.example.apiRest.response.Response;
87
import com.example.apiRest.service.FilmsService;
98
import io.swagger.annotations.Api;

src/main/java/com/example/apiRest/dto/FilmsDTO.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
import org.hibernate.validator.constraints.Length;
66
import org.hibernate.validator.constraints.NotBlank;
77
import org.hibernate.validator.constraints.Range;
8-
98
import javax.persistence.Column;
10-
import javax.persistence.GeneratedValue;
11-
import javax.persistence.GenerationType;
12-
import javax.persistence.Id;
139
import javax.validation.constraints.NotNull;
1410
import java.io.Serializable;
1511

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,18 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
4444
@Override
4545
protected void configure(HttpSecurity http) throws Exception {
4646
http.authorizeRequests()
47+
.antMatchers("/h2-console/**").permitAll()
4748
.antMatchers(HttpMethod.GET, "/api/v1/films").permitAll()
4849
.antMatchers(HttpMethod.GET, "/api/v1/films/*").permitAll()
4950
.antMatchers(HttpMethod.GET, "/actuator/**").permitAll()
5051
.antMatchers(HttpMethod.POST, "/auth").permitAll()
52+
.antMatchers(HttpMethod.POST, "/api/v1/films").hasRole("ADMIN")
53+
.antMatchers(HttpMethod.DELETE, "/api/v1/films/*").hasRole("ADMIN")
54+
.antMatchers(HttpMethod.PUT, "/api/v1/films").hasRole("ADMIN")
5155
.anyRequest().authenticated()
5256
.and().csrf().disable()
5357
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
58+
.and().headers().frameOptions().sameOrigin()
5459
.and().addFilterBefore(new AuthenticationViaTokenFilter(tokenService, userRepository), UsernamePasswordAuthenticationFilter.class);
5560
}
5661

src/main/resources/data.sql

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ INSERT INTO TB_FILMS(name, genre, release_year) VALUES('enter the dragon', 'adve
44
INSERT INTO TB_FILMS(name, genre, release_year) VALUES('enter the dragon 2', 'adventure', 1974);
55
INSERT INTO TB_FILMS(name, genre, release_year) VALUES('enter the dragon 3', 'adventure', 1977);
66

7-
INSERT INTO USER(name, email, password) VALUES('Admin', '[email protected]', '$2a$10$XAzYDwFxPJNAshMotBsHU.tyAYICXeGZWfqkG6hu.pSc7RlLVQA1S');
7+
INSERT INTO USER(name, email, password) VALUES('admin', '[email protected]', '$2a$10$XAzYDwFxPJNAshMotBsHU.tyAYICXeGZWfqkG6hu.pSc7RlLVQA1S');
8+
INSERT INTO USER(name, email, password) VALUES('user', '[email protected]', '$2a$10$XAzYDwFxPJNAshMotBsHU.tyAYICXeGZWfqkG6hu.pSc7RlLVQA1S');
9+
10+
INSERT INTO PROFILE(id, name) VALUES(1, 'ROLE_ADMIN');
11+
INSERT INTO PROFILE(id, name) VALUES(2, 'ROLE_USER');
12+
13+
INSERT INTO USER_PROFILES(user_id, profiles_id) VALUES(1, 1);
14+
INSERT INTO USER_PROFILES(user_id, profiles_id) VALUES(2, 2);
15+
16+

0 commit comments

Comments
 (0)