Skip to content

Commit 67975fe

Browse files
rahulrahul
rahul
authored and
rahul
committed
first commit
1 parent 0d1e0b5 commit 67975fe

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed

pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@
4646
<version>0.9.0</version>
4747
</dependency>
4848

49+
<dependency>
50+
<groupId>org.springframework.security</groupId>
51+
<artifactId>spring-security-test</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-starter-test</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.postgresql</groupId>
63+
<artifactId>postgresql</artifactId>
64+
<version>42.2.3</version>
65+
</dependency>
66+
67+
4968
</dependencies>
5069

5170
<build>

src/main/java/com/baghaniya/springsecurity/controller/AuthController.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
import org.springframework.security.core.Authentication;
2020
import org.springframework.security.core.context.SecurityContextHolder;
2121
import org.springframework.security.crypto.password.PasswordEncoder;
22-
import org.springframework.web.bind.annotation.PostMapping;
23-
import org.springframework.web.bind.annotation.RequestBody;
24-
import org.springframework.web.bind.annotation.RequestMapping;
25-
import org.springframework.web.bind.annotation.RestController;
22+
import org.springframework.web.bind.annotation.*;
2623
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
2724

2825
import javax.validation.Valid;
@@ -51,7 +48,7 @@ public class AuthController {
5148
@Autowired
5249
JwtTokenProvider tokenProvider;
5350

54-
@PostMapping("/signin")
51+
@RequestMapping(value = "/signin", method = RequestMethod.POST)
5552
public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginRequest loginRequest) {
5653

5754
Authentication authentication = authenticationManager.authenticate(
@@ -67,7 +64,7 @@ public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginRequest login
6764
return ResponseEntity.ok(new JwtAuthenticationResponse(jwt));
6865
}
6966

70-
@PostMapping("/signup")
67+
@RequestMapping(value = "/signup", method = RequestMethod.POST)
7168
public ResponseEntity<?> registerUser(@Valid @RequestBody SignUpRequest signUpRequest) {
7269
if(userRepository.existsByUsername(signUpRequest.getUsername())) {
7370
return new ResponseEntity(new ApiResponse(false, "Username is already taken!"),
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baghaniya.springsecurity.controller;
2+
3+
import org.springframework.security.access.prepost.PreAuthorize;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RequestMethod;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
/**
9+
* Created by RAHUL on Jul, 2018
10+
*/
11+
@RestController
12+
@RequestMapping(value = "/config")
13+
public class CarrierController {
14+
15+
@RequestMapping(value = "/carriers", method = RequestMethod.GET)
16+
@PreAuthorize("hasRole('USER')")
17+
public String getCarrier(){
18+
return "carriers";
19+
}
20+
21+
}

src/main/resources/application.properties

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
server.compression.enabled=true
33

44
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
5-
#spring.datasource.url= jdbc:postgresql://localhost:5432/postgres
6-
#spring.datasource.username= postgres
7-
#spring.datasource.password= postgres
5+
spring.datasource.url= jdbc:postgresql://localhost:5432/security
6+
spring.datasource.username= postgres
7+
spring.datasource.password= postgres
8+
app.datasource.driver-class-name=org.postgresql.Driver
9+
810

911

1012
## Hibernate Properties
@@ -13,6 +15,8 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialec
1315
spring.jpa.hibernate.ddl-auto = update
1416
spring.jpa.generate-ddl=true
1517
spring.jpa.show-sql=true
18+
spring.jpa.hibernate.show_sql=true
19+
1620

1721
## Hibernate Logging
1822
logging.level.org.hibernate.SQL= DEBUG

0 commit comments

Comments
 (0)