Skip to content

Commit

Permalink
Added new child module 'services-security'
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v committed Mar 24, 2021
1 parent dff3768 commit afc3dd1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.scalecube.services.security;

import io.scalecube.services.auth.Authenticator;
import java.util.Map;
import org.jctools.maps.NonBlockingHashMapLong;
import reactor.core.publisher.Mono;

/**
* Implementation of {@link Authenticator} which works on top of existing {@code authenticator}.
* Internally maintains a map of service claims where key is some id (of type {@code long}) and
* value is {@link ServiceClaims} object.
*
* @see #saveAuthData(long, ServiceClaims)
* @see #getAuthData(long)
* @see #removeAuthData(long)
*/
public final class CompositeAuthenticator implements Authenticator<ServiceClaims> {

private final Authenticator<ServiceClaims> authenticator;

private final Map<Long, ServiceClaims> registry = new NonBlockingHashMapLong<>();

public CompositeAuthenticator(Authenticator<ServiceClaims> authenticator) {
this.authenticator = authenticator;
}

@Override
public Mono<ServiceClaims> apply(Map<String, String> credentials) {
return authenticator.apply(credentials);
}

public void saveAuthData(long id, ServiceClaims serviceClaims) {
registry.put(id, serviceClaims);
}

public ServiceClaims getAuthData(long id) {
return registry.get(id);
}

public void removeAuthData(long id) {
registry.remove(id);
}

public boolean containsAuthData(long id) {
return registry.containsKey(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
import reactor.util.retry.Retry;

/**
* Generic {@link Authenticator} implementation based on abstract {@link JwtTokenResolver}. Using
* token resolver this authenticator turns extracted and verified token claims into the {@link
* Implementation of {@link Authenticator} backed up by provided {@link JwtTokenResolver}. Using
* token resolver this authenticator turns extracted (and verified) token claims into the {@link
* ServiceClaims} object.
*
* @see #apply(Map)
* @see ServiceTokens
* @see ServiceClaims
*/
public final class ServiceTokenAuthenticator implements Authenticator<ServiceClaims> {

Expand Down

0 comments on commit afc3dd1

Please sign in to comment.