@Override
  public Set<CredentialStore<?>> getStoresForCredentialStorage(
      final IdentityContext context, Class<? extends CredentialStorage> storageClass) {
    Map<IdentityStoreConfiguration, IdentityStore<?>> storesConfig =
        this.stores.get(getConfigurationForPartition(context.getPartition()));

    Set<CredentialStore<?>> credentialStores = new HashSet<CredentialStore<?>>();

    if (storesConfig != null) {
      for (IdentityStore identityStore : storesConfig.values()) {
        if (CredentialStore.class.isInstance(identityStore)
            && identityStore.getConfig().supportsCredential()) {
          CredentialStore<?> credentialStore = (CredentialStore<?>) identityStore;

          for (Class<? extends CredentialHandler> credentialHandler :
              credentialStore.getConfig().getCredentialHandlers()) {
            SupportsCredentials supportedCredentials =
                credentialHandler.getAnnotation(SupportsCredentials.class);

            if (supportedCredentials != null) {
              if (supportedCredentials.credentialStorage().equals(storageClass)) {
                credentialStores.add(credentialStore);
              }
            }
          }
        }
      }
    }

    return credentialStores;
  }
  @Override
  public <T extends CredentialStore<?>> T getStoreForCredentialOperation(
      IdentityContext context, Class<?> credentialClass) {
    T store = null;

    IdentityConfiguration identityConfiguration = null;

    if (this.partitionManagementConfig != null) {
      identityConfiguration = getConfigurationForPartition(context.getPartition());
    } else {
      for (IdentityConfiguration configuration : this.configurations) {
        for (IdentityStoreConfiguration storeConfig : configuration.getStoreConfiguration()) {
          if (storeConfig.supportsCredential()) {
            identityConfiguration = configuration;
          }
        }
      }
    }

    if (identityConfiguration != null && identityConfiguration.supportsCredential()) {
      for (IdentityStoreConfiguration storeConfig : identityConfiguration.getStoreConfiguration()) {
        if (storeConfig.supportsCredential()) {
          for (@SuppressWarnings("rawtypes")
          Class<? extends CredentialHandler> handlerClass : storeConfig.getCredentialHandlers()) {
            if (handlerClass.isAnnotationPresent(SupportsCredentials.class)) {
              for (Class<?> cls :
                  handlerClass.getAnnotation(SupportsCredentials.class).credentialClass()) {
                if (cls.isAssignableFrom(credentialClass)) {
                  IdentityStore<?> identityStore = null;
                  try {
                    store =
                        getIdentityStoreAndInitializeContext(
                            context, identityConfiguration, storeConfig);
                  } catch (ClassCastException cce) {
                    throw MESSAGES.storeUnexpectedType(
                        identityStore.getClass(), CredentialStore.class);
                  }

                  // if we found a specific handler for the credential, immediately return.
                  if (cls.equals(credentialClass)) {
                    return store;
                  }
                }
              }
            }
          }
        }
      }
    }

    if (store == null) {
      throw MESSAGES.credentialNoStoreForCredentials(credentialClass);
    }

    return store;
  }
  @Override
  public boolean validatePassword(User user, String password) {
    if (this.passwordEncoder != null) {
      password = this.passwordEncoder.encodePassword(user, password);
    }

    return store.validatePassword(user, password);
  }
 @Override
 public Group createGroup(String id, Group parent) {
   ensureStoreExists();
   return store.createGroup(id, parent);
 }
 @Override
 public Group createGroup(String id) {
   return store.createGroup(id, null);
 }
 @Override
 public void removeGroup(Group group) {
   ensureStoreExists();
   store.removeGroup(group);
 }
 @Override
 public void removeUser(String name) {
   ensureStoreExists();
   store.removeUser(getUser(name));
 }
 @Override
 public User getUser(String name) {
   ensureStoreExists();
   return store.getUser(name);
 }
 @Override
 public User createUser(User user) {
   ensureStoreExists();
   return store.createUser(user);
 }
 @Override
 public void removeUser(User user) {
   ensureStoreExists();
   store.removeUser(user);
 }
 @Override
 public boolean updateCertificate(User user, X509Certificate certificate) {
   return store.updateCertificate(user, certificate);
 }
 @Override
 public User createUser(String name) {
   ensureStoreExists();
   return store.createUser(name);
 }
 @Override
 public Role getRole(String name) {
   ensureStoreExists();
   return store.getRole(name);
 }
 @Override
 public Group createGroup(String id, String parent) {
   ensureStoreExists();
   Group parentGroup = store.getGroup(parent);
   return store.createGroup(id, parentGroup);
 }
 @Override
 public void removeRole(String name) {
   ensureStoreExists();
   store.removeRole(getRole(name));
 }
 @Override
 public void removeRole(Role role) {
   ensureStoreExists();
   store.removeRole(role);
 }
 @Override
 public Role createRole(String name) {
   ensureStoreExists();
   return store.createRole(name);
 }
 @Override
 public Group getGroup(String groupId) {
   ensureStoreExists();
   return store.getGroup(groupId);
 }
 @Override
 public void removeGroup(String groupId) {
   ensureStoreExists();
   store.removeGroup(getGroup(groupId));
 }