001: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.channels.permissionsmanager;
007:
008: import java.util.HashMap;
009:
010: import org.jasig.portal.IPermissible;
011: import org.jasig.portal.IServant;
012: import org.jasig.portal.PortalException;
013: import org.jasig.portal.security.IAuthorizationPrincipal;
014: import org.jasig.portal.security.IPermission;
015: import org.apache.commons.logging.Log;
016: import org.apache.commons.logging.LogFactory;
017: import org.jasig.portal.utils.XSLT;
018:
019: /**
020: * CPermissionsManagerServant is an IServant subclass of CPermissionsManager
021: * This will allow other channels to delegate to CPermissionsManager at runtime
022: *
023: * Master channels should instantiate this channel with the following
024: * staticData parameter preset:
025: *
026: * prmOwners = IPermissible[] owners
027: *
028: * where owners is an array with a single element being an instance of the
029: * master's representative IPermissible class.
030: *
031: * see org.jasig.portal.IPermissible for more information
032: *
033: * @author Alex Vigdor
034: * @version $Revision: 36568 $
035: */
036: public class CPermissionsManagerServant extends CPermissionsManager
037: implements IServant {
038: private static final Log log = LogFactory
039: .getLog(CPermissionsManagerServant.class);
040:
041: private IPermission[] results;
042:
043: /** Creates new CPermissionsManagerServant */
044: public CPermissionsManagerServant() {
045: }
046:
047: /**
048: * put your documentation comment here
049: * @param xslt
050: */
051: protected void transform(XSLT xslt) {
052: if (!isFinished()) {
053: try {
054: xslt.setStylesheetParameter("isAdminUser", "true");
055: xslt.transform();
056: } catch (Exception e) {
057: log.debug(e, e);
058: }
059: }
060: }
061:
062: /**
063: * put your documentation comment here
064: *
065: * @return <code>true</code> if finished; <code>false</code> otherwise
066: */
067: public boolean isFinished() {
068: return session.isFinished;
069: }
070:
071: /**
072: * put your documentation comment here
073: * Currently returns and empy array
074: * @return the results
075: */
076: public Object[] getResults() {
077: return results;
078: }
079:
080: public void setStaticData(org.jasig.portal.ChannelStaticData sD)
081: throws PortalException {
082: super .setStaticData(sD);
083: session.isAuthorized = true;
084:
085: // handle pre-selection for servant mode
086: if (session.staticData.get("prmOwners") != null) {
087: log
088: .debug("PermissionServant.setStaticData(): processing pre-selection");
089:
090: // use specified set of owners
091: IPermissible[] selOwners = (IPermissible[]) session.staticData
092: .get("prmOwners");
093: for (int j = 0; j < selOwners.length; j++) {
094: PermissionsXML.setSelected(session, selOwners[j]
095: .getClass().getName(), "owner", selOwners[j]
096: .getOwnerToken(), true);
097:
098: if (session.staticData.get("prmTargets") != null) {
099: if (((HashMap) session.staticData.get("prmTargets"))
100: .get(selOwners[j].getOwnerToken()) != null) {
101: String[] selTargets = (String[]) ((HashMap) session.staticData
102: .get("prmTargets")).get(selOwners[j]
103: .getOwnerToken());
104: if (log.isDebugEnabled())
105: log
106: .debug("PermissionServant.setStaticData(): got "
107: + selTargets.length
108: + " pre-selected targets");
109: for (int s = 0; s < selTargets.length; s++) {
110: PermissionsXML.setSelected(session,
111: selOwners[j].getClass().getName(),
112: "target", selTargets[s], true);
113: }
114: session.gotTargets = true;
115: } else {
116: log
117: .debug("PermissionServant.setStaticData(): error retrieving pre-selected targets");
118: }
119: }
120:
121: if (session.staticData.get("prmActivities") != null) {
122: if (((HashMap) session.staticData
123: .get("prmActivities")).get(selOwners[j]
124: .getOwnerToken()) != null) {
125: String[] selActivities = (String[]) ((HashMap) session.staticData
126: .get("prmActivities")).get(selOwners[j]
127: .getOwnerToken());
128: if (log.isDebugEnabled())
129: log
130: .debug("PermissionServant.setStaticData(): got "
131: + selActivities.length
132: + " pre-selected activities");
133: for (int s = 0; s < selActivities.length; s++) {
134: PermissionsXML.setSelected(session,
135: selOwners[j].getClass().getName(),
136: "activity", selActivities[s], true);
137: }
138: session.gotActivities = true;
139: } else {
140: log
141: .debug("PermissionServant.setStaticData(): error retrieving pre-selected activities");
142: }
143: }
144:
145: }
146: session.gotOwners = true;
147: }
148: if (session.staticData.get("prmPrincipals") != null) {
149: session.principals = (IAuthorizationPrincipal[]) session.staticData
150: .get("prmPrincipals");
151: PermissionsXML.populatePrincipals(session);
152: }
153: }
154: }
|