0001: /*--
0002:
0003: Copyright (C) 2002-2005 Adrian Price.
0004: All rights reserved.
0005:
0006: Redistribution and use in source and binary forms, with or without
0007: modification, are permitted provided that the following conditions
0008: are met:
0009:
0010: 1. Redistributions of source code must retain the above copyright
0011: notice, this list of conditions, and the following disclaimer.
0012:
0013: 2. Redistributions in binary form must reproduce the above copyright
0014: notice, this list of conditions, and the disclaimer that follows
0015: these conditions in the documentation and/or other materials
0016: provided with the distribution.
0017:
0018: 3. The names "OBE" and "Open Business Engine" must not be used to
0019: endorse or promote products derived from this software without prior
0020: written permission. For written permission, please contact
0021: adrianprice@sourceforge.net.
0022:
0023: 4. Products derived from this software may not be called "OBE" or
0024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
0025: appear in their name, without prior written permission from
0026: Adrian Price (adrianprice@users.sourceforge.net).
0027:
0028: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0029: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0030: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0031: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
0032: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0033: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
0034: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0035: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
0036: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
0037: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0038: POSSIBILITY OF SUCH DAMAGE.
0039:
0040: For more information on OBE, please see
0041: <http://obe.sourceforge.net/>.
0042:
0043: */
0044:
0045: package org.obe.client.api.base;
0046:
0047: import org.apache.commons.logging.Log;
0048: import org.apache.log4j.NDC;
0049: import org.obe.client.api.ClientConfig;
0050: import org.obe.client.api.WMClient;
0051: import org.obe.client.api.tool.Parameter;
0052: import org.obe.client.api.tool.ToolInvocation;
0053: import org.obe.xpdl.model.pkg.XPDLPackage;
0054: import org.wfmc.audit.WMAAuditEntryIterator;
0055: import org.wfmc.wapi.*;
0056: import org.wfmc.wapi2.WMEntity;
0057: import org.wfmc.wapi2.WMEntityIterator;
0058:
0059: import javax.security.auth.Subject;
0060: import javax.security.auth.callback.CallbackHandler;
0061: import javax.security.auth.login.LoginContext;
0062: import javax.security.auth.login.LoginException;
0063: import java.lang.reflect.Constructor;
0064: import java.security.*;
0065: import java.security.acl.Group;
0066: import java.util.Iterator;
0067: import java.util.Set;
0068:
0069: /**
0070: * Abstract base class for J2EE client implementations.
0071: * To use this client, please ensure that JNDI is configured with the correct
0072: * InitialContextFactory (set in jndi.properties, or as a system property).
0073: * <p/>
0074: * This interface is based on the WfMC's Interface 2 Client API
0075: * specification. Some of the methods have been modified from the original
0076: * specification to fit within the normal design of Java applications. For
0077: * instance, the WfMC specification functions always return an error object
0078: * (even for success) and uses out parameters to return values. This interface
0079: * returns the value and throws an exception when an error occurs. If no error
0080: * occurs then an exception is not thrown.
0081: *
0082: * @author Adrian Price
0083: */
0084: public abstract class AbstractJAASClient implements WMClient {
0085: // JBoss: The value of this system property is assumed to reference a
0086: // JAAS configuration that uses ClientLoginModule. Under JBoss this is the
0087: // client "other" configuration; to use it you must set the system property
0088: // "java.security.auth.login.config" to "$JBOSS_HOME/client/auth.conf"
0089: protected static final String JAAS_CONFIG = ClientConfig
0090: .getJAASConfig();
0091: protected static final String JAAS_CALLBACK_HANDLER = ClientConfig
0092: .getJAASCallbackHandlerClass();
0093: private static final Class _callerPrincipalClass;
0094: private LoginContext _loginCtx;
0095: private String _callerPrincipal;
0096: private boolean _connected;
0097: private static final Class[] CBH_CTOR_ARGS = {
0098: // (url, user, password)
0099: String.class, String.class, String.class };
0100: protected WorkflowEngineIntf _engine;
0101:
0102: static {
0103: Class cpc = null;
0104: String cpcName = ClientConfig.getJAASCallerPrincipalClass();
0105: if (cpcName != null) {
0106: try {
0107: cpc = Class.forName(cpcName);
0108: } catch (ClassNotFoundException e) {
0109: // Invalid configuration information.
0110: }
0111: }
0112: _callerPrincipalClass = cpc;
0113: }
0114:
0115: protected AbstractJAASClient() {
0116: }
0117:
0118: protected abstract Log getLogger();
0119:
0120: private LoginContext getLoginContext(WMConnectInfo connectInfo)
0121: throws LoginException {
0122:
0123: LoginContext loginCtx = _loginCtx;
0124: if (loginCtx == null) {
0125: CallbackHandler cbh;
0126: try {
0127: Class cbhClass = Class.forName(JAAS_CALLBACK_HANDLER);
0128: Constructor ctor = cbhClass
0129: .getConstructor(CBH_CTOR_ARGS);
0130: cbh = (CallbackHandler) ctor.newInstance(new Object[] {
0131: connectInfo.getEngineName(),
0132: connectInfo.getUserIdentification(),
0133: connectInfo.getPassword() });
0134: } catch (Exception e) {
0135: getLogger()
0136: .error("Unable to create CallbackHandler", e);
0137: throw new LoginException(e.getMessage());
0138: }
0139: if (getLogger().isDebugEnabled())
0140: getLogger().debug(
0141: "getLoginContext: CallbackHandler=" + cbh);
0142: _loginCtx = loginCtx = new LoginContext(JAAS_CONFIG, cbh);
0143: }
0144: return loginCtx;
0145: }
0146:
0147: public synchronized void connect(WMConnectInfo connectInfo)
0148: throws WMConnectException {
0149:
0150: if (_connected) {
0151: throw new WMConnectException(new IllegalStateException(
0152: "Already connected."));
0153: }
0154:
0155: try {
0156: Log logger = getLogger();
0157: boolean debug = logger.isDebugEnabled();
0158: if (connectInfo != null) {
0159: if (debug) {
0160: logger
0161: .debug("Performing JAAS login via '"
0162: + JAAS_CONFIG
0163: + "' entry in configuration file "
0164: + System
0165: .getProperty("java.security.auth.login.config")
0166: + ". Logging in as '"
0167: + connectInfo
0168: .getUserIdentification()
0169: + (connectInfo.getEngineName() == null ? "' locally"
0170: : "' to '"
0171: + connectInfo
0172: .getEngineName()
0173: + '\'')
0174: + " using '" + getProtocol()
0175: + "' protocol");
0176: }
0177:
0178: // Perform JAAS client login.
0179: getLoginContext(connectInfo).login();
0180: _callerPrincipal = connectInfo.getUserIdentification();
0181:
0182: if (debug) {
0183: logger.debug("JAAS login succeeded, subject="
0184: + _loginCtx.getSubject());
0185: }
0186: } else {
0187: if (debug)
0188: logger
0189: .debug("JAAS login skipped - no principal supplied");
0190: }
0191: _connected = true;
0192: } catch (LoginException e) {
0193: throw new WMConnectException(e);
0194: }
0195: }
0196:
0197: public synchronized void disconnect() throws WMConnectException {
0198: if (!_connected) {
0199: throw new WMConnectException(new IllegalStateException(
0200: "Not connected."));
0201: }
0202:
0203: try {
0204: if (_loginCtx != null)
0205: _loginCtx.logout();
0206: } catch (LoginException e) {
0207: throw new WMConnectException(e);
0208: } finally {
0209: _callerPrincipal = null;
0210: _connected = false;
0211: if (getLogger().isDebugEnabled())
0212: getLogger().debug("Disconnected");
0213: }
0214: }
0215:
0216: protected final boolean isConnected() {
0217: return _connected;
0218: }
0219:
0220: protected final Subject getSubject() {
0221: if (!_connected)
0222: throw new IllegalStateException("Not connected.");
0223: return _loginCtx == null ? null : _loginCtx.getSubject();
0224: }
0225:
0226: protected final Object doAsSubject(PrivilegedExceptionAction action)
0227: throws WMWorkflowException {
0228:
0229: try {
0230: pushCallerPrincipal();
0231: Subject subject = getSubject();
0232: return subject == null ? action.run() : Subject.doAs(
0233: subject, action);
0234: } catch (PrivilegedActionException e) {
0235: Exception ee = e.getException();
0236: throw ee instanceof WMWorkflowException ? (WMWorkflowException) ee
0237: : new WMWorkflowException(ee);
0238: } catch (WMWorkflowException e) {
0239: throw e;
0240: } catch (Exception e) {
0241: throw new WMWorkflowException(e);
0242: } finally {
0243: popCallerPrincipal();
0244: }
0245: }
0246:
0247: protected void pushCallerPrincipal() {
0248: // If we didn't authenticate the caller ourselves, see if JAAS can tell
0249: // us the caller's identity.
0250: String callerPrincipal = _callerPrincipal;
0251: if (callerPrincipal == null) {
0252: AccessControlContext context = AccessController
0253: .getContext();
0254: if (context != null) {
0255: Subject subject = Subject.getSubject(context);
0256: if (subject != null) {
0257: if (_callerPrincipalClass == null) {
0258: // If we don't know the exact class that represents the
0259: // caller's identity, just take the first non-group
0260: // principal we encounter.
0261: Set set = subject.getPrincipals();
0262: for (Iterator iter = set.iterator(); iter
0263: .hasNext();) {
0264: Principal p = (Principal) iter.next();
0265: if (!(p instanceof Group)) {
0266: callerPrincipal = p.getName();
0267: break;
0268: }
0269: }
0270: } else {
0271: // If we do know the exact class that represents the
0272: // caller's identity, take the first matching Principal.
0273: Set set = subject
0274: .getPrincipals(_callerPrincipalClass);
0275: if (!set.isEmpty()) {
0276: Principal p = (Principal) set.iterator()
0277: .next();
0278: callerPrincipal = p.getName();
0279: }
0280: }
0281: }
0282: }
0283: }
0284: NDC.push(callerPrincipal);
0285:
0286: if (getLogger().isDebugEnabled())
0287: getLogger().debug(
0288: "Pushed caller principal: " + callerPrincipal);
0289: }
0290:
0291: protected void popCallerPrincipal() {
0292: String callerPrincipal = NDC.pop();
0293:
0294: if (getLogger().isDebugEnabled())
0295: getLogger().debug(
0296: "Popped caller principal: " + callerPrincipal);
0297: }
0298:
0299: public boolean isWorkListHandlerProfileSupported() {
0300: return true;
0301: }
0302:
0303: public boolean isProcessControlStatusProfileSupported() {
0304: return true;
0305: }
0306:
0307: public boolean isProcessDefinitionProfileSupported() {
0308: return true;
0309: }
0310:
0311: public boolean isProcessAdminProfileSupported() {
0312: return true;
0313: }
0314:
0315: public boolean isActivityControlStatusProfileSupported() {
0316: return true;
0317: }
0318:
0319: public boolean isActivityAdminProfileSupported() {
0320: return true;
0321: }
0322:
0323: public boolean isEntityHandlerProfileSupported() {
0324: return false;
0325: }
0326:
0327: public boolean isAuditRecordProfileSupported() {
0328: return false;
0329: }
0330:
0331: public boolean isToolAgentProfileSupported() {
0332: return false;
0333: }
0334:
0335: //
0336: // The following WAPI2 methods have not yet been implemented.
0337: //
0338:
0339: public WMEntity createEntity(WMEntity scopingEntity,
0340: String entityClass, String entityName)
0341: throws WMWorkflowException {
0342:
0343: // TODO: implement WAPI2.createEntity
0344: throw new WMUnsupportedOperationException("createEntity");
0345: }
0346:
0347: public WMEntityIterator listEntities(WMEntity scopingEntity,
0348: WMFilter filter, boolean countFlag)
0349: throws WMWorkflowException {
0350:
0351: // TODO: implement WAPI2.listEntities
0352: throw new WMUnsupportedOperationException("listEntities");
0353: }
0354:
0355: public void deleteEntity(WMEntity scopingEntity, String entityId)
0356: throws WMWorkflowException {
0357:
0358: // TODO: implement WAPI2.deleteEntity
0359: throw new WMUnsupportedOperationException("deleteEntity");
0360: }
0361:
0362: public WMAttributeIterator listEntityAttributes(
0363: WMEntity scopingEntity, String entityId, WMFilter filter,
0364: boolean countFlag) throws WMWorkflowException {
0365:
0366: // TODO: implement WAPI2.getEntityAttributes
0367: throw new WMUnsupportedOperationException("getEntityAttributes");
0368: }
0369:
0370: // Spec. says param 3 is a WMEntity... does that really make sense?
0371: public WMAttribute getEntityAttributeValue(WMEntity scopingEntity,
0372: WMEntity entityHandle, String attributeName)
0373: throws WMWorkflowException {
0374:
0375: // TODO: implement WAPI2.getEntityAttributeValue
0376: throw new WMUnsupportedOperationException(
0377: "getEntityAttributeValue");
0378: }
0379:
0380: // These methods are for retrieving multi-valued entity attributes.
0381: public WMAttributeIterator listEntityAttributeValues(
0382: WMEntity scopingEntity, String entityHandle,
0383: String attributeName) throws WMWorkflowException {
0384:
0385: // TODO: implement WAPI2.getEntityAttributeValues
0386: throw new WMUnsupportedOperationException(
0387: "listEntityAttributeValues");
0388: }
0389:
0390: public void assignEntityAttributeValue(WMEntity entityHandle,
0391: String attributeName, int attributeType,
0392: String attributeValue) throws WMWorkflowException {
0393:
0394: // TODO: implement WAPI2.assignEntityAttributeValue
0395: throw new WMUnsupportedOperationException(
0396: "assignEntityAttributeValue");
0397: }
0398:
0399: public void clearEntityAttributeList(WMEntity entityHandle,
0400: String attributeName) throws WMWorkflowException {
0401:
0402: // TODO: implement WAPI2.clearEntityAttributeList
0403: throw new WMUnsupportedOperationException(
0404: "clearEntityAttributeList");
0405: }
0406:
0407: public void addEntityAttributeValue(WMEntity entityHandle,
0408: String attributeName, int attributeType,
0409: String attributeValue) throws WMWorkflowException {
0410:
0411: // TODO: implement WAPI2.addEntityAttributeValue
0412: throw new WMUnsupportedOperationException(
0413: "addEntityAttributeValue");
0414: }
0415:
0416: public WMEntity openWorkflowDefinition(String name, String scope)
0417: throws WMWorkflowException {
0418:
0419: // TODO: implement WAPI2.openWorkflowDefinition
0420: throw new WMUnsupportedOperationException(
0421: "openWorkflowDefinition");
0422: }
0423:
0424: public void closeWorkflowDefinition(
0425: WMEntity workflowDefinitionHandle)
0426: throws WMWorkflowException {
0427:
0428: // TODO: implement WAPI2.closeWorkflowDefinition
0429: throw new WMUnsupportedOperationException(
0430: "closeWorkflowDefinition");
0431: }
0432:
0433: public String createPackage() throws WMWorkflowException {
0434:
0435: // TODO: implement WAPI2.createPackage
0436: throw new WMUnsupportedOperationException("createPackage");
0437: }
0438:
0439: public void deleteProcessDefinition(String processDefinitionId)
0440: throws WMWorkflowException {
0441:
0442: // TODO: implement WAPI2.deleteProcessDefinition
0443: throw new WMUnsupportedOperationException(
0444: "deleteProcessDefinition");
0445: }
0446:
0447: // Spec. says param 2 is WMTPProcDefinition, but this isn't defined
0448: // anywhere. In any case, for consistency it should be the procDefId.
0449: public WMEntity openProcessDefinition(String procDefId)
0450: throws WMWorkflowException {
0451:
0452: // TODO: implement WAPI2.openProcessDefinition
0453: throw new WMUnsupportedOperationException(
0454: "openProcessDefinition");
0455: }
0456:
0457: public void closeProcessDefinition(WMEntity procModelHandle)
0458: throws WMWorkflowException {
0459:
0460: // TODO: implement WAPI2.closeProcessDefinition
0461: throw new WMUnsupportedOperationException(
0462: "closeProcessDefinition");
0463: }
0464:
0465: public WMEntity addTransition(String procModelId,
0466: String sourceActDefId, String targetActDefId)
0467: throws WMWorkflowException {
0468:
0469: // TODO: implement WAPI2.addTransition
0470: throw new WMUnsupportedOperationException("addTransition");
0471: }
0472:
0473: public void addProcessDataAttribute(String procModelId,
0474: String procDataId, String attributeName, int attributeType,
0475: int attributeLength, String attributeValue)
0476: throws WMWorkflowException {
0477:
0478: // TODO: implement WAPI2.addProcessDataAttribute
0479: throw new WMUnsupportedOperationException(
0480: "addProcessDataAttribute");
0481: }
0482:
0483: public void removeProcessDataAttribute(String procModelId,
0484: String procDataId, String attributeName)
0485: throws WMWorkflowException {
0486:
0487: // TODO: implement WAPI2.removeProcessDataAttribute
0488: throw new WMUnsupportedOperationException(
0489: "removeProcessDataAttribute");
0490: }
0491:
0492: public String getPackageContent(String packageId)
0493: throws WMWorkflowException {
0494: return getPackageContent(packageId, XPDL);
0495: }
0496:
0497: public void setPackageContent(String packageId, String content)
0498: throws WMWorkflowException {
0499:
0500: setPackageContent(packageId, content, XPDL);
0501: }
0502:
0503: public String createPackage(final XPDLPackage pkg)
0504: throws WMWorkflowException {
0505:
0506: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0507: public Object run() throws Exception {
0508: return _engine.createPackage(pkg);
0509: }
0510: };
0511: return (String) doAsSubject(action);
0512: }
0513:
0514: public void updatePackage(final XPDLPackage pkg)
0515: throws WMWorkflowException {
0516:
0517: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0518: public Object run() throws Exception {
0519: _engine.updatePackage(pkg);
0520: return null;
0521: }
0522: };
0523: doAsSubject(action);
0524: }
0525:
0526: public String createPackage(final String content,
0527: final String contentType) throws WMWorkflowException {
0528:
0529: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0530: public Object run() throws Exception {
0531: return _engine.createPackage(content, contentType);
0532: }
0533: };
0534: return (String) doAsSubject(action);
0535: }
0536:
0537: public XPDLPackage getPackage(final String packageId)
0538: throws WMWorkflowException {
0539:
0540: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0541: public Object run() throws Exception {
0542: return _engine.getPackage(packageId);
0543: }
0544: };
0545: return (XPDLPackage) doAsSubject(action);
0546: }
0547:
0548: public String getPackageContent(final String packageId,
0549: final String contentType) throws WMWorkflowException {
0550:
0551: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0552: public Object run() throws Exception {
0553: return _engine
0554: .getPackageContent(packageId, contentType);
0555: }
0556: };
0557: return (String) doAsSubject(action);
0558: }
0559:
0560: public void setPackageContent(final String packageId,
0561: final String content, final String contentType)
0562: throws WMWorkflowException {
0563:
0564: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0565: public Object run() throws Exception {
0566: _engine.setPackageContent(packageId, content,
0567: contentType);
0568: return packageId;
0569: }
0570: };
0571: doAsSubject(action);
0572: }
0573:
0574: public void deletePackage(final String packageId)
0575: throws WMWorkflowException {
0576:
0577: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0578: public Object run() throws Exception {
0579: _engine.deletePackage(packageId);
0580: return null;
0581: }
0582: };
0583: doAsSubject(action);
0584: }
0585:
0586: public WMProcessDefinitionIterator listProcessDefinitions(
0587: final WMFilter filter, final boolean countFlag)
0588: throws WMWorkflowException {
0589:
0590: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0591: public Object run() throws Exception {
0592: return _engine
0593: .listProcessDefinitions(filter, countFlag);
0594: }
0595: };
0596: Object[] list = (Object[]) doAsSubject(action);
0597: return countFlag ? new WMProcessDefinitionIteratorImpl(
0598: list.length)
0599: : new WMProcessDefinitionIteratorImpl(list);
0600: }
0601:
0602: public WMProcessDefinitionStateIterator listProcessDefinitionStates(
0603: String procDefId, final WMFilter filter,
0604: final boolean countFlag) throws WMWorkflowException {
0605:
0606: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0607: public Object run() throws Exception {
0608: return _engine.listProcessDefinitionStates(filter,
0609: countFlag);
0610: }
0611: };
0612: Object[] list = (Object[]) doAsSubject(action);
0613: return countFlag ? new WMProcessDefinitionStateIteratorImpl(
0614: list.length)
0615: : new WMProcessDefinitionStateIteratorImpl(list);
0616: }
0617:
0618: public void changeProcessDefinitionState(final String procDefId,
0619: final WMProcessDefinitionState newState)
0620: throws WMWorkflowException {
0621:
0622: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0623: public Object run() throws Exception {
0624: _engine.changeProcessDefinitionState(procDefId,
0625: newState);
0626: return null;
0627: }
0628: };
0629: doAsSubject(action);
0630: }
0631:
0632: public WMProcessInstanceIterator listProcessInstances(
0633: final WMFilter filter, final boolean countFlag)
0634: throws WMWorkflowException {
0635:
0636: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0637: public Object run() throws Exception {
0638: return _engine.listProcessInstances(filter, countFlag);
0639: }
0640: };
0641: Object[] list = (Object[]) doAsSubject(action);
0642: return countFlag ? new WMProcessInstanceIteratorImpl(
0643: list.length) : new WMProcessInstanceIteratorImpl(list);
0644: }
0645:
0646: public WMProcessInstance getProcessInstance(final String procInstId)
0647: throws WMWorkflowException {
0648:
0649: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0650: public Object run() throws Exception {
0651: return _engine.getProcessInstance(procInstId);
0652: }
0653: };
0654: return (WMProcessInstance) doAsSubject(action);
0655: }
0656:
0657: public String createProcessInstance(final String procDefId,
0658: final String procInstName) throws WMWorkflowException {
0659:
0660: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0661: public Object run() throws Exception {
0662: return _engine.createProcessInstance(procDefId,
0663: procInstName);
0664: }
0665: };
0666: return (String) doAsSubject(action);
0667: }
0668:
0669: public String createProcessInstanceVersioned(final String name,
0670: final String processInstanceName)
0671: throws WMWorkflowException {
0672:
0673: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0674: public Object run() throws Exception {
0675: return _engine.createProcessInstanceVersioned(name,
0676: processInstanceName);
0677: }
0678: };
0679: return (String) doAsSubject(action);
0680: }
0681:
0682: public String startProcess(final String procInstId)
0683: throws WMWorkflowException {
0684:
0685: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0686: public Object run() throws Exception {
0687: return _engine.startProcess(procInstId);
0688: }
0689: };
0690: return (String) doAsSubject(action);
0691: }
0692:
0693: public WMProcessInstanceStateIterator listProcessInstanceStates(
0694: final String procInstId, final WMFilter filter,
0695: final boolean countFlag) throws WMWorkflowException {
0696:
0697: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0698: public Object run() throws Exception {
0699: return _engine.listProcessInstanceStates(procInstId,
0700: filter, countFlag);
0701: }
0702: };
0703: Object[] list = (Object[]) doAsSubject(action);
0704: return countFlag ? new WMProcessInstanceStateIteratorImpl(
0705: list.length) : new WMProcessInstanceStateIteratorImpl(
0706: list);
0707: }
0708:
0709: public void changeProcessInstanceState(final String procInstId,
0710: final WMProcessInstanceState newState)
0711: throws WMWorkflowException {
0712:
0713: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0714: public Object run() throws Exception {
0715: _engine
0716: .changeProcessInstanceState(procInstId,
0717: newState);
0718: return null;
0719: }
0720: };
0721: doAsSubject(action);
0722: }
0723:
0724: public void changeProcessInstancesState(final String procDefId,
0725: final WMFilter filter, final WMProcessInstanceState newState)
0726: throws WMWorkflowException {
0727:
0728: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0729: public Object run() throws Exception {
0730: _engine.changeProcessInstancesState(procDefId, filter,
0731: newState);
0732: return null;
0733: }
0734: };
0735: doAsSubject(action);
0736: }
0737:
0738: public void abortProcessInstance(final String procInstId)
0739: throws WMWorkflowException {
0740:
0741: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0742: public Object run() throws Exception {
0743: _engine.abortProcessInstance(procInstId);
0744: return null;
0745: }
0746: };
0747: doAsSubject(action);
0748: }
0749:
0750: public void abortProcessInstances(final String procDefId,
0751: final WMFilter filter) throws WMWorkflowException {
0752:
0753: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0754: public Object run() throws Exception {
0755: _engine.abortProcessInstances(procDefId, filter);
0756: return null;
0757: }
0758: };
0759: doAsSubject(action);
0760: }
0761:
0762: public void terminateProcessInstance(final String procInstId)
0763: throws WMWorkflowException {
0764:
0765: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0766: public Object run() throws Exception {
0767: _engine.terminateProcessInstance(procInstId);
0768: return null;
0769: }
0770: };
0771: doAsSubject(action);
0772: }
0773:
0774: public void terminateProcessInstances(final String procDefId,
0775: final WMFilter filter) throws WMWorkflowException {
0776:
0777: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0778: public Object run() throws Exception {
0779: _engine.terminateProcessInstances(procDefId, filter);
0780: return null;
0781: }
0782: };
0783: doAsSubject(action);
0784: }
0785:
0786: public void deleteProcessInstance(final String processInstanceId)
0787: throws WMWorkflowException {
0788:
0789: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0790: public Object run() throws Exception {
0791: _engine.deleteProcessInstance(processInstanceId);
0792: return null;
0793: }
0794: };
0795: doAsSubject(action);
0796: }
0797:
0798: public void deleteProcessInstances(
0799: final String processDefinitionId, final WMFilter filter)
0800: throws WMWorkflowException {
0801:
0802: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0803: public Object run() throws Exception {
0804: _engine.deleteProcessInstances(processDefinitionId,
0805: filter);
0806: return null;
0807: }
0808: };
0809: doAsSubject(action);
0810: }
0811:
0812: public WMAttributeIterator listProcessInstanceAttributes(
0813: final String procInstId, final WMFilter filter,
0814: final boolean countFlag) throws WMWorkflowException {
0815:
0816: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0817: public Object run() throws Exception {
0818: return _engine.listProcessInstanceAttributes(
0819: procInstId, filter, countFlag);
0820: }
0821: };
0822: Object[] list = (Object[]) doAsSubject(action);
0823: return countFlag ? new WMAttributeIteratorImpl(list.length)
0824: : new WMAttributeIteratorImpl(list);
0825: }
0826:
0827: public WMAttribute getProcessInstanceAttributeValue(
0828: final String procInstId, final String attrName)
0829: throws WMWorkflowException {
0830:
0831: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0832: public Object run() throws Exception {
0833: return _engine.getProcessInstanceAttributeValue(
0834: procInstId, attrName);
0835: }
0836: };
0837: return (WMAttribute) doAsSubject(action);
0838: }
0839:
0840: public void assignProcessInstanceAttribute(final String procInstId,
0841: final String attrName, final Object attrValue)
0842: throws WMWorkflowException {
0843:
0844: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0845: public Object run() throws Exception {
0846: _engine.assignProcessInstanceAttribute(procInstId,
0847: attrName, attrValue);
0848: return null;
0849: }
0850: };
0851: doAsSubject(action);
0852: }
0853:
0854: public void assignProcessInstancesAttribute(final String procDefId,
0855: final WMFilter filter, final String attrName,
0856: final Object attrValue) throws WMWorkflowException {
0857:
0858: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0859: public Object run() throws Exception {
0860: _engine.assignProcessInstancesAttribute(procDefId,
0861: filter, attrName, attrValue);
0862: return null;
0863: }
0864: };
0865: doAsSubject(action);
0866: }
0867:
0868: public WMActivityInstanceIterator listActivityInstances(
0869: final WMFilter filter, final boolean countFlag)
0870: throws WMWorkflowException {
0871:
0872: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0873: public Object run() throws Exception {
0874: return _engine.listActivityInstances(filter, countFlag);
0875: }
0876: };
0877: Object[] list = (Object[]) doAsSubject(action);
0878: return countFlag ? new WMActivityInstanceIteratorImpl(
0879: list.length) : new WMActivityInstanceIteratorImpl(list);
0880: }
0881:
0882: public WMActivityInstance getActivityInstance(
0883: final String procInstId, final String actInstId)
0884: throws WMWorkflowException {
0885:
0886: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0887: public Object run() throws Exception {
0888: return _engine.getActivityInstance(procInstId,
0889: actInstId);
0890: }
0891: };
0892: return (WMActivityInstance) doAsSubject(action);
0893: }
0894:
0895: public WMActivityInstanceStateIterator listActivityInstanceStates(
0896: final String procInstId, final String actInstId,
0897: final WMFilter filter, final boolean countFlag)
0898: throws WMWorkflowException {
0899:
0900: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0901: public Object run() throws Exception {
0902: return _engine.listActivityInstanceStates(procInstId,
0903: actInstId, filter, countFlag);
0904: }
0905: };
0906: Object[] list = (Object[]) doAsSubject(action);
0907: return countFlag ? new WMActivityInstanceStateIteratorImpl(
0908: list.length) : new WMActivityInstanceStateIteratorImpl(
0909: list);
0910: }
0911:
0912: public void changeActivityInstanceState(final String procInstId,
0913: final String actInstId,
0914: final WMActivityInstanceState newState)
0915: throws WMWorkflowException {
0916:
0917: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0918: public Object run() throws Exception {
0919: _engine.changeActivityInstanceState(procInstId,
0920: actInstId, newState);
0921: return null;
0922: }
0923: };
0924: doAsSubject(action);
0925: }
0926:
0927: public void changeActivityInstancesState(final String procDefId,
0928: final String actDefId, final WMFilter filter,
0929: final WMActivityInstanceState newState)
0930: throws WMWorkflowException {
0931:
0932: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0933: public Object run() throws Exception {
0934: _engine.changeActivityInstancesState(procDefId,
0935: actDefId, filter, newState);
0936: return null;
0937: }
0938: };
0939: doAsSubject(action);
0940: }
0941:
0942: public WMAttributeIterator listActivityInstanceAttributes(
0943: final String procInstId, final String actInstId,
0944: final WMFilter filter, final boolean countFlag)
0945: throws WMWorkflowException {
0946:
0947: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0948: public Object run() throws Exception {
0949: return _engine.listActivityInstanceAttributes(
0950: procInstId, actInstId, filter, countFlag);
0951: }
0952: };
0953: Object[] list = (Object[]) doAsSubject(action);
0954: return countFlag ? new WMAttributeIteratorImpl(list.length)
0955: : new WMAttributeIteratorImpl(list);
0956: }
0957:
0958: public WMAttribute getActivityInstanceAttributeValue(
0959: final String procInstId, final String actInstId,
0960: final String attrName) throws WMWorkflowException {
0961:
0962: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0963: public Object run() throws Exception {
0964: return _engine.getActivityInstanceAttributeValue(
0965: procInstId, actInstId, attrName);
0966: }
0967: };
0968: return (WMAttribute) doAsSubject(action);
0969: }
0970:
0971: public void assignActivityInstanceAttribute(
0972: final String procInstId, final String actInstId,
0973: final String attrName, final Object attrValue)
0974: throws WMWorkflowException {
0975:
0976: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0977: public Object run() throws Exception {
0978: _engine.assignActivityInstanceAttribute(procInstId,
0979: actInstId, attrName, attrValue);
0980: return null;
0981: }
0982: };
0983: doAsSubject(action);
0984: }
0985:
0986: public void assignActivityInstancesAttribute(
0987: final String procDefId, final String actDefId,
0988: final WMFilter filter, final String attrName,
0989: final Object attrValue) throws WMWorkflowException {
0990:
0991: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
0992: public Object run() throws Exception {
0993: _engine.assignActivityInstancesAttribute(procDefId,
0994: actDefId, filter, attrName, attrValue);
0995: return null;
0996: }
0997: };
0998: doAsSubject(action);
0999: }
1000:
1001: public WMWorkItemIterator listWorkItems(final WMFilter filter,
1002: final boolean countFlag) throws WMWorkflowException {
1003:
1004: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1005: public Object run() throws Exception {
1006: return _engine.listWorkItems(filter, countFlag);
1007: }
1008: };
1009: Object[] list = (Object[]) doAsSubject(action);
1010: return countFlag ? new WMWorkItemIteratorImpl(list.length)
1011: : new WMWorkItemIteratorImpl(list);
1012: }
1013:
1014: public WMWorkItem getWorkItem(final String procInstId,
1015: final String workItemId) throws WMWorkflowException {
1016:
1017: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1018: public Object run() throws Exception {
1019: return _engine.getWorkItem(procInstId, workItemId);
1020: }
1021: };
1022: return (WMWorkItem) doAsSubject(action);
1023: }
1024:
1025: public void completeWorkItem(final String procInstId,
1026: final String workItemId) throws WMWorkflowException {
1027:
1028: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1029: public Object run() throws Exception {
1030: _engine.completeWorkItem(procInstId, workItemId);
1031: return null;
1032: }
1033: };
1034: doAsSubject(action);
1035: }
1036:
1037: public void reassignWorkItem(final String sourceUser,
1038: final String targetUser, final String procInstId,
1039: final String workItemId) throws WMWorkflowException {
1040:
1041: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1042: public Object run() throws Exception {
1043: _engine.reassignWorkItem(sourceUser, targetUser,
1044: procInstId, workItemId);
1045: return null;
1046: }
1047: };
1048: doAsSubject(action);
1049: }
1050:
1051: public WMWorkItemStateIterator listWorkItemStates(
1052: final String procInstId, final String workItemId,
1053: final WMFilter filter, final boolean countFlag)
1054: throws WMWorkflowException {
1055:
1056: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1057: public Object run() throws Exception {
1058: return _engine.listWorkItemStates(procInstId,
1059: workItemId, filter, countFlag);
1060: }
1061: };
1062: Object[] list = (Object[]) doAsSubject(action);
1063: return countFlag ? new WMWorkItemStateIteratorImpl(list.length)
1064: : new WMWorkItemStateIteratorImpl(list);
1065: }
1066:
1067: public void changeWorkItemState(final String procInstId,
1068: final String workItemId, final WMWorkItemState newState)
1069: throws WMWorkflowException {
1070:
1071: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1072: public Object run() throws Exception {
1073: _engine.changeWorkItemState(procInstId, workItemId,
1074: newState);
1075: return null;
1076: }
1077: };
1078: doAsSubject(action);
1079: }
1080:
1081: public WMAttributeIterator listWorkItemAttributes(
1082: final String procInstId, final String workItemId,
1083: final WMFilter filter, final boolean countFlag)
1084: throws WMWorkflowException {
1085:
1086: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1087: public Object run() throws Exception {
1088: return _engine.listWorkItemAttributes(procInstId,
1089: workItemId, filter, countFlag);
1090: }
1091: };
1092: Object[] list = (Object[]) doAsSubject(action);
1093: return countFlag ? new WMAttributeIteratorImpl(list.length)
1094: : new WMAttributeIteratorImpl(list);
1095: }
1096:
1097: public WMAttribute getWorkItemAttributeValue(
1098: final String procInstId, final String workItemId,
1099: final String attrName) throws WMWorkflowException {
1100:
1101: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1102: public Object run() throws Exception {
1103: return _engine.getWorkItemAttributeValue(procInstId,
1104: workItemId, attrName);
1105: }
1106: };
1107: return (WMAttribute) doAsSubject(action);
1108: }
1109:
1110: public void assignWorkItemAttribute(final String procInstId,
1111: final String workItemId, final String attrName,
1112: final Object attrValue) throws WMWorkflowException {
1113:
1114: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1115: public Object run() throws Exception {
1116: _engine.assignWorkItemAttribute(procInstId, workItemId,
1117: attrName, attrValue);
1118: return null;
1119: }
1120: };
1121: doAsSubject(action);
1122: }
1123:
1124: public void invokeApplication(int toolAgentHandle, String appName,
1125: String procInstId, String workItemId, Object[] parameters,
1126: int appMode) throws WMWorkflowException {
1127:
1128: // TODO: implement WAPI.invokeApplication
1129: throw new WMUnsupportedOperationException("invokeApplication");
1130: }
1131:
1132: public WMAttribute[] requestAppStatus(int toolAgentHandle,
1133: String procInstId, String workItemId, int[] status)
1134: throws WMWorkflowException {
1135:
1136: // TODO: implement WAPI2.requestAppStatus
1137: throw new WMUnsupportedOperationException("requestAppStatus");
1138: }
1139:
1140: public void terminateApp(int toolAgentHandle, String procInstId,
1141: String workItemId) throws WMWorkflowException {
1142:
1143: // TODO: implement WAPI.terminateApp
1144: throw new WMUnsupportedOperationException("terminateApp");
1145: }
1146:
1147: public WMAAuditEntryIterator listAuditEntries(final WMFilter filter)
1148: throws WMWorkflowException {
1149:
1150: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1151: public Object run() throws Exception {
1152: return _engine.listAuditEntries(filter);
1153: }
1154: };
1155: Object[] list = (Object[]) doAsSubject(action);
1156: return new WMAAuditEntryIteratorImpl(list);
1157: }
1158:
1159: public int deleteAuditEntries(final WMFilter filter)
1160: throws WMWorkflowException {
1161:
1162: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1163: public Object run() throws Exception {
1164: return new Integer(_engine.deleteAuditEntries(filter));
1165: }
1166: };
1167: Object result = doAsSubject(action);
1168: return ((Integer) result).intValue();
1169: }
1170:
1171: public ToolInvocation[] executeWorkItem(final String procInstId,
1172: final String workItemId) throws WMWorkflowException {
1173:
1174: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1175: public Object run() throws Exception {
1176: return _engine.executeWorkItem(procInstId, workItemId);
1177: }
1178: };
1179: return (ToolInvocation[]) doAsSubject(action);
1180: }
1181:
1182: public void toolStarted(final String procInstId,
1183: final String workItemId) throws WMWorkflowException {
1184:
1185: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1186: public Object run() throws Exception {
1187: _engine.toolStarted(procInstId, workItemId);
1188: return null;
1189: }
1190: };
1191: doAsSubject(action);
1192: }
1193:
1194: public void toolFinished(final String procInstId,
1195: final String workItemId, final int appStatus,
1196: final Parameter[] parms) throws WMWorkflowException {
1197:
1198: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
1199: public Object run() throws Exception {
1200: _engine.toolFinished(procInstId, workItemId, appStatus,
1201: parms);
1202: return null;
1203: }
1204: };
1205: doAsSubject(action);
1206: }
1207: }
|