Wednesday, February 18, 2009

PRPC Code: Java code to check the privilege

// Check if the requestor has access ...
// The reqeustor must have either one of the Roles specified
// OR access to one of the privileges specified.
// If both lists are empty the the requestor passes this access check
// Also a list is considered empty if not defined correctly (ie not a page list of the expected class)
// The privilegeList property expects a Page List of Embed-Rule-PrivilegeSecurity

// find tools, as usual
PublicAPI tools = null;
PRThread thisThread = (PRThread)ThreadContainer.get();
if (thisThread != null) {
tools = thisThread.getPublicAPI();
}
ClipboardProperty privilegeList = RulePage.getProperty("pyPrivilegeList");
String strClassName = RulePage.getString("pyClassName");
if (privilegeList.size() == 0) return true;
Dictionary dict = thisThread.getDictionary();
boolean hasSecurity = true;
boolean privsEmpty = true;
String nextPrivValue = null;
String nextPrivClass = null;
ClipboardProperty nextPrivProp;
ClipboardPage nextPrivPage;
Iterator iter = privilegeList.iterator(); // loop over the list of privileges
while (iter.hasNext()) {
nextPrivProp = (ClipboardProperty) iter.next();
nextPrivPage = nextPrivProp.getPageValue();
nextPrivValue = nextPrivPage.getString(".pyPrivilegeName");
if (nextPrivValue == null || nextPrivValue.equals("")) return true;
if (nextPrivValue.equals(PrivilageToCheck)) hasSecurity = false;
} //end more privs
return hasSecurity;

No comments:

Post a Comment