Smart Service is using deprecated API

Hi ,

we have some smart service that is used to unlock document, part of some KC, that were lock more that 2 hours. We did a health check using available action on the forum and we find out following remark about it:
Document Unlocker (documentunlocker) references deprecated Appian APIs
[deprecated] com.appiancorp.suiteapi.common.ServiceLocator.getAdministratorServiceContext()

I am not the one that design this plugin, so I need help. Could you give me an suggestion how to replace that API with some support API and make still useful for the Appian platform?

OriginalPostID-230186

  Discussion posts and replies are publicly visible

  • The recommendation would be to use a user context rather than the admin service context. You can replace ServiceLocator.getAdministratorServiceContext() with WebServiceContextFactory.getServiceContext(<INSERT_USERNAME_HERE>);
  • I would suggest to create secure credentials store with a username(this can avoid hardcoding the username in the plugin code. The plugin code then does not have to store the username in the Java code anywhere). The username field of the secure store should contain the username of a user who is authorized to perform the API call. Most of the times, it is a user with systems admin credentials. Then read the username in plugin code dynamically. Then, use ServiceContextFactory.getServiceContext(username);

    eg:
    String username = null;
                        try {
                                  Map<String, String> securedValues = scs.getSystemSecuredValues(EXTERNAL_KEY) ;
                                  username = securedValues.get(USERNAME_FIELD);
                        } catch (InsufficientPrivilegesException | ObjectNotFoundException e) {
                                  LOG.error("Could not get the Secure credentials key");
                                  e.printStackTrace();
                        }
                        
                        ServiceContext sc_userContext = ServiceContextFactory.getServiceContext(username);

    This way, you do not need to hardcode the username in the plugin code anywhere.
    Only caveat is that you need to create the secure credentials store on every new environment that you need to deploy the plugin on. Also, when you create the secure credential store with some external key name, you need to specify the plugins which should be allowed access to that credential store.
    You can read about the Secure Credential Store here: forum.appian.com/.../Secure_Credentials_Store.html