diff --git a/src/main/java/hello/APIServicePaths.java b/src/main/java/hello/APIServicePaths.java index ccbcc79..f6f0a91 100644 --- a/src/main/java/hello/APIServicePaths.java +++ b/src/main/java/hello/APIServicePaths.java @@ -11,5 +11,8 @@ public final class APIServicePaths { private APIServicePaths() { } - public static final String ROOT = "http://10.156.207.136:8080/"; + //AUTHENTICATION + public static final String AUTHENTICATION_CONTROLLER = "/authentication"; + public static final String CHECK_PERMISSION_FOR_TOKEN = "/checkPermissionForToken"; + public static final String LOGIN_USER = "/loginUser"; } diff --git a/src/main/java/hello/LoginController.java b/src/main/java/hello/LoginController.java index a050d0c..7d9d26a 100644 --- a/src/main/java/hello/LoginController.java +++ b/src/main/java/hello/LoginController.java @@ -1,7 +1,13 @@ package hello; import org.springframework.stereotype.Controller; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.client.RestTemplate; /** * Created by Marcin on 2015-01-19. @@ -9,6 +15,27 @@ import org.springframework.web.bind.annotation.RequestMapping; @Controller -@RequestMapping("http://10.156.207.136:8080/auth-ws/") +@RequestMapping(APIServicePaths.AUTHENTICATION_CONTROLLER) public class LoginController { + + RestTemplate restTemplate = new RestTemplate(); + + @RequestMapping(APIServicePaths.CHECK_PERMISSION_FOR_TOKEN) + @ResponseBody + String checkForPermission(@RequestParam("token") String token, @RequestParam("permission") String permission) { + return restTemplate.getForObject(ModuleServicePaths.CHECK_PERMISSION_FOR_TOKEN + .concat("?token=").concat(token) + .concat("&permission=").concat(permission), + String.class + ); + } + + @RequestMapping(value = APIServicePaths.LOGIN_USER, method = RequestMethod.POST) + @ResponseBody + String loginUser(@RequestParam("login") String login, @RequestParam("password") String password) { + MultiValueMap map = new LinkedMultiValueMap<>(); + map.add("login", login); + map.add("password", password); + return restTemplate.postForObject(ModuleServicePaths.AUTHENTICATICATE, map, String.class); + } } diff --git a/src/main/java/hello/ModuleServicePaths.java b/src/main/java/hello/ModuleServicePaths.java index 3e1d891..0f77e5a 100644 --- a/src/main/java/hello/ModuleServicePaths.java +++ b/src/main/java/hello/ModuleServicePaths.java @@ -12,7 +12,7 @@ public final class ModuleServicePaths { private ModuleServicePaths() { } - public static final String ROOT= "http://10.156.207.136:8080"; + public static final String ROOT = "http://10.156.207.136:8080"; //AUTHENTICATION public static final String AUTHENTICATION_MODULE = ROOT + "/auth-ws";