Parcourir la source

u may want to reset to prev commit

woat il y a 6 ans
Parent
révision
9db5a79120

+ 58
- 0
Back-End/pom.xml Voir le fichier

@@ -27,6 +27,34 @@
27 27
     <dependencies>
28 28
         <dependency>
29 29
             <groupId>org.springframework.boot</groupId>
30
+            <artifactId>spring-boot-starter-websocket</artifactId>
31
+        </dependency>
32
+
33
+        <dependency>
34
+            <groupId>org.webjars</groupId>
35
+            <artifactId>webjars-locator-core</artifactId>
36
+        </dependency>
37
+
38
+        <dependency>
39
+            <groupId>org.webjars</groupId>
40
+            <artifactId>sockjs-client</artifactId>
41
+            <version>1.0.2</version>
42
+        </dependency>
43
+
44
+        <dependency>
45
+            <groupId>org.webjars</groupId>
46
+            <artifactId>stomp-websocket</artifactId>
47
+            <version>2.3.3</version>
48
+        </dependency>
49
+
50
+        <dependency>
51
+            <groupId>org.json</groupId>
52
+            <artifactId>json</artifactId>
53
+            <version>20180130</version>
54
+        </dependency>
55
+
56
+        <dependency>
57
+            <groupId>org.springframework.boot</groupId>
30 58
             <artifactId>spring-boot-starter-data-jpa</artifactId>
31 59
         </dependency>
32 60
         <dependency>
@@ -48,6 +76,36 @@
48 76
             <artifactId>spring-boot-starter-test</artifactId>
49 77
             <scope>test</scope>
50 78
         </dependency>
79
+
80
+        <dependency>
81
+            <groupId>org.projectlombok</groupId>
82
+            <artifactId>lombok</artifactId>
83
+            <version>1.18.0</version>
84
+            <scope>provided</scope>
85
+        </dependency>
86
+
87
+        <dependency>
88
+            <groupId>org.springframework.boot</groupId>
89
+            <artifactId>spring-boot-starter-security</artifactId>
90
+            <version>2.0.3.RELEASE</version>
91
+        </dependency>
92
+
93
+        <dependency>
94
+            <groupId>org.springframework.security</groupId>
95
+            <artifactId>spring-security-core</artifactId>
96
+            <version>5.0.6.RELEASE</version>
97
+        </dependency>
98
+
99
+        <dependency>
100
+            <groupId>org.springframework.security</groupId>
101
+            <artifactId>spring-security-jwt</artifactId>
102
+        </dependency>
103
+
104
+        <dependency>
105
+            <groupId>io.jsonwebtoken</groupId>
106
+            <artifactId>jjwt</artifactId>
107
+            <version>0.9.1</version>
108
+        </dependency>
51 109
     </dependencies>
52 110
 
53 111
     <build>

+ 8
- 0
Back-End/src/main/java/com/zipline/back/BackEndZipLineYellowApplication.java Voir le fichier

@@ -2,10 +2,18 @@ package com.zipline.back;
2 2
 
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+import org.springframework.context.annotation.Bean;
6
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
5 7
 
6 8
 @SpringBootApplication
7 9
 public class BackEndZipLineYellowApplication {
10
+    @Bean
11
+    public BCryptPasswordEncoder passwordEncoder() {
12
+        return new BCryptPasswordEncoder();
13
+    }
14
+
8 15
     public static void main(String[] args) {
9 16
         SpringApplication.run(BackEndZipLineYellowApplication.class, args);
10 17
     }
18
+
11 19
 }

+ 64
- 0
Back-End/src/main/java/com/zipline/back/config/JWTAuthenticationFilter.java Voir le fichier

