commit 1c632f96f99f22bf6b0b686d493eb869a5b67677
Author: Jiri Trefil <badjokke@gmail.com>
Date:   Fri Apr 7 23:28:16 2023 +0200

    #10228 implementace komunikace s autentizacni aplikaci.

diff --git a/pom.xml b/pom.xml
index b0d9c57..db067b0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -97,7 +97,11 @@
 			<version>${com.fasterxml.jackson.core.version}</version>
 		</dependency>
 
-
+	<!-- Security library -->
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-security</artifactId>
+		</dependency>
 
 
 		<!-- Junit libraries for unit tests-->
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserController.java
index e7b75a8..3da823a 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserController.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserController.java
@@ -50,8 +50,10 @@ public class UserController {
         UserModelStatusCodes statusCode = userService.loginUser(user);
 
         String jwtToken = null;
-        if (statusCode.statusCode == 200)
-            jwtToken = "token";
+        if (statusCode.getStatusCode() == 200) {
+            jwtToken = response.getBody();
+        }
+
 
         return getResponseEntity(statusCode, jwtToken);
     }
@@ -76,7 +78,7 @@ public class UserController {
      */
     private ResponseEntity<String> getResponseEntity(UserModelStatusCodes statusCode, String jwtToken) {
         String message = this.generateResponseObject(statusCode, jwtToken);
-        int code = statusCode.statusCode;
+        int code = statusCode.getStatusCode();
         return new ResponseEntity<>(message, HttpStatus.valueOf(code));
     }
 
@@ -88,7 +90,7 @@ public class UserController {
      */
     private String generateResponseObject(UserModelStatusCodes code, String jwtToken) {
         HashMap<String, String> json = new HashMap<>();
-        json.put("msg", code.label);
+        json.put("message", code.getLabel());
         if (jwtToken != null) {
             json.put("jwtToken", jwtToken);
         }
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/dials/UserModelStatusCodes.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/dials/UserModelStatusCodes.java
index b0d2a5b..0b0f4e4 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/dials/UserModelStatusCodes.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/dials/UserModelStatusCodes.java
@@ -13,12 +13,19 @@ public enum UserModelStatusCodes {
     USER_CREATION_FAILED("Error occurred while creating user",503),
     USER_LOGGED_OUT("User logged out.",200);
 
-    public final String label;
-    public final int statusCode;
+    private final String label;
+    private final int statusCode;
 
     UserModelStatusCodes(String s, int i) {
         this.label = s;
         this.statusCode = i;
     }
 
+    public int getStatusCode(){
+        return this.statusCode;
+    }
+    public String getLabel(){
+        return this.label;
+    }
+
 }
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserService.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserService.java
index cddf913..441c47b 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserService.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserService.java
@@ -28,5 +28,7 @@ public interface UserService {
      */
     public UserModelStatusCodes logoutUser(User user);
 
+    public User getUserByName(String name);
+
 
 }
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpl.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpl.java
index 10c6f00..b7f3389 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpl.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpl.java
@@ -124,7 +124,6 @@ public class UserServiceImpl implements UserService {
         if (u == null) {
             return UserModelStatusCodes.USER_LOGIN_FAILED;
         }
-        //TODO request to OAuth for authentication
         final boolean passwordMatches = comparePassword(password,u.getPassword());
 
         return (!passwordMatches ? UserModelStatusCodes.USER_LOGIN_FAILED : UserModelStatusCodes.USER_LOGGED_IN);
@@ -151,4 +150,11 @@ public class UserServiceImpl implements UserService {
         //TODO with OAuth app
         return UserModelStatusCodes.USER_LOGGED_OUT;
     }
+
+    @Override
+    public User getUserByName(String name) {
+        return this.userRepository.findByName(name);
+    }
+
+
 }
diff --git a/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserControllerTest.java b/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserControllerTest.java
index 2f9a22f..d40f079 100644
--- a/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserControllerTest.java
+++ b/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserControllerTest.java
@@ -99,7 +99,7 @@ public class UserControllerTest {
 
     @Test
     public void loginValidUser() throws Exception {
-        Mockito.when(userService.loginUser(any())).thenReturn(UserModelStatusCodes.USER_LOGGED_IN);
+        Mockito.when(userService.verifyUser(any())).thenReturn(UserModelStatusCodes.USER_LOGGED_IN);
         HashMap<String,String> map = new HashMap<>();
         map.put("name","pepa");
         map.put("password","ahojSvete");
@@ -119,7 +119,7 @@ public class UserControllerTest {
 
     @Test
     public void loginInValidUser() throws Exception {
-        Mockito.when(userService.loginUser(any())).thenReturn(UserModelStatusCodes.USER_LOGIN_FAILED);
+        Mockito.when(userService.verifyUser(any())).thenReturn(UserModelStatusCodes.USER_LOGIN_FAILED);
         HashMap<String,String> map = new HashMap<>();
         map.put("name","pepa");
         map.put("password","ahojSvete");
diff --git a/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpTest.java b/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpTest.java
index daedfcc..d5d01e4 100644
--- a/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpTest.java
+++ b/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpTest.java
@@ -202,7 +202,7 @@ public class UserServiceImpTest {
         Mockito.when(userRepository.findByName(mockUser.getName())).thenReturn(mockUser);
 
         String name = "test";
-        UserModelStatusCodes foundCode = userService.loginUser(new User(name, ""));
+        UserModelStatusCodes foundCode = userService.verifyUser(new User(name, ""));
 
         assertEquals(foundCode, UserModelStatusCodes.USER_LOGGED_IN);
     }
@@ -217,7 +217,7 @@ public class UserServiceImpTest {
         //Mockito.when(userRepository.findByName(mockUser.getName())).thenReturn(mockUser);
 
         String name = "notest";
-        UserModelStatusCodes foundCode = userService.loginUser(new User(name, ""));
+        UserModelStatusCodes foundCode = userService.verifyUser(new User(name, ""));
 
         assertEquals(foundCode, UserModelStatusCodes.USER_LOGIN_FAILED);
     }
