1 package com.srv4pos.server.api.auth;
2
3 import com.srv4pos.server.api.infrastructure.EmptyConnectionWriter;
4 import com.srv4pos.server.api.infrastructure.HttpMethod;
5 import com.srv4pos.server.api.infrastructure.credentials.Credentials;
6 import com.srv4pos.server.api.infrastructure.exceptions.enums.ForbiddenErrorType;
7 import com.srv4pos.server.api.infrastructure.http.HttpHelper;
8 import com.srv4pos.server.api.infrastructure.http.Transport;
9
10 import java.net.URL;
11
12 import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestString;
13
14
15
16
17 public class AuthService {
18 private URL url;
19 private Credentials credentials;
20 private Transport transport;
21
22 public AuthService() {
23
24 }
25
26 public AuthService(URL url, Credentials credentials, Transport transport) {
27 this.url = url;
28 this.credentials = credentials;
29 this.transport = transport;
30 }
31
32
33
34
35
36
37
38 public HandshakeReply handshake() {
39 return HandshakeReply.fromJsonToHandshakeReply(
40 requestString("auth/handshake", HttpMethod.GET, url, credentials == null ? null : credentials.toAuthentication(), null, null,
41 EmptyConnectionWriter.EMPTY_CONNECTION_WRITER,
42 HttpHelper.CONTENT_TYPE_APPLICATION_JSON, transport).getContent());
43 }
44
45
46
47
48
49
50
51
52
53 public AuthInfo getAuth() {
54 return AuthInfo.fromJsonToAuthInfo(requestString(String.format("auth/user"), HttpMethod.GET, url, credentials.toAuthentication(), null, null,
55 EmptyConnectionWriter.EMPTY_CONNECTION_WRITER, HttpHelper.CONTENT_TYPE_APPLICATION_JSON, transport).getContent());
56 }
57 }