@@ -0,0 +1,64 @@
1
+package com.zipline.back.config;
2
+
3
+import com.fasterxml.jackson.databind.ObjectMapper;
4
+import com.zipline.back.model.User;
5
+import io.jsonwebtoken.Jwts;
6
+import io.jsonwebtoken.SignatureAlgorithm;
7
+import org.springframework.security.authentication.AuthenticationManager;
8
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
9
+import org.springframework.security.core.Authentication;
10
+import org.springframework.security.core.AuthenticationException;
11
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
12
+
13
+import javax.servlet.FilterChain;
14
+import javax.servlet.Servlet;
15
+import javax.servlet.ServletException;
16
+import javax.servlet.http.HttpServletRequest;
17
+import javax.servlet.http.HttpServletResponse;
18
+import java.io.IOException;
19
+import java.util.ArrayList;
20
+import java.util.Date;
21
+
22
+import static com.zipline.back.config.SecurityConstants.*;
23
+
24
+public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
25
+    private AuthenticationManager authenticationManager;
26
+
27
+    public JWTAuthenticationFilter(AuthenticationManager authenticationManager) {
28
+        this.authenticationManager = authenticationManager;
29
+        setUsernameParameter("githubId");
30
+        setPasswordParameter("password");
31
+    }
32
+
33
+    @Override
34
+    public Authentication attemptAuthentication(HttpServletRequest req,
35
+                                                HttpServletResponse res) throws AuthenticationException {
36
+        try {
37
+            User credentials = new ObjectMapper().readValue(req.getInputStream(), User.class);
38
+
39
+            return authenticationManager
40
+                    .authenticate(
41
+                            new UsernamePasswordAuthenticationToken(
42
+                                    credentials.getGithubId(),
43
+                                    credentials.getPassword(),
44
+                                    new ArrayList<>())
45
+                    );
46
+        } catch (IOException e) {
47
+            throw new RuntimeException(e);
48
+        }
49
+    }
50
+
51
+    @Override
52
+    protected void successfulAuthentication(HttpServletRequest req,
53
+                                            HttpServletResponse res,
54
+                                            FilterChain chain,
55
+                                            Authentication auth) throws IOException, ServletException {
56
+        User user = (User) auth.getPrincipal();
57
+        String token = Jwts.builder()
58
+                .setSubject(user.getGithubId())
59
+                .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
60
+                .signWith(SignatureAlgorithm.ES512, SECRET.getBytes())
61
+                .compact();
62
+        res.addHeader(HEADER_STRING, TOKEN_PREFIX + token);
63
+    }
64
+}

+ 58
- 0
Back-End/src/main/java/com/zipline/back/config/JWTAuthorizationFilter.java Voir le fichier

@@ -0,0 +1,58 @@
1
+package com.zipline.back.config;
2
+
3
+import io.jsonwebtoken.Jwts;
4
+import org.springframework.security.authentication.AuthenticationManager;
5
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
6
+import org.springframework.security.core.context.SecurityContextHolder;
7
+import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
8
+
9
+import javax.servlet.FilterChain;
10
+import javax.servlet.ServletException;
11
+import javax.servlet.http.HttpServletRequest;
12
+import javax.servlet.http.HttpServletResponse;
13
+import java.io.IOException;
14
+import java.util.ArrayList;
15
+
16
+import static com.zipline.back.config.SecurityConstants.HEADER_STRING;
17
+import static com.zipline.back.config.SecurityConstants.SECRET;
18
+import static com.zipline.back.config.SecurityConstants.TOKEN_PREFIX;
19
+
20
+public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
21
+    public JWTAuthorizationFilter(AuthenticationManager authManager) {
22
+        super(authManager);
23
+    }
24
+
25
+    @Override
26
+    protected void doFilterInternal(HttpServletRequest req,
27
+                                    HttpServletResponse res,
28
+                                    FilterChain chain) throws IOException, ServletException {
29
+        String header = req.getHeader(HEADER_STRING);
30
+
31
+        if (header == null || !header.startsWith(TOKEN_PREFIX)) {
32
+            chain.doFilter(req, res);
33
+            return;
34
+        }
35
+
36
+        UsernamePasswordAuthenticationToken authentication = getAuthentication(req);
37
+
38
+        SecurityContextHolder.getContext().setAuthentication(authentication);
39
+        chain.doFilter(req, res);
40
+    }
41
+
42
+    private UsernamePasswordAuthenticationToken getAuthentication(HttpServletRequest req) {
43
+        String token = req.getHeader(HEADER_STRING);
44
+        if (token != null) {
45
+            String user = Jwts.parser()
46
+                    .setSigningKey(SECRET.getBytes())
47
+                    .parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
48
+                    .getBody()
49
+                    .getSubject();
50
+
51
+            if (user != null) {
52
+                return new UsernamePasswordAuthenticationToken(user, null, new ArrayList<>());
53
+            }
54
+            return null;
55
+        }
56
+        return null;
57
+    }
58
+}

