Skip to content

Commit

Permalink
Merge pull request #403 from WildMeOrg/notification-check-optimization
Browse files Browse the repository at this point in the history
Prevent unauthenticated users from opening an unneeded database conne…
  • Loading branch information
TanyaStere42 committed Mar 8, 2024
2 parents 57abe8e + 9b11414 commit c82c789
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions src/main/webapp/header.jsp
Expand Up @@ -41,8 +41,6 @@ context=ServletUtilities.getContext(request);
String langCode=ServletUtilities.getLanguageCode(request);
Properties props = new Properties();
props = ShepherdProperties.getProperties("header.properties", langCode, context);
Shepherd myShepherd = new Shepherd(context);
myShepherd.setAction("header.jsp");
String urlLoc = "//" + CommonConfiguration.getURLLocation(request);
Expand All @@ -65,33 +63,37 @@ if (organization!=null && organization.toLowerCase().equals("indocet")) {
indocetUser = true;
}
String notifications="";
myShepherd.beginDBTransaction();
try {
notifications=Collaboration.getNotificationsWidgetHtml(request, myShepherd);
if(!indocetUser && request.getUserPrincipal()!=null && !loggingOut){
user = myShepherd.getUser(request);
username = (user!=null) ? user.getUsername() : null;
String orgName = "indocet";
Organization indocetOrg = myShepherd.getOrganizationByName(orgName);
indocetUser = ((user!=null && user.hasAffiliation(orgName)) || (indocetOrg!=null && indocetOrg.hasMember(user)));
if(user.getUserImage()!=null){
profilePhotoURL="/"+CommonConfiguration.getDataDirectoryName(context)+"/users/"+user.getUsername()+"/"+user.getUserImage().getFilename();
}
}
}
catch(Exception e){
System.out.println("Exception on indocetCheck in header.jsp:");
e.printStackTrace();
myShepherd.closeDBTransaction();
}
finally{
myShepherd.rollbackDBTransaction();
myShepherd.closeDBTransaction();
}
//check if user is logged in and has pending notifications
if(request.getUserPrincipal()!=null){
Shepherd myShepherd = new Shepherd(context);
myShepherd.setAction("header.jsp");
myShepherd.beginDBTransaction();
try {
notifications=Collaboration.getNotificationsWidgetHtml(request, myShepherd);
if(!indocetUser && request.getUserPrincipal()!=null && !loggingOut){
user = myShepherd.getUser(request);
username = (user!=null) ? user.getUsername() : null;
String orgName = "indocet";
Organization indocetOrg = myShepherd.getOrganizationByName(orgName);
indocetUser = ((user!=null && user.hasAffiliation(orgName)) || (indocetOrg!=null && indocetOrg.hasMember(user)));
if(user.getUserImage()!=null){
profilePhotoURL="/"+CommonConfiguration.getDataDirectoryName(context)+"/users/"+user.getUsername()+"/"+user.getUserImage().getFilename();
}
}
}
catch(Exception e){
System.out.println("Exception on indocetCheck in header.jsp:");
e.printStackTrace();
myShepherd.closeDBTransaction();
}
finally{
myShepherd.rollbackDBTransaction();
myShepherd.closeDBTransaction();
}
}
%>


Expand Down

0 comments on commit c82c789

Please sign in to comment.