io.vlingo.xoom.auth.infra.persistence.InMemoryRoleRepository Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xoom-auth Show documentation
Show all versions of xoom-auth Show documentation
The reactive, scalable, and resilient authentication and authorization service for VLINGO XOOM Platform
components, and also suitable for hosted platform services and applications.
// 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.Role;
import io.vlingo.xoom.auth.model.RoleRepository;
import io.vlingo.xoom.auth.model.TenantId;
public class InMemoryRoleRepository extends BaseRepository implements RoleRepository {
private final Map roles = new HashMap<>();
@Override
public Role roleOf(final TenantId tenantId, final String roleName) {
final Role role = roles.get(keyFor(tenantId, roleName));
return role == null ? Role.NonExisting : role;
}
@Override
public Collection rolesOf(TenantId tenantId) {
final Set tenantRoles = new HashSet<>();
final String tenantKey = keyFor(tenantId);
for (final String key : roles.keySet()) {
if (key.startsWith(tenantKey)) {
tenantRoles.add(roles.get(key));
}
}
return tenantRoles;
}
@Override
public void save(final Role role) {
roles.put(keyFor(role.tenantId(), role.name()), role);
}
}