|
Hi Seth, I actually access the navigation.xml from within flow. I pass all function calls through a 'main' function and this calls a 'checkUserSecurity(functionName)' function where the user's access is checked. In the sitemap I have: <map:match pattern="*.do"> <map:call function="main"> <map:parameter name="page" value="{1}" /> </map:call> </map:match> In my navigation.xml I have: <menu label="Access" href=""> <menu-item href="" ignoreRole="true" label="Login" roleName="Public" role="0"/> <menu-item href="" ignoreRole="true" label="Logout" roleName="Public" role="0"/> <menu-item href="" label="Edit password reminder lists" roleName="Administer Users" role="1"/> <menu-item href="" label="eService Admin" roleName="Administer Eservices" role="512"/> <menu-item href="" label="Database Connections" roleName="Administer Hierarchies" role="256"/> <menu-item href="" label="View Link Types" roleName="Public" role="1"/> <menu-item href="" label="Edit Sitemap Components" roleName="Administer Hierarchies" role="1024"/> </menu> If I am trying to call 'signOnForm.do', it gets passed to 'main'. My credentials and the role against the function are checked against each other and if its OK the finction is then called. If the function has an 'ignoreRole' attribute set to true, then no checking takes place and the function is called. I use a simple bit flag mechanism to determine a user's permissions. The user's role number (stored in user.userLogin.rol_num ) is ANDed against the function's role number. Eg if a user's role number is 2560 and the function has a role of 512 then the user has access to this function (2560 AND 512 = 512 [true]). The user details can be obtained from a database or a simple ACL xml file living under cocoon. The advantage for me is that I can impose a fairly flexible authentication structure without having to resort to any java (such is the wonderful nature of Cocoon!!). The relevant bits of flow are listed below. Using this process I can change menu items on the fly depending on user permissions by transforming the navigation.xml document and bitshifting the function's role and the user's role in XSL. But that's another story! I hope this lengthy reply helps! Regards, Tony function main() { var funName = cocoon.parameters["page"]; print("Function Main(). Calling " + funName + "..."); var fun = this[funName]; print("Check that user has security to access the function: '" + funName + "'"); print("First: make sure user's security setting is in session:"); var userRoleNum = 0; userRoleNum = cocoon.session.getAttribute("securityAccess"); if(((userRoleNum == null) || (userRoleNum == 0)) && (user != null)){ print("Users session role num = " + userRoleNum); print("User's session role num has been clobbered. Re-add it."); cocoon.session.setAttribute("securityAccess",user.userLogin.rol_num); } var functionRedirect = checkUserSecurity(funName); print("Redirected function = " + functionRedirect); fun = this[functionRedirect]; var args = new Array(arguments.length -1); for (var i = 1; i < arguments.length; i++) { args[i-1] = arguments[i]; print("Args: " + args[i-1]); } message=""; fun.apply(args); } function checkUserSecurity(psFuncName){ //Check user role against function role and returns the // function you're trying to get to if OK or else directs you to // the welcome screen where you can read the error message. print("*****************************************************************"); print("In checkUserSecurity. Checking user access to '" + psFuncName + "'"); print("Is the function an aim specific function?"); print("Do we ignore this role?"); var ignoreRole = getIgnoreRoleStatus(psFuncName); if(ignoreRole == "true"){ print("Yes we do."); return psFuncName; } if((user == null) || (typeof(user) == 'undefined')){ print("user is null - hasn't logged on."); return 'welcome'; } var userRole = user.userLogin.rol_num; print("User's magic number = " + userRole); var lFuncMagNum = getFunctionMagicNumber(psFuncName); print("Role number for this function = " + lFuncMagNum); var biLevel = new Packages.java.math.BigInteger(userRole + ""); var biAccess = new Packages.java.math.BigInteger(lFuncMagNum + ""); var result = biLevel.and(biAccess).intValue(); print("Result of ANDing " + userRole + " AND " + lFuncMagNum + " = " + result); if(result > 0){ print("*****************************************************************"); return psFuncName; } else { message = "You don't have the required pemissions to access the '" + psFuncName + "' function."; setMessage(message); print("*****************************************************************"); return 'welcome'; } } function getFunctionMagicNumber(psFunctionName){ print("Loading the navigation document."); var navDoc = loadDocument("cocoon:/xml/navigation.xml"); if(navDoc != null){ print("Looking for element with href attribute of '" + psFunctionName + ".do'"); var navElement = getNodesByAttribute(navDoc, "menu-item", "href", Trim(psFunctionName) + ".do"); if(navElement != null){ print("Found element, get role attribute."); var roleVal = getNodeAttributeValue(navElement, "role"); var label = getNodeAttributeValue(navElement, "label"); print("Menu item label = " + label); print("Role setting = " + roleVal); return roleVal; } else { print("Could not find role attribute in element " + getNodeText(navElement)); return null; } } else { message = "Could not find navigation document. Please notify administrator."; print(message); return null; } } function getNodesByAttribute(document, elmntName, attrName, attrValue) { /** elmntName = "hNode" * attrName = the attribute we're trying to find. * attrValue = the atrribute's value we're trying to retrieve * Returns the nodes whose attr = the value parm */ print("In getNodesByAttribute: element Name = " + elmntName + "; Attribute Name = " + attrName + "; Attribute Value = " + attrValue); if(document == null){ print("Document is null!"); return null; } var node = null; print("Getting all parentNode or childNode elements: getElementsByTagName(" + elmntName + ")"); var pnodes = document.getElementsByTagName(elmntName); var nodeLen = pnodes.getLength(); print("Number of elements retrieved = " + nodeLen); if (nodeLen == 0) { //Node don't exist! return null; } else { //We've found some Node elements, //see if the id attribute value = nodeId parm. for (var i = 0; i < nodeLen; i++) { node = pnodes.item(i); if (node != null) { if (node.hasAttributes()) { var attributes = node.getAttributes(); var idAttribute = attributes.getNamedItem(attrName); if (idAttribute != null){ if (idAttribute.getNodeValue().equals(attrValue)) { return node; } } else { return null; } } } } return null; } } function getNodeAttributeValue(domNode,attributeName){ if(domNode == null){ return null; } if (domNode.hasAttributes()) { var attributes = domNode.getAttributes(); var idAttribute = attributes.getNamedItem(attributeName); if (idAttribute != null){ return idAttribute.getNodeValue(); } else { return null; } } else { return null; } } Seth Foss wrote:
-- |
- Re: Restrict users to flow tedwards
- RE: Restrict users to flow Seth Foss
