コード例 #1
0
  /**
   * Create data (ServerConfig loaded at this point)
   *
   * @param idmClient
   * @throws Exception
   */
  public static void createData(CasIdmClient idmClient) throws Exception {
    logger.debug("IdmDataCreator.createData called");

    Validate.notNull(idmClient);

    if (forceCleanup) {
      // delete tenants
      int i = 0;
      String tenantName = ServerConfig.getTenant(i);
      while (tenantName != null) {
        IdmDataRemover.addTenant(tenantName);
        i++;
        tenantName = ServerConfig.getTenant(i);
      }
      try {
        IdmDataRemover.removeData(idmClient);
      } catch (Exception e) {
        logger.debug("Caught exception while removing data {}", e.toString());
      }
      forceCleanup = false;
    }

    // create tenants
    int i = 0;
    String tenantName = ServerConfig.getTenant(i);
    while (tenantName != null) {
      processTenant(idmClient, tenantName);
      i++;
      tenantName = ServerConfig.getTenant(i);
    }
    // process default tenant
    String defaultTenant = ServerConfig.getDefaultTenant();
    idmClient.setDefaultTenant(defaultTenant);
  }
コード例 #2
0
  // create tenant from configuration properties. We do not overwrite existing
  // tenants.
  private static void processTenant(CasIdmClient idmClient, String tenantName) throws Exception {
    // create tenant
    Tenant tenantToCreate = new Tenant(tenantName);
    tenantToCreate._issuerName = ServerConfig.getTenantEntityId(tenantName);
    IdmDataRemover.addTenant(tenantName);

    Tenant existingTenant = null;
    try {
      existingTenant = idmClient.getTenant(tenantName);
      assert (existingTenant != null);
      return;
    } catch (NoSuchTenantException ex) {
      idmClient.addTenant(
          tenantToCreate,
          ServerConfig.getTenantAdminUsername(),
          ServerConfig.getTenantAdminPassword().toCharArray());
    }

    existingTenant = idmClient.getTenant(tenantName);
    assert (existingTenant != null);

    // add entity ID, clock tolerance, certificates and keys
    try {
      idmClient.setEntityID(tenantName, ServerConfig.getTenantEntityId(tenantName));
      idmClient.setClockTolerance(tenantName, ServerConfig.getTenantClockTolerance(tenantName));
      idmClient.setDelegationCount(tenantName, ServerConfig.getTenantDelegationCount(tenantName));
      idmClient.setBrandName(tenantName, ServerConfig.getTenantBrandName(tenantName));
      idmClient.setRenewCount(tenantName, ServerConfig.getTenantRenewCount(tenantName));
      idmClient.setMaximumBearerTokenLifetime(
          tenantName, ServerConfig.getTenantMaximumBearerTokenLifetime(tenantName));
      idmClient.setMaximumHoKTokenLifetime(
          tenantName, ServerConfig.getTenantMaximumHokTokenLifetime(tenantName));
      KeyPair kp = readKeyStore(ServerConfig.getTenantCredentialDescriptor(tenantName));
      idmClient.setTenantCredentials(tenantName, kp.getCertificateChain(), kp.getPrivateKey());
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }

    // create relying parties
    int i = 0;
    String rpName = ServerConfig.getRelyingParty(tenantName, i);
    while (rpName != null) {
      RelyingParty rp = processRelyingParty(idmClient, rpName);
      // add relying party info
      idmClient.addRelyingParty(tenantName, rp);
      i++;
      rpName = ServerConfig.getRelyingParty(tenantName, i);
    }

    // create identity stores
    int j = 0;
    String adProviderName = ServerConfig.getADProvider(tenantName, j);
    while (adProviderName != null) {
      IdentityStoreData adStore = processADProvider(idmClient, adProviderName);
      // add store info
      idmClient.addProvider(tenantName, adStore);
      j++;
      adProviderName = ServerConfig.getADProvider(tenantName, j);
    }
  }