commit e5500e5202b83abec95f2a8834e5328db08a3a75
Author: Jiri Trefil <badjokke@gmail.com>
Date:   Fri Apr 7 23:30:20 2023 +0200

    #10244 implementace komunikace s autentizacni aplikaci.

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 3da823a..8f2afaa 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
@@ -2,11 +2,13 @@ package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller;
 
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.UserModelStatusCodes;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.OAuthService;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.UserService;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.JSONBuilder;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
+import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.HashMap;
@@ -21,12 +23,18 @@ import java.util.HashMap;
 @RequestMapping("v2/user")
 public class UserController {
 
+    @Autowired
+    private AuthenticationManager authenticationManager;
+
     /**
      * Service for work with user management
      */
     @Autowired
     private UserService userService;
 
+    @Autowired
+    private OAuthService authService;
+
     /**
      * Method to register new user in the app
      *
@@ -47,7 +55,8 @@ public class UserController {
      */
     @PostMapping(value = "/login")
     public ResponseEntity<String> loginUser(@RequestBody User user) {
-        UserModelStatusCodes statusCode = userService.loginUser(user);
+        UserModelStatusCodes statusCode = userService.verifyUser(user);
+        ResponseEntity<String> response = authService.loginUser(user);
 
         String jwtToken = null;
         if (statusCode.getStatusCode() == 200) {
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/User.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/User.java
index ed16073..2565a58 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/User.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/User.java
@@ -16,6 +16,13 @@ public class User {
      */
     @Transient
     private static final int MAX_COLUMN_LENGTH = 255;
+
+    /**
+     * Max length of column in the table
+     */
+    @Transient
+    private String token;
+
     /**
      * Unique key of table
      */
@@ -96,7 +103,27 @@ public class User {
         return MAX_COLUMN_LENGTH;
     }
 
+    /**
+     * Getter for password of user
+     * @return user password
+     */
     public String getPassword() {
         return this.password;
     }
+
+    /**
+     * Getter for token of user
+     * @return  user token
+     */
+    public String getToken() {
+        return this.token;
+    }
+
+    /**
+     * Setter of user token
+     * @param token user token
+     */
+    public void setToken(String token) {
+        this.token = token;
+    }
 }
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 441c47b..0447986 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
@@ -20,7 +20,7 @@ public interface UserService {
      * @param user serialized JSON object representing user
      * @return Integer - status code of the operation, ie 1 - successful, 0 - failed, ....
      */
-    public UserModelStatusCodes loginUser(User user);
+    public UserModelStatusCodes verifyUser(User user);
     /**
      * Method attempts to log out a user
      * @param user serialized JSON object representing user
@@ -30,5 +30,4 @@ public interface UserService {
 
     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 b7f3389..55f0c4f 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
@@ -54,8 +54,10 @@ public class UserServiceImpl implements UserService {
         //save the user
         User u = userRepository.save(new User(name, email, passwordHash));
         //database insert failed for some reason
-        if(u == null)
+        if(u == null) {
             return UserModelStatusCodes.USER_CREATION_FAILED;
+        }
+
         //TODO request to OAuth for token - send user info to the oauth app for token
         //return okay status code, the user was created
         return UserModelStatusCodes.USER_CREATED;
@@ -90,7 +92,7 @@ public class UserServiceImpl implements UserService {
     private String hashPassword(String password) {
         //standard java security encryption module
         MessageDigest digest = null;
-        try{
+        try {
             //try to instance the class - throws an error if algorithm
             digest = MessageDigest.getInstance("SHA3-256");
         }
@@ -112,7 +114,7 @@ public class UserServiceImpl implements UserService {
      */
 
     @Override
-    public UserModelStatusCodes loginUser(User user) {
+    public UserModelStatusCodes verifyUser(User user) {
         final String name = user.getName();
         final String password = user.getPassword();
         if(name == null || password == null) {
@@ -135,7 +137,7 @@ public class UserServiceImpl implements UserService {
      * @param hash String hash saved in database
      * @return true if hashes are the same
      */
-    boolean comparePassword(String password, String hash){
+    boolean comparePassword(String password, String hash) {
         final String passwordHash = this.hashPassword(password);
         return hash.equals(passwordHash);
     }
