-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new child module 'services-security'
- Loading branch information
Showing
2 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
services-security/src/main/java/io/scalecube/services/security/CompositeAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters