| 396 |
ashish |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
4 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
5 |
import org.apache.thrift.TException;
|
|
|
6 |
|
|
|
7 |
import in.shop2020.model.v1.user.AuthenticationException;
|
|
|
8 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
|
|
9 |
import in.shop2020.serving.rest.Auth;
|
|
|
10 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
11 |
import in.shop2020.thrift.clients.UserProfileClient;
|
|
|
12 |
|
|
|
13 |
import com.opensymphony.xwork2.ModelDriven;
|
|
|
14 |
|
|
|
15 |
public class AuthController implements ModelDriven<Object>{
|
|
|
16 |
|
|
|
17 |
private Auth auth = new Auth();
|
|
|
18 |
|
|
|
19 |
private UserContextServiceClient client = null;
|
|
|
20 |
|
|
|
21 |
private int errorCode = 0;
|
|
|
22 |
private String errorMessage;
|
|
|
23 |
|
|
|
24 |
public AuthController(){
|
|
|
25 |
try {
|
|
|
26 |
client = new UserContextServiceClient();
|
|
|
27 |
} catch (Exception e) {
|
|
|
28 |
e.printStackTrace();
|
|
|
29 |
}
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
@Override
|
|
|
33 |
public Object getModel() {
|
|
|
34 |
return auth;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public HttpHeaders create(){
|
|
|
38 |
|
|
|
39 |
//AUTH service to be invoked from here
|
|
|
40 |
Client c = client.getClient();
|
|
|
41 |
try {
|
|
|
42 |
if (c.authenticateUser(auth.getUserName(), auth.getPassword(), true)){
|
|
|
43 |
return new DefaultHttpHeaders("lsuccess");
|
|
|
44 |
}
|
|
|
45 |
} catch (AuthenticationException e) {
|
|
|
46 |
|
|
|
47 |
errorCode = e.getErrorCode();
|
|
|
48 |
errorMessage = e.getMessage();
|
|
|
49 |
|
|
|
50 |
} catch (TException e) {
|
|
|
51 |
// TODO Auto-generated catch block
|
|
|
52 |
errorCode = -1;
|
|
|
53 |
e.printStackTrace();
|
|
|
54 |
}
|
|
|
55 |
return new DefaultHttpHeaders("lfail");
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public int getErrorCode() {
|
|
|
59 |
return errorCode;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public String getErrorMessage() {
|
|
|
63 |
return errorMessage;
|
|
|
64 |
}
|
|
|
65 |
}
|