| Line 3... |
Line 3... |
| 3 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| 4 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| 5 |
import java.util.HashMap;
|
5 |
import java.util.HashMap;
|
| 6 |
import java.util.Iterator;
|
6 |
import java.util.Iterator;
|
| 7 |
import java.util.Map;
|
7 |
import java.util.Map;
|
| - |
|
8 |
import java.util.Set;
|
| 8 |
|
9 |
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
11 |
import org.springframework.stereotype.Component;
|
| 10 |
|
12 |
|
| 11 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
13 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
| 12 |
import com.fasterxml.jackson.databind.JsonNode;
|
14 |
import com.fasterxml.jackson.databind.JsonNode;
|
| 13 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
15 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
16 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 15 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
17 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 16 |
import com.spice.profitmandi.common.util.JWTUtil;
|
18 |
import com.spice.profitmandi.common.util.JWTUtil;
|
| - |
|
19 |
import com.spice.profitmandi.dao.entity.Role;
|
| 17 |
import com.spice.profitmandi.dao.entity.SocialUser;
|
20 |
import com.spice.profitmandi.dao.entity.SocialUser;
|
| 18 |
import com.spice.profitmandi.dao.entity.User;
|
21 |
import com.spice.profitmandi.dao.entity.User;
|
| 19 |
import com.spice.profitmandi.dao.enumuration.Gender;
|
22 |
import com.spice.profitmandi.dao.enumuration.Gender;
|
| 20 |
import com.spice.profitmandi.dao.enumuration.SocialType;
|
23 |
import com.spice.profitmandi.dao.enumuration.SocialType;
|
| 21 |
import com.spice.profitmandi.dao.repository.SocialUserRepository;
|
24 |
import com.spice.profitmandi.dao.repository.SocialUserRepository;
|
| 22 |
import com.spice.profitmandi.dao.repository.UserRepository;
|
25 |
import com.spice.profitmandi.dao.repository.UserRepository;
|
| 23 |
import com.spice.profitmandi.web.client.RestClient;
|
26 |
import com.spice.profitmandi.web.client.RestClient;
|
| 24 |
import com.spice.profitmandi.web.enumuration.SchemeType;
|
27 |
import com.spice.profitmandi.web.enumuration.SchemeType;
|
| 25 |
|
28 |
|
| - |
|
29 |
@Component
|
| 26 |
public class GoogleLoginProcessor {
|
30 |
public class GoogleLoginProcessor {
|
| 27 |
//https://content.googleapis.com/plus/v1/people/me?access_token
|
- |
|
| - |
|
31 |
|
| 28 |
private static final String HOST_NAME = "content.googleapis.com";
|
32 |
private static final String HOST_NAME = "content.googleapis.com";
|
| 29 |
private static final String URI = "/plus/v1/people/me";
|
33 |
private static final String URI = "/plus/v1/people/me";
|
| 30 |
private static final int PORT_NUMBER = 443;
|
34 |
private static final int PORT_NUMBER = 443;
|
| 31 |
private final ObjectMapper objectMapper = new ObjectMapper();
|
35 |
private final ObjectMapper objectMapper = new ObjectMapper();
|
| 32 |
|
36 |
|
| Line 77... |
Line 81... |
| 77 |
socialUser.setUpdateTimestamp(LocalDateTime.now());
|
81 |
socialUser.setUpdateTimestamp(LocalDateTime.now());
|
| 78 |
socialUserRepository.persist(socialUser);
|
82 |
socialUserRepository.persist(socialUser);
|
| 79 |
Map<String, Object> responseMap = new HashMap<>(2);
|
83 |
Map<String, Object> responseMap = new HashMap<>(2);
|
| 80 |
try{
|
84 |
try{
|
| 81 |
User user = userRepository.selectByEmailId(socialUser.getEmailId());
|
85 |
User user = userRepository.selectByEmailId(socialUser.getEmailId());
|
| - |
|
86 |
Set<Role> roles = user.getRoles();
|
| - |
|
87 |
String[] roleTypes = new String[roles.size()];
|
| - |
|
88 |
int index = 0;
|
| - |
|
89 |
for(Role role : roles){
|
| - |
|
90 |
roleTypes[index++] = role.getType().toString();
|
| - |
|
91 |
}
|
| 82 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId()));
|
92 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleTypes));
|
| 83 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
93 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| 84 |
}catch (ProfitMandiBusinessException pmbe) {
|
94 |
}catch (ProfitMandiBusinessException pmbe) {
|
| 85 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(-1));
|
95 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create());
|
| 86 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
96 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
| 87 |
}
|
97 |
}
|
| 88 |
return responseMap;
|
98 |
return responseMap;
|
| 89 |
}catch (JsonProcessingException jsonProcessingException) {
|
99 |
}catch (JsonProcessingException jsonProcessingException) {
|
| 90 |
//LOGGER.error("Json parse exception of "+json,jsonProcessingException);
|
100 |
//LOGGER.error("Json parse exception of "+json,jsonProcessingException);
|