-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
PrincipalIdentifierToken.java
66 lines (55 loc) · 1.72 KB
/
PrincipalIdentifierToken.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.identity;
import org.opensearch.common.io.stream.NamedWriteable;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import java.io.IOException;
import java.util.Objects;
/**
* Requester Token for requests to/from an extension
* Each user will have different token for different extension
*
* @opensearch.internal
*/
public class PrincipalIdentifierToken implements NamedWriteable {
public static final String NAME = "principal_identifier_token";
private final String token;
/**
* Should only be instantiated via extensionTokenProcessor.generateToken(..)
* @param token string value of token
*/
protected PrincipalIdentifierToken(String token) {
this.token = token;
}
public PrincipalIdentifierToken(StreamInput in) throws IOException {
this.token = in.readString();
}
public String getToken() {
return this.token;
}
@Override
public String getWriteableName() {
return NAME;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(token);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof PrincipalIdentifierToken)) return false;
PrincipalIdentifierToken other = (PrincipalIdentifierToken) obj;
return Objects.equals(token, other.token);
}
@Override
public int hashCode() {
return Objects.hash(token);
}
}