Skip to content

Commit afc3dd1

Browse files
committed
Added new child module 'services-security'
1 parent dff3768 commit afc3dd1

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.scalecube.services.security;
2+
3+
import io.scalecube.services.auth.Authenticator;
4+
import java.util.Map;
5+
import org.jctools.maps.NonBlockingHashMapLong;
6+
import reactor.core.publisher.Mono;
7+
8+
/**
9+
* Implementation of {@link Authenticator} which works on top of existing {@code authenticator}.
10+
* Internally maintains a map of service claims where key is some id (of type {@code long}) and
11+
* value is {@link ServiceClaims} object.
12+
*
13+
* @see #saveAuthData(long, ServiceClaims)
14+
* @see #getAuthData(long)
15+
* @see #removeAuthData(long)
16+
*/
17+
public final class CompositeAuthenticator implements Authenticator<ServiceClaims> {
18+
19+
private final Authenticator<ServiceClaims> authenticator;
20+
21+
private final Map<Long, ServiceClaims> registry = new NonBlockingHashMapLong<>();
22+
23+
public CompositeAuthenticator(Authenticator<ServiceClaims> authenticator) {
24+
this.authenticator = authenticator;
25+
}
26+
27+
@Override
28+
public Mono<ServiceClaims> apply(Map<String, String> credentials) {
29+
return authenticator.apply(credentials);
30+
}
31+
32+
public void saveAuthData(long id, ServiceClaims serviceClaims) {
33+
registry.put(id, serviceClaims);
34+
}
35+
36+
public ServiceClaims getAuthData(long id) {
37+
return registry.get(id);
38+
}
39+
40+
public void removeAuthData(long id) {
41+
registry.remove(id);
42+
}
43+
44+
public boolean containsAuthData(long id) {
45+
return registry.containsKey(id);
46+
}
47+
}

services-security/src/main/java/io/scalecube/services/security/ServiceTokenAuthenticator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
import reactor.util.retry.Retry;
1111

1212
/**
13-
* Generic {@link Authenticator} implementation based on abstract {@link JwtTokenResolver}. Using
14-
* token resolver this authenticator turns extracted and verified token claims into the {@link
13+
* Implementation of {@link Authenticator} backed up by provided {@link JwtTokenResolver}. Using
14+
* token resolver this authenticator turns extracted (and verified) token claims into the {@link
1515
* ServiceClaims} object.
16+
*
17+
* @see #apply(Map)
18+
* @see ServiceTokens
19+
* @see ServiceClaims
1620
*/
1721
public final class ServiceTokenAuthenticator implements Authenticator<ServiceClaims> {
1822

0 commit comments

Comments
 (0)