+ 16
- 0
Back-End/src/main/java/com/zipline/back/config/SecurityConstants.java Voir le fichier

@@ -0,0 +1,16 @@
1
+package com.zipline.back.config;
2
+
3
+import com.zipline.back.model.User;
4
+import io.jsonwebtoken.Jwts;
5
+import io.jsonwebtoken.SignatureAlgorithm;
6
+
7
+import java.security.PrivateKey;
8
+import java.util.Date;
9
+
10
+public class SecurityConstants {
11
+    public static final String SECRET = "Secret";
12
+    public static final long EXPIRATION_TIME = 5*60*100;
13
+    public static final String TOKEN_PREFIX = "Bearer ";
14
+    public static final String HEADER_STRING = "Authorization";
15
+    public static final String SIGN_UP_URL = "/register";
16
+}

+ 53
- 0
Back-End/src/main/java/com/zipline/back/config/WebSecurity.java Voir le fichier

@@ -0,0 +1,53 @@
1
+package com.zipline.back.config;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.http.HttpMethod;
5
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
6
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
8
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9
+import org.springframework.security.config.http.SessionCreationPolicy;
10
+import org.springframework.security.core.userdetails.UserDetailsService;
11
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
12
+import org.springframework.web.cors.CorsConfiguration;
13
+import org.springframework.web.cors.CorsConfigurationSource;
14
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
15
+
16
+import static com.zipline.back.config.SecurityConstants.SIGN_UP_URL;
17
+
18
+@EnableWebSecurity
19
+public class WebSecurity extends WebSecurityConfigurerAdapter {
20
+    private UserDetailsService userDetailsService;
21
+    private BCryptPasswordEncoder passwordEncoder;
22
+
23
+    public WebSecurity(UserDetailsService userDetailsService,
24
+                       BCryptPasswordEncoder passwordEncoder) {
25
+        this.userDetailsService = userDetailsService;
26
+        this.passwordEncoder = passwordEncoder;
27
+    }
28
+
29
+    @Override
30
+    protected void configure(HttpSecurity http) throws Exception {
31
+        http.cors().and().csrf().disable().authorizeRequests()
32
+                .antMatchers("/**").permitAll();
33
+//                .antMatchers(HttpMethod.POST, SIGN_UP_URL).permitAll()
34
+//                .anyRequest().authenticated()
35
+//                .and()
36
+//                .addFilter(new JWTAuthenticationFilter(authenticationManager()))
37
+//                .addFilter(new JWTAuthorizationFilter(authenticationManager()))
38
+//                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
39
+    }
40
+
41
+    @Override
42
+    public void configure(AuthenticationManagerBuilder auth) throws Exception {
43
+        auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
44
+    }
45
+
46
+    @Bean
47
+    CorsConfigurationSource corsConfigurationSource() {
48
+        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
49
+        source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
50
+        return source;
51
+    }
52
+
53
+}

+ 23
- 0
Back-End/src/main/java/com/zipline/back/config/WebSocketConfig.java Voir le fichier

@@ -0,0 +1,23 @@
1
+package com.zipline.back.config;
2
+
3
+import org.springframework.context.annotation.Configuration;
4
+import org.springframework.messaging.simp.config.MessageBrokerRegistry;
5
+import org.springframework.messaging.simp.config.StompBrokerRelayRegistration;
6
+import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
7
+import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
8
+import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
9
+
10
+@Configuration
11
+@EnableWebSocketMessageBroker
12
+public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
13
+    @Override
14
+    public void configureMessageBroker(MessageBrokerRegistry config) {
15
+        config.enableSimpleBroker("/socket");
16
+        config.setApplicationDestinationPrefixes("/app");
17
+    }
18
+
19
+    @Override
20
+    public void registerStompEndpoints(StompEndpointRegistry registry) {
21
+        registry.addEndpoint("/stomp");
22
+    }
23
+}

