Пример #1
0
  private boolean isPartitionSupported(final List<IdentityConfiguration> configurations) {
    for (IdentityConfiguration configuration : configurations) {
      for (IdentityStoreConfiguration storeConfig : configuration.getStoreConfiguration()) {
        if (storeConfig.supportsPartition()
            && storeConfig.supportsType(Realm.class, IdentityOperation.create)) {
          return true;
        }
      }
    }

    return false;
  }
  public DefaultPartitionManager(
      Collection<IdentityConfiguration> configurations,
      EventBridge eventBridge,
      Collection<PermissionHandler> permissionHandlers,
      IdGenerator idGenerator) {
    if (configurations == null || configurations.isEmpty()) {
      throw MESSAGES.configNoIdentityConfigurationProvided();
    }

    ROOT_LOGGER.partitionManagerBootstrap();

    try {
      this.configurations = Collections.unmodifiableCollection(configurations);

      if (eventBridge != null) {
        this.eventBridge = eventBridge;
      } else {
        this.eventBridge =
            new EventBridge() {
              public void raiseEvent(Object event) {
                /* no-op */
              }
            };
      }

      if (idGenerator != null) {
        this.idGenerator = idGenerator;
      } else {
        this.idGenerator = new DefaultIdGenerator();
      }

      permissionHandlerPolicy = new PermissionHandlerPolicy(null);
      if (permissionHandlers != null) {
        for (PermissionHandler handler : permissionHandlers) {
          permissionHandlerPolicy.registerHandler(handler);
        }
      }

      IdentityConfiguration partitionCfg = null;
      IdentityConfiguration attributeCfg = null;

      for (IdentityConfiguration config : configurations) {
        for (IdentityStoreConfiguration storeConfig : config.getStoreConfiguration()) {
          if (storeConfig.supportsPartition()) {
            partitionCfg = config;
          }

          if (storeConfig.supportsAttribute()) {
            attributeCfg = config;
          }
        }
      }

      // There may be no configuration that supports partition management, in which case the
      // partitionManagementConfig
      // field will be null and partition management operations will not be supported
      this.partitionManagementConfig = partitionCfg;
      this.attributeManagementConfig = attributeCfg;

      logConfiguration(this.configurations);

      Map<IdentityConfiguration, Map<IdentityStoreConfiguration, IdentityStore<?>>>
          configuredStores =
              new HashMap<
                  IdentityConfiguration, Map<IdentityStoreConfiguration, IdentityStore<?>>>();

      for (IdentityConfiguration config : configurations) {
        Map<IdentityStoreConfiguration, IdentityStore<?>> storeMap =
            new HashMap<IdentityStoreConfiguration, IdentityStore<?>>();

        for (IdentityStoreConfiguration storeConfig : config.getStoreConfiguration()) {
          storeMap.put(storeConfig, createIdentityStore(storeConfig));
        }

        configuredStores.put(config, Collections.unmodifiableMap(storeMap));
      }

      stores = Collections.unmodifiableMap(configuredStores);
    } catch (Exception e) {
      throw MESSAGES.partitionManagerInitializationFailed(this.getClass(), e);
    }
  }