您可以在多租户或单租户环境中使用带有已配置的 vRA 身份验证的 REST API SDK。

要获取以下代码所需的身份验证令牌 (Oauth2.0),请参见知识库文章《使用 Oauth2.0 身份验证的 vRO REST API 授权 (2148518)》

注:

以 VRealize Automation 身份验证模式获取会话

以下示例代码在单租户和多租户环境中以 vRealize Automation 身份验证模式获取会话。

  • 如果未启用多租户功能:

    URI uri = URI.create("https://orchestrator-server:8283/vco/api");
    VcoSessionFactory sessionFactory = new DefaultVcoSessionFactory(uri);
    String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJqdGkiOiJjNzg4NWNiYS1hZTFmLTRiM2UtYmYyYi04ZmRmNzY3N"
    + "GZiZWEiLCJwcm4iOiJhZG1pbmlzdHJhdG9yQFZTUEhFUkUuTE9DQUwiLCJkb21haW4iOiJ2c3BoZXJlLmxvY2FsIiwidXNlcl9pZCI6Ij"
    + "MiLCJhdXRoX3RpbWUiOjE1MDIyMDIxMTAsImlzcyI6Imh0dHBzOi8vc2YtMjktMTAtMjkuc29mLW1idS5lbmcudm13YXJlLmN"
    + "vbS9TQUFTL3QvdnNwaGVyZS5sb2NhbC9hdXRoIiwiYXVkIjoiaHR0cHM6Ly9zZi0yOS0xMC0yOS5zb2YtbWJ1LmVuZy52bXdhcmUuY29tL"
    + "1NBQVMvdC92c3BoZXJlLmxvY2FsL2F1dGgvb2F1dGh0b2tlbiIsImN0eCI6Ilt7XCJtdGRcIjpcInVybjpvYXNpczpuYW1lczp"
    + "0YzpTQU1MOjIuMDphYzpjbGFzc2VzOlBhc3N3b3JkUHJvdGVjdGVkVHJhbnNwb3J0XCIsXCJpYXRcIjoxNTAyMjAyMTEwLFwiaWRcIjoxM"
    + "n1dIiwic2NwIjoidXNlciIsImlkcCI6IjAiLCJlbWwiOiJhZG1pbmlzdHJhdG9yQHNmLTI5LTEwLTI5LnNvZi1tYnUuZW5nLnZ"
    + "td2FyZS5jb20iLCJjaWQiOiJjYWZlX2NsaS1yRlJlNEx6bURnIiwiZGlkIjoiIiwid2lkIjoiIiwiZXhwIjoxNTAyMjMwOTEwLCJpYXQiOj"
    + "E1MDIyMDIxMTAsInN1YiI6IjQ1ZjQwNWUzLTNlNTgtNGJmZC1hNzMwLTQ1MjU4OWIxOGUxNyIsInBybl90eXBlIjoiVVNFUiJ9."
    + "G9gEQPtmEH5jYab-IlTK8NFYcwc3JZCEEjsmpUSH6oxLmZKEf-1JbsysBVH4ufqmGah3GMvmy6PUiTTamLRLFkCLwa50OQCQ-qgKutZl21R"
    + "m740qBKLhmBB0NQg19ysMAVJNSxapFzirmWurF_5CKpv4WM7Y8H_bY9iNmDKQTXI";
    
    //provide OAuth2 token obtained in step 1 here
    Authentication auth = new OAuthTokenAuthentication(token);
    
    VcoSession session = sessionFactory.newSession(auth);
    //Use the session here
  • 如果启用了多租户功能:

    • 对于常规租户用户:

      URI uri = URI.create("https://orchestrator-server:8283/vco/api");
      VcoSessionFactory sessionFactory = new DefaultVcoSessionFactory(uri);
      String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJqdGkiOiJjNzg4NWNiYS1hZTFmLTRiM2UtYmYyYi04ZmRmNzY3N"
      + "GZiZWEiLCJwcm4iOiJhZG1pbmlzdHJhdG9yQFZTUEhFUkUuTE9DQUwiLCJkb21haW4iOiJ2c3BoZXJlLmxvY2FsIiwidXNlcl9pZCI6Ij"
      + "MiLCJhdXRoX3RpbWUiOjE1MDIyMDIxMTAsImlzcyI6Imh0dHBzOi8vc2YtMjktMTAtMjkuc29mLW1idS5lbmcudm13YXJlLmN"
      + "vbS9TQUFTL3QvdnNwaGVyZS5sb2NhbC9hdXRoIiwiYXVkIjoiaHR0cHM6Ly9zZi0yOS0xMC0yOS5zb2YtbWJ1LmVuZy52bXdhcmUuY29tL"
      + "1NBQVMvdC92c3BoZXJlLmxvY2FsL2F1dGgvb2F1dGh0b2tlbiIsImN0eCI6Ilt7XCJtdGRcIjpcInVybjpvYXNpczpuYW1lczp"
      + "0YzpTQU1MOjIuMDphYzpjbGFzc2VzOlBhc3N3b3JkUHJvdGVjdGVkVHJhbnNwb3J0XCIsXCJpYXRcIjoxNTAyMjAyMTEwLFwiaWRcIjoxM"
      + "n1dIiwic2NwIjoidXNlciIsImlkcCI6IjAiLCJlbWwiOiJhZG1pbmlzdHJhdG9yQHNmLTI5LTEwLTI5LnNvZi1tYnUuZW5nLnZ"
      + "td2FyZS5jb20iLCJjaWQiOiJjYWZlX2NsaS1yRlJlNEx6bURnIiwiZGlkIjoiIiwid2lkIjoiIiwiZXhwIjoxNTAyMjMwOTEwLCJpYXQiOj"
      + "E1MDIyMDIxMTAsInN1YiI6IjQ1ZjQwNWUzLTNlNTgtNGJmZC1hNzMwLTQ1MjU4OWIxOGUxNyIsInBybl90eXBlIjoiVVNFUiJ9."
      + "G9gEQPtmEH5jYab-IlTK8NFYcwc3JZCEEjsmpUSH6oxLmZKEf-1JbsysBVH4ufqmGah3GMvmy6PUiTTamLRLFkCLwa50OQCQ-qgKutZl21R"
      + "m740qBKLhmBB0NQg19ysMAVJNSxapFzirmWurF_5CKpv4WM7Y8H_bY9iNmDKQTXI";
      
      //provide OAuth2 token obtained in step 1 here
      Authentication auth = new OAuthTokenAuthentication(token);
      
      VcoSession session = sessionFactory.newSession(auth);
      //The operations will be executed in the scope of the tenant authenticated with the token above.
      
      //Use the session below
      
    • 对于解决方案用户:

      解决方案用户可以在其自身租户范围内和常规租户范围内工作。这些用户可以更改所执行操作的范围。

      URI uri = URI.create("https://orchestrator-server:8283/vco/api");
      VcoSessionFactory sessionFactory = new DefaultVcoSessionFactory(uri);
      
      exapmle
      
      String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJqdGkiOiJjNzg4NWNiYS1hZTFmLTRiM2UtYmYyYi04ZmRmNzY3N"
      + "GZiZWEiLCJwcm4iOiJhZG1pbmlzdHJhdG9yQFZTUEhFUkUuTE9DQUwiLCJkb21haW4iOiJ2c3BoZXJlLmxvY2FsIiwidXNlcl9pZCI6Ij"
      + "MiLCJhdXRoX3RpbWUiOjE1MDIyMDIxMTAsImlzcyI6Imh0dHBzOi8vc2YtMjktMTAtMjkuc29mLW1idS5lbmcudm13YXJlLmN"
      + "vbS9TQUFTL3QvdnNwaGVyZS5sb2NhbC9hdXRoIiwiYXVkIjoiaHR0cHM6Ly9zZi0yOS0xMC0yOS5zb2YtbWJ1LmVuZy52bXdhcmUuY29tL"
      + "1NBQVMvdC92c3BoZXJlLmxvY2FsL2F1dGgvb2F1dGh0b2tlbiIsImN0eCI6Ilt7XCJtdGRcIjpcInVybjpvYXNpczpuYW1lczp"
      + "0YzpTQU1MOjIuMDphYzpjbGFzc2VzOlBhc3N3b3JkUHJvdGVjdGVkVHJhbnNwb3J0XCIsXCJpYXRcIjoxNTAyMjAyMTEwLFwiaWRcIjoxM"
      + "n1dIiwic2NwIjoidXNlciIsImlkcCI6IjAiLCJlbWwiOiJhZG1pbmlzdHJhdG9yQHNmLTI5LTEwLTI5LnNvZi1tYnUuZW5nLnZ"
      + "td2FyZS5jb20iLCJjaWQiOiJjYWZlX2NsaS1yRlJlNEx6bURnIiwiZGlkIjoiIiwid2lkIjoiIiwiZXhwIjoxNTAyMjMwOTEwLCJpYXQiOj"
      + "E1MDIyMDIxMTAsInN1YiI6IjQ1ZjQwNWUzLTNlNTgtNGJmZC1hNzMwLTQ1MjU4OWIxOGUxNyIsInBybl90eXBlIjoiVVNFUiJ9."
      + "G9gEQPtmEH5jYab-IlTK8NFYcwc3JZCEEjsmpUSH6oxLmZKEf-1JbsysBVH4ufqmGah3GMvmy6PUiTTamLRLFkCLwa50OQCQ-qgKutZl21R"
      + "m740qBKLhmBB0NQg19ysMAVJNSxapFzirmWurF_5CKpv4WM7Y8H_bY9iNmDKQTXI";
      
      //provide OAuth2 token obtained in step 1 here
      Authentication auth = new OAuthTokenAuthentication(token);
      
      
      // By default each tenant works in its tenant scope. However, solution users can overrde the tenant in which they performa a given operation:
      // Here, users of SDK should provide a value that is meanningful to their context.
      String overrideWithTenant = "nonSolutionUserTenant";
      
      
      VcoSession session = sessionFactory.newSession(auth, overrideWithTenant);
      
      //Use session below