+ 15
- 8
Back-End/src/main/java/com/zipline/back/controller/PostController.java Voir le fichier

@@ -4,13 +4,19 @@ import com.zipline.back.dao.PostRepository;
4 4
 import com.zipline.back.dao.UserRepository;
5 5
 import com.zipline.back.model.Post;
6 6
 import com.zipline.back.model.User;
7
+import com.zipline.back.utils.JWTUtils;
8
+import org.json.JSONObject;
7 9
 import org.springframework.beans.factory.annotation.Autowired;
8 10
 import org.springframework.http.HttpEntity;
9 11
 import org.springframework.http.HttpStatus;
12
+import org.springframework.messaging.handler.annotation.MessageMapping;
13
+import org.springframework.messaging.handler.annotation.SendTo;
10 14
 import org.springframework.web.bind.annotation.*;
11 15
 
12 16
 import java.time.LocalDateTime;
13 17
 
18
+import static com.zipline.back.config.SecurityConstants.TOKEN_PREFIX;
19
+
14 20
 
15 21
 @RestController
16 22
 @RequestMapping("/post")
@@ -20,16 +26,17 @@ public class PostController {
20 26
     @Autowired
21 27
     private PostRepository postRepo;
22 28
 
23
-    @PostMapping("{githubId}/new-post")
24
-    @ResponseStatus(HttpStatus.OK)
25
-    public Post createPost (
26
-            @PathVariable String githubId,
27
-            @RequestBody Post post
28
-    ) {
29
-        post.setUser(userRepo.findByGithubId(githubId));
29
+    @MessageMapping("/new-post")
30
+    @SendTo("/socket/posts")
31
+    public Post createPost(@RequestHeader(value = "Authorization") String token,
32
+                           @RequestBody Post post) {
33
+        JWTUtils jwtutils = new JWTUtils();
34
+
35
+        String githubId = jwtutils.getGithubIdFromToken(token.replace(TOKEN_PREFIX, ""));
36
+        User user = userRepo.findByGithubId(githubId);
37
+        post.setUser(user);
30 38
         post.setTimestamp(LocalDateTime.now());
31 39
         return postRepo.save(post);
32
-
33 40
     }
34 41
 
35 42
     @GetMapping("/{githubId}")

+ 55
- 0
Back-End/src/main/java/com/zipline/back/controller/RegistrationController.java Voir le fichier

@@ -0,0 +1,55 @@
1
+package com.zipline.back.controller;
2
+
3
+import com.fasterxml.jackson.annotation.JsonIgnore;
4
+import com.zipline.back.dao.UserRepository;
5
+import com.zipline.back.model.User;
6
+import com.zipline.back.utils.JWTUtils;
7
+import org.json.JSONObject;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.http.ResponseEntity;
10
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
11
+import org.springframework.web.bind.annotation.PostMapping;
12
+import org.springframework.web.bind.annotation.RequestBody;
13
+import org.springframework.web.bind.annotation.RestController;
14
+
15
+import static com.zipline.back.config.SecurityConstants.HEADER_STRING;
16
+import static com.zipline.back.config.SecurityConstants.TOKEN_PREFIX;
17
+
18
+@RestController
19
+public class RegistrationController {
20
+
21
+    private UserRepository userRepo;
22
+    private BCryptPasswordEncoder passwordEncoder;
23
+
24
+
25
+    public RegistrationController(UserRepository userRepo,
26
+                                  BCryptPasswordEncoder passwordEncoder) {
27
+        this.userRepo = userRepo;
28
+        this.passwordEncoder = passwordEncoder;
29
+    }
30
+
31
+    /*
32
+        STUBBED REQUEST =>
33
+        {
34
+            githubId : string,
35
+            name : string,
36
+            password : string
37
+        }
38
+     */
39
+    @PostMapping("/register")
40
+    public ResponseEntity<Void> signup(@RequestBody User user) {
41
+        user.setPassword( passwordEncoder.encode(user.getPassword()));
42
+        userRepo.save(user);
43
+
44
+        String token = new JWTUtils().generateToken(user);
45
+        return ResponseEntity
46
+                .status(302)
47
+                .header(HEADER_STRING, TOKEN_PREFIX + token)
48
+                /*
49
+                .header("location", "location_example")
50
+                .header("X-Sample-Token", "token_example")
51
+                */
52
+                .body(null);
53
+    }
54
+
55
+}

+ 1
- 0
Back-End/src/main/java/com/zipline/back/model/Post.java Voir le fichier

@@ -1,6 +1,7 @@
1 1
 package com.zipline.back.model;
2 2
 
3 3
 import com.fasterxml.jackson.annotation.JsonIgnore;
4
+import lombok.Getter;
4 5
 import org.hibernate.annotations.OnDelete;
5 6
 import org.hibernate.annotations.OnDeleteAction;
6 7
 

+ 9
- 0
Back-End/src/main/java/com/zipline/back/model/User.java Voir le fichier

@@ -12,6 +12,7 @@ public class User {
12 12
 
13 13
     private String githubId;
14 14
     private String name;
15
+    private String password;
15 16
     private ArrayList<String> friends;
16 17
 
17 18
     public User(String githubId, String name) {
@@ -38,6 +39,14 @@ public class User {
38 39
         this.githubId = githubId;
39 40
     }
40 41
 
42
+    public String getPassword() {
43
+        return password;
44
+    }
45
+
46
+    public void setPassword(String password) {
47
+        this.password = password;
48
+    }
49
+
41 50
     public String getName() {
42 51
         return name;
43 52
     }

+ 31
- 0
Back-End/src/main/java/com/zipline/back/service/UserDetailsServiceImpl.java Voir le fichier

@@ -0,0 +1,31 @@
1
+package com.zipline.back.service;
2
+
3
+import com.zipline.back.dao.UserRepository;
4
+import org.springframework.context.annotation.Primary;
5
+import org.springframework.security.core.userdetails.User;
6
+import org.springframework.security.core.userdetails.UserDetails;
7
+import org.springframework.security.core.userdetails.UserDetailsService;
8
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
9
+import org.springframework.stereotype.Service;
10
+
11
+import static java.util.Collections.emptyList;
12
+
13
+@Service
14
+@Primary
15
+public class UserDetailsServiceImpl implements UserDetailsService {
16
+    private UserRepository userRepository;
17
+
18
+    public UserDetailsServiceImpl(UserRepository userRepository) {
19
+        this.userRepository = userRepository;
20
+    }
21
+
22
+    // username -> githubId
23
+    @Override
24
+    public UserDetails loadUserByUsername(String username) {
25
+        com.zipline.back.model.User user = userRepository.findByGithubId(username);
26
+        if (user == null) {
27
+            throw new UsernameNotFoundException(username);
28
+        }
29
+        return new User(user.getGithubId(), user.getName(), emptyList());
30
+    }
31
+}

+ 27
- 0
Back-End/src/main/java/com/zipline/back/utils/JWTUtils.java Voir le fichier

@@ -0,0 +1,27 @@
1
+package com.zipline.back.utils;
2
+
3
+import com.zipline.back.model.User;
4
+import io.jsonwebtoken.Jwts;
5
+import io.jsonwebtoken.SignatureAlgorithm;
6
+
7
+import java.util.Date;
8
+
9
+import static com.zipline.back.config.SecurityConstants.*;
10
+
11
+public class JWTUtils {
12
+    public String generateToken(User user) {
13
+        return Jwts.builder()
14
+                .setSubject(user.getGithubId())
15
+                .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
16
+                .signWith(SignatureAlgorithm.HS512, SECRET.getBytes())
17
+                .compact();
18
+    }
19
+
20
+    public String getGithubIdFromToken(String token) {
21
+        return Jwts.parser()
22
+                .setSigningKey(SECRET.getBytes())
23
+                .parseClaimsJws(token)
24
+                .getBody()
25
+                .getSubject();
26
+    }
27
+}

+ 69
- 0
Back-End/src/test/java/com/zipline/back/controller/UserControllerTest.java Voir le fichier

@@ -0,0 +1,69 @@
1
+package com.zipline.back.controller;
2
+
3
+import org.junit.Test;
4
+import org.springframework.http.HttpEntity;
5
+import org.springframework.http.HttpHeaders;
6
+import org.springframework.http.MediaType;
7
+import org.springframework.http.ResponseEntity;
8
+import org.springframework.util.LinkedMultiValueMap;
9
+import org.springframework.util.MultiValueMap;
10
+import org.springframework.web.client.RestTemplate;
11
+
12
+import static org.junit.Assert.*;
13
+
14
+public class UserControllerTest {
15
+    @Test
16
+    public void signup_A_User() {
17
+        HttpHeaders headers = new HttpHeaders();
18
+        headers.setContentType(MediaType.APPLICATION_JSON);
19
+        String json = "{\"githubId\": \"testGithubIda\", \"name\": \"testName\", \"password\": \"testPassword\"}";
20
+        HttpEntity<String> entity = new HttpEntity<>(json, headers);
21
+        RestTemplate rt = new RestTemplate();
22
+        ResponseEntity<String> resp = rt.postForEntity("http://localhost:8080/register", entity, String.class);
23
+        System.out.println(resp.getHeaders().get("Authorization").get(0));
24
+    }
25
+
26
+    @Test
27
+        public void login_A_User() {
28
+        HttpHeaders headers = new HttpHeaders();
29
+        headers.setContentType(MediaType.APPLICATION_JSON);
30
+        String json = "{\"githubId\": \"testGithubIda\", \"password\": \"$2a$10$n8h8GehQ461NgGQP8DrS.OAM6d7I1hSmmRw8wMonRNYhX2biWlYNC\"}";
31
+        HttpEntity<String> entity = new HttpEntity<>(json, headers);
32
+        RestTemplate rt = new RestTemplate();
33
+        ResponseEntity<String> resp = rt.postForEntity("http://localhost:8080/login", entity, String.class);
34
+        System.out.println(resp);
35
+    }
36
+
37
+    @Test
38
+    public void create_A_User() {
39
+        HttpHeaders headers = new HttpHeaders();
40
+        headers.setContentType(MediaType.APPLICATION_JSON);
41
+        String json = "{\"githubId\": \"testGithubId\", \"name\": \"testName\"}";
42
+        HttpEntity<String> entity = new HttpEntity<>(json, headers);
43
+        RestTemplate rt = new RestTemplate();
44
+        ResponseEntity<String> resp = rt.postForEntity("http://localhost:8080/user/new-user", entity, String.class);
45
+        System.out.println(resp);
46
+    }
47
+
48
+    @Test
49
+    public void create_A_Post() {
50
+        HttpHeaders headers = new HttpHeaders();
51
+        headers.setContentType(MediaType.APPLICATION_JSON);
52
+        headers.set("Authorization", getToken_FromSigningUp());
53
+        String json = "{\"body\": \"testPostBody\"}";
54
+        HttpEntity<String> entity = new HttpEntity<>(json, headers);
55
+        RestTemplate rt = new RestTemplate();
56
+        ResponseEntity<String> resp = rt.postForEntity("http://localhost:8080/post/new-post", entity, String.class);
57
+        System.out.println(resp);
58
+    }
59
+
60
+    private String getToken_FromSigningUp() {
61
+        HttpHeaders headers = new HttpHeaders();
62
+        headers.setContentType(MediaType.APPLICATION_JSON);
63
+        String json = "{\"githubId\": \"testGithubId\", \"name\": \"testName\", \"password\": \"testPassword\"}";
64
+        HttpEntity<String> entity = new HttpEntity<>(json, headers);
65
+        RestTemplate rt = new RestTemplate();
66
+        ResponseEntity<String> resp = rt.postForEntity("http://localhost:8080/register", entity, String.class);
67
+        return resp.getHeaders().get("Authorization").get(0);
68
+    }
69
+}