| Line 3... |
Line 3... |
| 3 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| 4 |
import java.util.HashMap;
|
4 |
import java.util.HashMap;
|
| 5 |
import java.util.Map;
|
5 |
import java.util.Map;
|
| 6 |
|
6 |
|
| 7 |
import org.apache.http.conn.HttpHostConnectException;
|
7 |
import org.apache.http.conn.HttpHostConnectException;
|
| - |
|
8 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
9 |
import org.apache.logging.log4j.Logger;
|
| 8 |
import org.springframework.http.HttpHeaders;
|
10 |
import org.springframework.http.HttpHeaders;
|
| 9 |
import org.springframework.http.MediaType;
|
11 |
import org.springframework.http.MediaType;
|
| 10 |
import org.springframework.stereotype.Component;
|
12 |
import org.springframework.stereotype.Component;
|
| 11 |
|
13 |
|
| 12 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
14 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
| Line 14... |
Line 16... |
| 14 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
16 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 15 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
17 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 16 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 17 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
19 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 18 |
import com.spice.profitmandi.common.web.client.RestClient;
|
20 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| - |
|
21 |
import com.spice.profitmandi.web.controller.LoginController;
|
| 19 |
|
22 |
|
| 20 |
@Component
|
23 |
@Component
|
| 21 |
public class GoogleTokenUtil {
|
24 |
public class GoogleTokenUtil {
|
| 22 |
|
25 |
|
| 23 |
private static final String V3_HOST_NAME = "www.googleapis.com";
|
26 |
private static final String V3_HOST_NAME = "www.googleapis.com";
|
| 24 |
private static final String V3_URI = "oauth2/v3/tokeninfo";
|
27 |
private static final String V3_URI = "oauth2/v3/tokeninfo";
|
| 25 |
private static final int PORT_NUMBER = 443;
|
28 |
private static final int PORT_NUMBER = 443;
|
| 26 |
private final ObjectMapper objectMapper = new ObjectMapper();
|
29 |
private final ObjectMapper objectMapper = new ObjectMapper();
|
| - |
|
30 |
|
| - |
|
31 |
private static final Logger LOGGER = LogManager.getLogger(GoogleTokenUtil.class);
|
| 27 |
|
32 |
|
| 28 |
public String getEmailId(String token) throws ProfitMandiBusinessException{
|
33 |
public String getEmailId(String token) throws ProfitMandiBusinessException {
|
| 29 |
RestClient restClient = new RestClient();
|
34 |
RestClient restClient = new RestClient();
|
| 30 |
Map<String, String> params = new HashMap<>();
|
35 |
Map<String, String> params = new HashMap<>();
|
| 31 |
params.put(ProfitMandiConstants.ID_TOKEN, token);
|
36 |
params.put(ProfitMandiConstants.ID_TOKEN, token);
|
| 32 |
Map<String, String> headers = new HashMap<>(1);
|
37 |
Map<String, String> headers = new HashMap<>(1);
|
| 33 |
headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
38 |
headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
| Line 37... |
Line 42... |
| 37 |
} catch (HttpHostConnectException e) {
|
42 |
} catch (HttpHostConnectException e) {
|
| 38 |
throw new ProfitMandiBusinessException("googleServerResponse", responseString, "GE_1006");
|
43 |
throw new ProfitMandiBusinessException("googleServerResponse", responseString, "GE_1006");
|
| 39 |
}
|
44 |
}
|
| 40 |
try {
|
45 |
try {
|
| 41 |
JsonNode rootNode = objectMapper.readTree(responseString);
|
46 |
JsonNode rootNode = objectMapper.readTree(responseString);
|
| - |
|
47 |
|
| - |
|
48 |
LOGGER.info("rootNode {}", rootNode);
|
| 42 |
return rootNode.get("email").asText();
|
49 |
return rootNode.get("email").asText();
|
| 43 |
|
50 |
|
| 44 |
}catch (JsonProcessingException jsonProcessingException) {
|
51 |
} catch (JsonProcessingException jsonProcessingException) {
|
| 45 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
52 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
| 46 |
}catch (IOException ioException) {
|
53 |
} catch (IOException ioException) {
|
| 47 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
54 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
| 48 |
}
|
55 |
}
|
| 49 |
}
|
56 |
}
|
| 50 |
}
|
57 |
}
|