Revision 60042
Added by Katerina Iatropoulou almost 4 years ago
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/RegisteredServicesServlet.java | ||
---|---|---|
55 | 55 |
try { |
56 | 56 |
registeredServices = registeredServicesUtils. |
57 | 57 |
getRegisteredServiceDao().fetchAllRegisteredServicesByOwner(userId); |
58 |
System.out.println("LOAD REGISTERED SERVICES. " + registeredServices.size()); |
|
58 |
//System.out.println("LOAD REGISTERED SERVICES. " + registeredServices.size());
|
|
59 | 59 |
|
60 | 60 |
if (registeredServices.isEmpty()) { |
61 | 61 |
request.getSession().setAttribute("showEmptyList", true); |
... | ... | |
74 | 74 |
name.append(authentication.getUserInfo().getFamilyName().charAt(0)); |
75 | 75 |
request.getSession().setAttribute("name", name.toString()); |
76 | 76 |
request.getSession().setAttribute("reachedLimit", reachedLimit); |
77 |
System.out.println("REACHED LIMIT??? " + reachedLimit); |
|
77 |
//System.out.println("REACHED LIMIT??? " + reachedLimit);
|
|
78 | 78 |
|
79 | 79 |
request.getSession().setAttribute("services", serviceResponses); |
80 | 80 |
request.getSession().setAttribute("keys", serviceKey); |
... | ... | |
102 | 102 |
|
103 | 103 |
private String extractJSONJwk(Jwks jwks) { |
104 | 104 |
Gson gson = new GsonBuilder().setPrettyPrinting().create(); |
105 |
System.out.println(gson.toJson(jwks)); |
|
105 |
//System.out.println(gson.toJson(jwks));
|
|
106 | 106 |
return gson.toJson(jwks); |
107 | 107 |
} |
108 | 108 |
|
... | ... | |
112 | 112 |
getContext().getAuthentication(); |
113 | 113 |
String id = request.getParameter("id"); |
114 | 114 |
|
115 |
System.out.println("POST " +id); |
|
115 |
//System.out.println("POST " +id);
|
|
116 | 116 |
|
117 | 117 |
if (id!=null && !id.isEmpty()) { |
118 | 118 |
try { |
... | ... | |
120 | 120 |
|
121 | 121 |
if (!registeredService.getOwner().equals(authentication.getSub())) { |
122 | 122 |
request.getSession().setAttribute("message", "You are not allowed to delete the service."); |
123 |
System.out.println("BLOCKED " + registeredService.getOwner() + " >> " + authentication.getSub()); |
|
123 |
//System.out.println("BLOCKED " + registeredService.getOwner() + " >> " + authentication.getSub());
|
|
124 | 124 |
response.sendRedirect("./registeredServices"); |
125 | 125 |
return; |
126 | 126 |
} |
... | ... | |
128 | 128 |
HttpResponse resp = tokenUtils.deleteService(registeredService.getClientId(), registeredService.getRegistrationAccessToken()); |
129 | 129 |
|
130 | 130 |
int statusCode = resp.getStatusLine().getStatusCode(); |
131 |
System.out.println("STATUS CODE " + statusCode); |
|
131 |
//System.out.println("STATUS CODE " + statusCode);
|
|
132 | 132 |
|
133 | 133 |
if (statusCode != 204) { |
134 | 134 |
logger.error("Unable to delete the service. Status code was " + statusCode); |
135 | 135 |
request.getSession().setAttribute("message", "Fail to delete the service. Status " + statusCode); |
136 |
System.out.println("AAI blocked"); |
|
136 |
//System.out.println("AAI blocked");
|
|
137 | 137 |
response.sendRedirect("./registeredServices"); |
138 | 138 |
return; |
139 | 139 |
} else { |
140 | 140 |
registeredServicesUtils.getRegisteredServiceDao().delete(Integer.parseInt(id)); |
141 | 141 |
request.getSession().setAttribute("success", "The service was successfully deleted."); |
142 |
System.out.println("HERE HERE"); |
|
142 |
//System.out.println("HERE HERE");
|
|
143 | 143 |
} |
144 | 144 |
|
145 | 145 |
} catch (SQLException sqle) { |
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServiceServlet.java | ||
---|---|---|
54 | 54 |
String idParam = request.getParameter("id"); |
55 | 55 |
|
56 | 56 |
if (idParam != null && !idParam.isEmpty()) { // EDIT CASE |
57 |
System.out.println("In edit"); |
|
57 |
//System.out.println("In edit");
|
|
58 | 58 |
try { |
59 | 59 |
int id = Integer.parseInt(idParam); |
60 | 60 |
RegisteredService registeredService = registeredServicesUtils.getRegisteredServiceDao().fetchRegisteredServiceById(id); |
... | ... | |
66 | 66 |
|
67 | 67 |
} else { |
68 | 68 |
if (registeredService == null) { |
69 |
System.out.println("No service found!"); |
|
69 |
//System.out.println("No service found!");
|
|
70 | 70 |
request.getSession().setAttribute("message", "Not valid registered service with given id " + id + "."); |
71 | 71 |
response.sendRedirect("./registeredServices"); |
72 | 72 |
logger.warn("Not valid registered service with " + id + "id."); |
73 | 73 |
|
74 | 74 |
} else { |
75 |
System.out.println("Not authorized"); |
|
75 |
//System.out.println("Not authorized");
|
|
76 | 76 |
request.getSession().setAttribute("message", "Not authorized to edit the registered service with id " + id + "."); |
77 | 77 |
response.sendRedirect("./registeredServices"); |
78 | 78 |
logger.warn("Not authorized to edit the service with " + id + "id."); |
... | ... | |
80 | 80 |
} |
81 | 81 |
|
82 | 82 |
} catch (NumberFormatException nfe) { |
83 |
System.out.println("WRONG FORMAT"); |
|
83 |
//System.out.println("WRONG FORMAT");
|
|
84 | 84 |
request.getSession().setAttribute("message", "Invalid service id."); |
85 | 85 |
response.sendRedirect("./registeredServices"); |
86 | 86 |
logger.error("Invalid service id.", nfe); |
87 | 87 |
|
88 | 88 |
} catch (SQLException sqle) { |
89 |
System.out.println("SQL PROBLEM"); |
|
89 |
//System.out.println("SQL PROBLEM");
|
|
90 | 90 |
request.getSession().setAttribute("message", "Could not fetch registered service."); |
91 | 91 |
response.sendRedirect("./registeredServices"); |
92 | 92 |
logger.error("Could not fetch registered service.", sqle); |
... | ... | |
106 | 106 |
} |
107 | 107 |
|
108 | 108 |
private void updateFormFields(HttpServletRequest request, String serviceName, String keyType, ServiceResponse serviceResponse) { |
109 |
System.out.println("UPDATING FORM"); |
|
109 |
//System.out.println("UPDATING FORM");
|
|
110 | 110 |
request.getSession().setAttribute("first_name", serviceName); |
111 |
System.out.println("Service response URI " + serviceResponse.getJwksUri()); |
|
111 |
//System.out.println("Service response URI " + serviceResponse.getJwksUri());
|
|
112 | 112 |
request.getSession().setAttribute("key_type", keyType); |
113 | 113 |
if (keyType != null) { |
114 | 114 |
if (keyType.equals("uri")) { |
... | ... | |
120 | 120 |
} else { |
121 | 121 |
key = new Key(); |
122 | 122 |
} |
123 |
System.out.println("Service response keys " + serviceResponse.getJwksUri()); |
|
123 |
//System.out.println("Service response keys " + serviceResponse.getJwksUri());
|
|
124 | 124 |
Gson gson = new GsonBuilder().setPrettyPrinting().create(); |
125 | 125 |
request.getSession().setAttribute("value", gson.toJson(key)); |
126 | 126 |
} |
... | ... | |
137 | 137 |
boolean canProceed = true; |
138 | 138 |
|
139 | 139 |
String mode = request.getParameter("mode").trim(); |
140 |
System.out.println("Mode was " + mode); |
|
140 |
//System.out.println("Mode was " + mode);
|
|
141 | 141 |
checkmode(mode); |
142 |
System.out.println("Mode is " + mode); |
|
142 |
//System.out.println("Mode is " + mode);
|
|
143 | 143 |
|
144 | 144 |
String serviceId = request.getParameter("id"); |
145 | 145 |
|
... | ... | |
173 | 173 |
request.getSession().setAttribute("value", jwksString); |
174 | 174 |
|
175 | 175 |
if (jwks.getKeys() == null || jwks.getKeys().length == 0) { |
176 |
System.out.println("Something wrong with the keys."); |
|
176 |
//System.out.println("Something wrong with the keys.");
|
|
177 | 177 |
request.getSession().setAttribute("value_error", true); |
178 | 178 |
canProceed = false; |
179 | 179 |
} |
... | ... | |
207 | 207 |
serverRequestJSON = createServiceJson(null, name, email, jwks); |
208 | 208 |
} |
209 | 209 |
if(serverRequestJSON != null) { |
210 |
System.out.println("SERVER JSON " + serverRequestJSON); |
|
210 |
//System.out.println("SERVER JSON " + serverRequestJSON);
|
|
211 | 211 |
serverMessage = tokenUtils.registerService(serverRequestJSON); |
212 | 212 |
logger.debug(serverMessage); |
213 | 213 |
if (serverMessage == null) { |
... | ... | |
252 | 252 |
response.sendRedirect("./registeredServices"); |
253 | 253 |
|
254 | 254 |
} else { |
255 |
System.out.println("In edit..."); |
|
255 |
//System.out.println("In edit...");
|
|
256 | 256 |
try { |
257 | 257 |
serviceIdInt = Integer.parseInt(serviceId); |
258 | 258 |
if (!registeredServicesUtils.isAuthorized(authentication.getSub(), serviceIdInt)) { |
... | ... | |
272 | 272 |
serverRequestJSON = createServiceJson(registeredService.getClientId(), name, email, jwks); |
273 | 273 |
} |
274 | 274 |
if (serverRequestJSON != null) { |
275 |
System.out.println("SERVER JSON " + serverRequestJSON); |
|
275 |
//System.out.println("SERVER JSON " + serverRequestJSON);
|
|
276 | 276 |
HttpResponse resp = tokenUtils.updateService(registeredService.getClientId(), serverRequestJSON, registeredService.getRegistrationAccessToken()); |
277 | 277 |
if (resp.getStatusLine().getStatusCode() == 200) { |
278 |
System.out.println("NAME >>>>" + name); |
|
278 |
//System.out.println("NAME >>>>" + name);
|
|
279 | 279 |
registeredService.setName(name); |
280 | 280 |
|
281 |
System.out.println("Client Id " + registeredService.getClientId()); |
|
281 |
//System.out.println("Client Id " + registeredService.getClientId());
|
|
282 | 282 |
try { |
283 | 283 |
registeredServicesUtils.getRegisteredServiceDao().update(registeredService); |
284 | 284 |
} catch (SQLException sqle) { |
... | ... | |
392 | 392 |
GsonBuilder builder = new GsonBuilder(); |
393 | 393 |
builder.serializeNulls(); |
394 | 394 |
Gson gson = builder.create(); |
395 |
System.out.println("Created json " + serviceJSON); |
|
395 |
//System.out.println("Created json " + serviceJSON);
|
|
396 | 396 |
return gson.toJson(serviceJSON); |
397 | 397 |
} |
398 | 398 |
|
... | ... | |
406 | 406 |
GsonBuilder builder = new GsonBuilder(); |
407 | 407 |
builder.serializeNulls(); |
408 | 408 |
Gson gson = builder.create(); |
409 |
System.out.println("Created json " + serviceJSON); |
|
409 |
//System.out.println("Created json " + serviceJSON);
|
|
410 | 410 |
return gson.toJson(serviceJSON); |
411 | 411 |
} |
412 | 412 |
|
... | ... | |
420 | 420 |
GsonBuilder builder = new GsonBuilder(); |
421 | 421 |
builder.serializeNulls(); |
422 | 422 |
Gson gson = builder.create(); |
423 |
System.out.println("Created json " + serviceJSON); |
|
423 |
//System.out.println("Created json " + serviceJSON);
|
|
424 | 424 |
return gson.toJson(serviceJSON); |
425 | 425 |
} |
426 | 426 |
|
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/TokenUtils.java | ||
---|---|---|
39 | 39 |
CloseableHttpClient httpclient = HttpClients.createDefault(); |
40 | 40 |
HttpResponse httpResponse = httpclient.execute(httppost); |
41 | 41 |
|
42 |
System.out.println("HTTP RESPONSE " + httpResponse.getStatusLine().getStatusCode()); |
|
42 |
//System.out.println("HTTP RESPONSE " + httpResponse.getStatusLine().getStatusCode());
|
|
43 | 43 |
if (httpResponse.getStatusLine().getStatusCode() == 201) { |
44 | 44 |
//logger.debug(IOUtils.toString(httpResponse.getEntity().getContent(), StandardCharsets.UTF_8.name())); |
45 | 45 |
return IOUtils.toString(httpResponse.getEntity().getContent(), StandardCharsets.UTF_8.name()); |
... | ... | |
62 | 62 |
|
63 | 63 |
public HttpResponse deleteService(String serviceId, String registeredAccessToken) throws IOException { |
64 | 64 |
|
65 |
System.out.println("DELETE " + issuer + "register/"+serviceId); |
|
65 |
//System.out.println("DELETE " + issuer + "register/"+serviceId);
|
|
66 | 66 |
HttpDelete httpDelete = new HttpDelete(issuer + "register/"+serviceId); |
67 | 67 |
httpDelete.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); |
68 | 68 |
httpDelete.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + registeredAccessToken); |
... | ... | |
72 | 72 |
} |
73 | 73 |
|
74 | 74 |
public ServiceResponse getRegisteredService(String serviceId, String registeredAccessToken) throws IOException { |
75 |
System.out.println("ISSUER " + issuer); |
|
75 |
//System.out.println("ISSUER " + issuer);
|
|
76 | 76 |
HttpGet httpGet = new HttpGet(issuer + "register/"+ serviceId); |
77 | 77 |
httpGet.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + registeredAccessToken); |
78 | 78 |
|
79 | 79 |
CloseableHttpClient httpclient = HttpClients.createDefault(); |
80 | 80 |
HttpResponse httpResponse = httpclient.execute(httpGet); |
81 | 81 |
String registeredService = IOUtils.toString(httpResponse.getEntity().getContent(), StandardCharsets.UTF_8.name()); |
82 |
System.out.println(registeredService); |
|
82 |
//System.out.println(registeredService);
|
|
83 | 83 |
return new Gson().fromJson(registeredService,ServiceResponse.class); |
84 | 84 |
} |
85 | 85 |
|
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/RegisteredServicesUtils.java | ||
---|---|---|
25 | 25 |
} |
26 | 26 |
|
27 | 27 |
public boolean isAuthorized(String userid, int id) throws SQLException { |
28 |
System.out.println("I AM HERE...."); |
|
29 | 28 |
RegisteredService registeredService = registeredServiceDao.fetchRegisteredServiceById(id); |
30 | 29 |
if (registeredService == null) { |
31 | 30 |
return false; //no harm in accessing nothing |
32 | 31 |
} |
33 |
System.out.println("....and HERE"); |
|
34 |
System.out.println(registeredService.getClientId()); |
|
35 |
System.out.println(registeredService.getOwner()); |
|
36 | 32 |
return registeredService.getOwner().equals(userid); |
37 | 33 |
} |
38 | 34 |
|
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/JwksDeserializer.java | ||
---|---|---|
63 | 63 |
"}"; |
64 | 64 |
Jwks jwks = gson.fromJson(jwksJson, Jwks.class); |
65 | 65 |
for(Key key:jwks.getKeys()) { |
66 |
System.out.println(key.getE()); |
|
66 |
//System.out.println(key.getE());
|
|
67 | 67 |
} |
68 | 68 |
} |
69 | 69 |
} |
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServlet.java | ||
---|---|---|
67 | 67 |
String gRecaptchaResponse = request.getParameter("g-recaptcha-response"); |
68 | 68 |
|
69 | 69 |
boolean isRecaptchaVerified = VerifyRecaptcha.verify(gRecaptchaResponse, secret); |
70 |
//System.out.println("RESPONSE " + gRecaptchaResponse); |
|
70 |
////System.out.println("RESPONSE " + gRecaptchaResponse);
|
|
71 | 71 |
|
72 | 72 |
if (organization == null){ |
73 | 73 |
logger.info("organization is null"); |
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/PersonalTokenServlet.java | ||
---|---|---|
87 | 87 |
HttpResponse response = httpclient.execute(httpDelete); |
88 | 88 |
if (response.getStatusLine().getStatusCode()!=200) { |
89 | 89 |
logger.warn("Could not delete old refresh tokens." + response.getStatusLine().getStatusCode()); |
90 |
System.out.println("Could not delete old refresh tokens." + response.getStatusLine().getStatusCode());//TODO should I throw exception? |
|
90 |
//System.out.println("Could not delete old refresh tokens." + response.getStatusLine().getStatusCode());//TODO should I throw exception?
|
|
91 | 91 |
} |
92 | 92 |
} |
93 | 93 |
} |
... | ... | |
111 | 111 |
} |
112 | 112 |
} |
113 | 113 |
|
114 |
System.out.println("Old refresh tokens... " + oldRefreshTokens); |
|
115 | 114 |
return oldRefreshTokens; |
116 | 115 |
} |
117 | 116 |
} |
Also available in: Unified diff
Removing debug messages