-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAuthenticationService.java
44 lines (34 loc) · 1.18 KB
/
AuthenticationService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.virgilsecurity.demo.server.service;
import com.virgilsecurity.sdk.crypto.exceptions.CryptoException;
import com.virgilsecurity.sdk.jwt.Jwt;
import com.virgilsecurity.sdk.jwt.JwtGenerator;
import com.virgilsecurity.sdk.utils.StringUtils;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AuthenticationService {
private Map<String, String> authTokens;
@Autowired
JwtGenerator jwtGenerator;
public AuthenticationService() {
this.authTokens = new ConcurrentHashMap<>();
}
public String login(String identity) {
String authToken = String.format("%s-%s", identity, UUID.randomUUID().toString());
this.authTokens.put(authToken, identity);
return authToken;
}
public String getIdentity(String authToken) {
if (StringUtils.isBlank(authToken)) {
return null;
}
String token = authToken.split(" ")[1];
return this.authTokens.get(token);
}
public Jwt generateVirgilToken(String identity) throws CryptoException {
return jwtGenerator.generateToken(identity);
}
}