/**
   * Login to the API gateway as an admin
   *
   * @return A session cookie string
   * @throws AxisFault if an error occurs while logging in
   */
  private String login(Environment environment) throws AxisFault {
    String user = environment.getUserName();
    String password = environment.getPassword();
    String serverURL = environment.getServerURL();

    if (serverURL == null || user == null || password == null) {
      throw new AxisFault("Required API gateway admin configuration unspecified");
    }

    String host;
    try {
      host = new URL(serverURL).getHost();
    } catch (MalformedURLException e) {
      throw new AxisFault("API gateway URL is malformed", e);
    }

    AuthenticationAdminStub authAdminStub =
        new AuthenticationAdminStub(null, serverURL + "AuthenticationAdmin");
    ServiceClient client = authAdminStub._getServiceClient();
    Options options = client.getOptions();
    options.setManageSession(true);
    try {
      authAdminStub.login(user, password, host);
      ServiceContext serviceContext =
          authAdminStub._getServiceClient().getLastOperationContext().getServiceContext();
      return (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
    } catch (RemoteException e) {
      throw new AxisFault("Error while contacting the authentication admin services", e);
    } catch (LoginAuthenticationExceptionException e) {
      throw new AxisFault("Error while authenticating against the API gateway admin", e);
    }
  }
  /**
   * Invalidates the registry cache for tiers.xml of given tenant domain
   *
   * @param tenantDomain
   * @throws APIManagementException
   */
  public void clearTiersResourceCache(String tenantDomain) throws APIManagementException {
    String cookie;

    // Clear Gateway Cache
    try {
      String gatewayServerURL;
      for (Map.Entry<String, Environment> entry : environments.entrySet()) {
        Environment environment = entry.getValue();
        gatewayServerURL = environment.getServerURL();
        cookie = login(gatewayServerURL, environment.getUserName(), environment.getPassword());
        clearCache(
            RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + APIConstants.API_TIER_LOCATION,
            tenantDomain,
            gatewayServerURL,
            cookie);
      }
    } catch (AxisFault axisFault) {
      log.error(
          "Error while initializing the OAuth admin service stub in Store for tenant : "
              + tenantDomain,
          axisFault);
    } catch (RemoteException e) {
      log.error(
          "Error while invalidating the tiers.xml cache in gateway for tenant : " + tenantDomain,
          e);
    }
  }
Пример #3
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Environment that = (Environment) o;

    if (!name.equals(that.getName())) return false;
    if (!type.equals(that.getType())) return false;

    return true;
  }