labelingsystem-server  Version 0.1.0.0
AuthResource Class Reference

Public Member Functions

Response loginUser (@FormParam("user") String user, @FormParam("pwd") String pwd)
 
Response statusUser (@QueryParam("user") String user, @QueryParam("token") String token)
 
Response logoutUser (@FormParam("user") String user)
 
Response getHash (@QueryParam("str") String str)
 

Member Function Documentation

◆ getHash()

Response getHash ( @QueryParam("str") String  str)
143  {
144  try {
145  String salt = Crypt.generateHash();
146  String hash = salt + Crypt.SHA1(salt + str);
147  JSONObject jsonOut = new JSONObject();
148  jsonOut.put("hash", hash);
149  return Response.ok(jsonOut).header("Content-Type", "application/json;charset=UTF-8").build();
150  } catch (Exception e) {
151  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.AuthResource"))
152  .header("Content-Type", "application/json;charset=UTF-8").build();
153  }
154  }

References Crypt.generateHash(), Logging.getMessageJSON(), and Crypt.SHA1().

◆ loginUser()

Response loginUser ( @FormParam("user") String  user,
@FormParam("pwd") String  pwd 
)
32  {
33  JSONObject jsonOut = new JSONObject();
34  JSONObject jsonStatus = new JSONObject();
35  JSONObject jsonUser = new JSONObject();
36  try {
37  String secretToken = UniqueIdentifier.getHashID();
38  String role = SQlite.getUserInfoAndCheckPassword(user, pwd);
39  boolean login = SQlite.setLogin(user + ";" + secretToken, role);
40  if (login) {
41  String status[] = SQlite.getLoginStatus(user + ";" + secretToken);
42  jsonStatus.put("verified", true);
43  jsonStatus.put("user", user);
44  jsonStatus.put("role", status[0]);
45  jsonStatus.put("date", status[1]);
46  jsonStatus.put("token", secretToken);
47  jsonOut.put("status", jsonStatus);
48  // get agent object
49  RDF rdf = new RDF();
50  String item = "ls_age";
51  String query = GeneralFunctions.getAllElementsForItemID(item, user);
52  List<BindingSet> result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
53  List<String> predicates = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "p");
54  List<String> objects = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "o");
55  if (result.size() > 0) {
56  for (int i = 0; i < predicates.size(); i++) {
57  rdf.setModelTriple(item + ":" + user, predicates.get(i), objects.get(i));
58  }
59  String jsonObject = Transformer.agent_GET(rdf.getModel("RDF/JSON"), user).toJSONString();
60  jsonUser = (JSONObject) new JSONParser().parse(jsonObject);
61  jsonOut.put("user", jsonUser);
62  }
63  }
64  return Response.ok(jsonOut).header("Content-Type", "application/json;charset=UTF-8").build();
65  } catch (Exception e) {
66  if (e.toString().contains("AccessDeniedException")) {
67  return Response.status(Response.Status.FORBIDDEN).entity(Logging.getMessageJSON(e, "v1.rest.AuthResource"))
68  .header("Content-Type", "application/json;charset=UTF-8").build();
69  } else {
70  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.AuthResource"))
71  .header("Content-Type", "application/json;charset=UTF-8").build();
72  }
73  }
74  }

References Transformer.agent_GET(), GeneralFunctions.getAllElementsForItemID(), UniqueIdentifier.getHashID(), SQlite.getLoginStatus(), Logging.getMessageJSON(), ConfigProperties.getPropertyParam(), SQlite.getUserInfoAndCheckPassword(), and SQlite.setLogin().

◆ logoutUser()

Response logoutUser ( @FormParam("user") String  user)
125  {
126  JSONObject jsonOut = new JSONObject();
127  try {
128  boolean logout = SQlite.setLogout(user);
129  if (logout) {
130  jsonOut.put("verified", false);
131  jsonOut.put("user", user);
132  }
133  return Response.ok(jsonOut).header("Content-Type", "application/json;charset=UTF-8").build();
134  } catch (Exception e) {
135  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.AuthResource"))
136  .header("Content-Type", "application/json;charset=UTF-8").build();
137  }
138  }

References Logging.getMessageJSON(), and SQlite.setLogout().

◆ statusUser()

Response statusUser ( @QueryParam("user") String  user,
@QueryParam("token") String  token 
)
79  {
80  JSONObject jsonOut = new JSONObject();
81  JSONObject jsonStatus = new JSONObject();
82  JSONObject jsonUser = new JSONObject();
83  try {
84  String status[] = SQlite.getLoginStatus(user + ";" + token);
85  if (status[0] != null) {
86  jsonStatus.put("verified", true);
87  jsonStatus.put("user", user);
88  jsonStatus.put("role", status[0]);
89  jsonStatus.put("date", status[1]);
90  jsonOut.put("status", jsonStatus);
91  // get agent object
92  RDF rdf = new RDF();
93  String item = "ls_age";
94  String query = GeneralFunctions.getAllElementsForItemID(item, user);
95  List<BindingSet> result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
96  List<String> predicates = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "p");
97  List<String> objects = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "o");
98  if (result.size() > 0) {
99  for (int i = 0; i < predicates.size(); i++) {
100  rdf.setModelTriple(item + ":" + user, predicates.get(i), objects.get(i));
101  }
102  String jsonObject = Transformer.agent_GET(rdf.getModel("RDF/JSON"), user).toJSONString();
103  jsonUser = (JSONObject) new JSONParser().parse(jsonObject);
104  jsonOut.put("user", jsonUser);
105  }
106  } else {
107  jsonOut.put("verified", false);
108  jsonOut.put("user", user);
109  throw new AccessDeniedException();
110  }
111  return Response.ok(jsonOut).header("Content-Type", "application/json;charset=UTF-8").build();
112  } catch (Exception e) {
113  if (e.toString().contains("AccessDeniedException")) {
114  return Response.status(Response.Status.FORBIDDEN).entity(jsonOut).header("Content-Type", "application/json;charset=UTF-8").build();
115  } else {
116  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.AuthResource"))
117  .header("Content-Type", "application/json;charset=UTF-8").build();
118  }
119  }
120  }

References Transformer.agent_GET(), GeneralFunctions.getAllElementsForItemID(), SQlite.getLoginStatus(), Logging.getMessageJSON(), and ConfigProperties.getPropertyParam().

rdf
Definition: RDF.java:1
Exception