This class would need to be included into a complete Component definition JAR file, published to the SIMULIA Execution Engine library, and marked as “credential-privileged” by the system administrator. /** * Component runtime class that uses credential privileges */ @Privileged // This class requires privileges public class PrivCredTestRuntime extends AbstractComponent { // This field will be set (injected) with a reference to // a CredentialService. @CredentialServiceReference private transient CredentialService serviceRef; /** * Runtime class ctor */ public PrivCredTestRuntime() { // Credential service is not available here in the ctor, the // serviceRef will be null. } /** * Called by the SEE infrastructure at runtime * @param runEnv * @throws RtException */ public void execute(RuntimeEnv runEnv) throws RtException { try { if (serviceRef.isPrivilegeGranted()) { // This component was marked in the library by the system // administrator as having credential privileges CredentialData logonCreds = serviceRef.getServerCreds(); if (logonCreds.isAvailable()) { // Server logon credentials are available. logonMyExternalSystem(logonCreds.getUserName(), logonCreds.getPw()); // ... interact with external system ... } else throw new RtException("Logon credentials are not available."); } else throw new RtException("This component is not marked as privileged."); } catch (RtException rte) { // Allow runtime exceptions to flow up the call stack throw rte; } catch (Throwable e) { // All other exceptions get wrapped in a runtime exception throw new RtException(e, "Failed executing my test component."); } } } |