forked from SAP/cloud-security-services-integration-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.java
More file actions
162 lines (143 loc) · 4.53 KB
/
Token.java
File metadata and controls
162 lines (143 loc) · 4.53 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.sap.cloud.security.token;
import com.sap.cloud.security.config.Service;
import com.sap.cloud.security.json.JsonObject;
import com.sap.cloud.security.json.JsonParsingException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.security.Principal;
import java.time.Instant;
import java.util.List;
import java.util.Set;
/**
* Represents a JSON Web Token (JWT).
*/
public interface Token {
/**
* Returns the header parameter value as string for the given header parameter
* name.
*
* @param headerName
* the name of the header parameter as defined here
* {@link TokenHeader}
* @return the value for the given header name or null, if the header is not
* provided.
*/
@Nullable
String getHeaderParameterAsString(@Nonnull String headerName);
/**
* Checks whether the token contains a given header parameter.
*
* @param headerName
* the name of the header parameter as defined here
* {@link TokenHeader}
* @return true when the given header name is found.
*/
boolean hasHeaderParameter(@Nonnull String headerName);
/**
* Checks whether the token contains a given claim.
*
* @param claimName
* the name of the claim as defined here {@link TokenClaims}.
* @return true when the claim with the given name is found.
*/
boolean hasClaim(@Nonnull String claimName);
/**
* Extracts the value as string for the given claim. If the claim is not found,
* it will return null. If the given claim is not a string, it will throw a
* {@link JsonParsingException}.
*
* @param claimName
* the name of the claim as defined here {@link TokenClaims}.
* @return the corresponding string value of the given claim or null.
*
* @throws JsonParsingException
* if the json object identified by the given claim is not a string.
*/
@Nullable
String getClaimAsString(@Nonnull String claimName);
/**
* Extracts the value as a list of strings for the given claim. If the claim is
* not found, it will return null. If the given claim is not a list of strings,
* it will throw a {@link JsonParsingException}.
*
* @param claimName
* the name of the claim as defined here {@link TokenClaims}.
* @return the data of the given claim as a list of strings or an empty list.
*/
List<String> getClaimAsStringList(@Nonnull String claimName);
/**
* Extracts the value of the given as a JsonObject. Use this to extract nested
* objects. If the claim is not found, it will return null. If the vale for the
* given claim is not an object, it will throw a {@link JsonParsingException}.
*
* @param claimName
* the name of the claim for which the object should be extracted.
* @return the corresponding {@link JsonObject} for the given claim.
*/
@Nullable
JsonObject getClaimAsJsonObject(@Nonnull String claimName);
/**
* Returns the moment in time when the token will be expired.
*
* @return the expiration point in time if present.
*/
@Nullable
Instant getExpiration();
/**
* Returns true if the token is expired.
*
* @return true if the token is expired.
*/
boolean isExpired();
/**
* Returns the moment in time before which the token must not be accepted.
*
* @return the not before point in time if present.
*/
@Nullable
Instant getNotBefore();
/**
* Get the encoded jwt token, e.g. for token forwarding to another app.
*
* <p>
* Never expose this token via log or via HTTP.
*
* @return the encoded token.
*/
String getTokenValue();
/**
* Returns a principal, which can be used to represent any entity, such as an
* individual, a corporation, and a login id.
*
* @return the principal or null if not yet implemented.
*/
Principal getPrincipal();
/**
* Returns the identity service, the token is issued by.
*
* @return the service.
*/
Service getService();
/**
* Returns the (empty) list of audiences the token is issued for. <br>
*
* @return the audiences.
**/
Set<String> getAudiences();
/**
* Returns the Zone identifier, which can be used as tenant discriminator
* (tenant guid).
*
* @return the unique Zone identifier.
*/
String getZoneId();
/**
* Returns the OAuth2 client identifier of the authentication token if present.
* Following OpenID Connect 1.0 standard specifications, client identifier is
* obtained from "azp" claim if present or when "azp" is not present from "aud"
* claim, but only in case there is one audience.
*
* @return the OAuth client ID.
*/
String getClientId();
}