All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vlingo.xoom.auth.infra.persistence.InMemoryPermissionRepository Maven / Gradle / Ivy

Go to download

The reactive, scalable, and resilient authentication and authorization service for VLINGO XOOM Platform components, and also suitable for hosted platform services and applications.

There is a newer version: 1.11.1
Show newest version
// Copyright © 2012-2021 VLINGO LABS. All rights reserved.
//
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL
// was not distributed with this file, You can obtain
// one at https://mozilla.org/MPL/2.0/.

package io.vlingo.xoom.auth.infra.persistence;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import io.vlingo.xoom.auth.model.Permission;
import io.vlingo.xoom.auth.model.PermissionRepository;
import io.vlingo.xoom.auth.model.TenantId;

public class InMemoryPermissionRepository extends BaseRepository implements PermissionRepository {
  private final Map permissions = new HashMap<>();

  @Override
  public Permission permissionOf(final TenantId tenantId, final String permissionName) {
    final Permission permission = permissions.get(keyFor(tenantId, permissionName));
    return permission == null ? Permission.NonExisting : permission;
  }

  @Override
  public Collection permissionsOf(TenantId tenantId) {
    final Set tenantPermissions = new HashSet<>();
    final String tenantKey = keyFor(tenantId);
    for (final String key : permissions.keySet()) {
      if (key.startsWith(tenantKey)) {
        tenantPermissions.add(permissions.get(key));
      }
    }
    return tenantPermissions;
  }

  @Override
  public void save(final Permission permission) {
    permissions.put(keyFor(permission.tenantId(), permission.name()), permission);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy