コード例 #1
0
 /**
  * Add the default Resident Identity Provider entry when a new tenant is registered.
  *
  * @param tenantInfo Information about the newly created tenant
  */
 public void onTenantCreate(TenantInfoBean tenantInfo) throws StratosException {
   try {
     String tenantDomain = tenantInfo.getTenantDomain();
     IdentityProvider identityProvider = new IdentityProvider();
     identityProvider.setIdentityProviderName(
         IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME);
     identityProvider.setHomeRealmId("localhost");
     identityProvider.setPrimary(true);
     IdentityProviderManager.getInstance().addResidentIdP(identityProvider, tenantDomain);
   } catch (IdentityApplicationManagementException e) {
     String message =
         "Error when adding Resident Identity Provider entry for tenant "
             + tenantInfo.getTenantDomain();
     log.error(message, e);
     throw new StratosException(message);
   }
 }
コード例 #2
0
  /** @param message - map message which contains data to tenant creation via a rest call. */
  @Override
  public void onMessage(Message message) {

    TenantInfoBean tenantInfoBean = null;
    MapMessage mapMessage;
    if (message instanceof MapMessage) {
      mapMessage = (MapMessage) message;
      String tenantInfoJson;
      try {
        tenantInfoJson = mapMessage.getString(AppFactoryConstants.TENANT_INFO);
        ObjectMapper mapper = new ObjectMapper();
        tenantInfoBean = mapper.readValue(tenantInfoJson, TenantInfoBean.class);

        if (log.isDebugEnabled()) {
          log.debug("Received a message for tenant domain " + tenantInfoBean.getTenantDomain());
        }
        mapMessage.acknowledge();
      } catch (JMSException e) {
        log.error("Error while getting message content.", e);
        throw new RuntimeException(e);
      } catch (JsonParseException e) {
        log.error("Error while converting the json to object.", e);
        throw new RuntimeException(e);
      } catch (JsonMappingException e) {
        log.error("Error while converting the json to object.", e);
        throw new RuntimeException(e);
      } catch (IOException e) {
        log.error("Error while converting the json to object.", e);
        throw new RuntimeException(e);
      }
    }

    try {
      int tenantId =
          ServiceHolder.getRealmService()
              .getTenantManager()
              .getTenantId(tenantInfoBean.getTenantDomain());
      if (tenantId == MultitenantConstants.INVALID_TENANT_ID) {
        addTenant(tenantInfoBean);
      } else {
        if (log.isDebugEnabled()) {
          log.debug(
              "Tenant Already exist, skipping the tenant addition. Tenant domain : "
                  + tenantInfoBean.getTenantDomain()
                  + "and tenant Id : "
                  + tenantInfoBean.getTenantId());
        }
      }

    } catch (JMSException e) {
      String msg = "Can not read received map massage";
      log.error(msg, e);
      throw new RuntimeException(e);
    } catch (AppFactoryException e) {
      String msg = "Can not create tenant";
      log.error(msg, e);
      throw new RuntimeException(e);
    } catch (Exception e) {
      String msg = "Can not create tenant";
      log.error(msg, e);
      throw new RuntimeException(e);
    }
  }