Skip to content

Commit

Permalink
Initial addition of 'display' object to XMLAuthenticationTest. This i…
Browse files Browse the repository at this point in the history
…mplementation is for easy testing of the UI. I will continue filling in the implementation. #65
  • Loading branch information
JoelProminic committed Nov 11, 2024
1 parent d09fd88 commit 30665cc
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.xml.parsers.ParserConfigurationException;

import org.json.JSONArray;
import org.json.JSONObject;
import org.w3c.dom.Element;

import com.moonshine.domino.crud.CRUDAgentBase;
Expand Down Expand Up @@ -115,6 +116,8 @@ else if (user.equals(SecurityInterface.ANONYMOUS)) {
for (String role : roles) {
jsonRoles.put(role);
}

jsonRoot.put("display", getDisplayRules(agentDatabase));
}
else {
Element rolesElement = xmlDoc.createElement("roles");
Expand All @@ -125,9 +128,10 @@ else if (user.equals(SecurityInterface.ANONYMOUS)) {
}

xmlRoot.appendChild(rolesElement);

// TODO: support display as well
}


}

/**
Expand Down Expand Up @@ -203,4 +207,36 @@ else if (DominoUtils.isValueEmpty(vector.get(0).toString())) {
}

}


public JSONObject getDisplayRules(Database configDatabase) {
JSONObject display = new JSONObject();
display.put("documentation", shouldDisplay(configDatabase, "documentation"));
display.put("installApps", shouldDisplay(configDatabase, "installApps"));
display.put("genesisDirectory", shouldDisplay(configDatabase, "genesisDirectory"));
display.put("viewInstalledApps", shouldDisplay(configDatabase, "viewInstalledApps"));
display.put("viewBookmarks", shouldDisplay(configDatabase, "viewBookmarks"));
display.put("manageBookmarks", shouldDisplay(configDatabase, "manageBookmarks"));
display.put("browseMyServer", shouldDisplay(configDatabase, "browseMyServer"));
return display;
}

/**
* Determine whether the interface indicated by the given ID should be displayed, based on the user roles and configuration values.
* The configuration document for a given sectionID is "allow_sectionID".
* @param configDatabase - the database instance for configuration
* @param sectionID the ID of the section to check
*
*/
public boolean shouldDisplay(Database configDatabase, String sectionID) {
try {
String value = ConfigurationUtils.getConfigAsString(configDatabase, "allow_" + sectionID);
return "true".equalsIgnoreCase(value);
// treat any other value as false
}
catch (Exception ex) {
getLog().err("Exception when checking display rights for '" + sectionID + "'. Default to hidden");
return false;
}
}
}

0 comments on commit 30665cc

Please sign in to comment.