1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3
4 package com.microsoft.azure.servicebus.security;
5
6 import java.time.Instant;
7
8 /**
9 * This class encapsulates the details of a security token.
10 *
11 * @since 1.2.0
12 *
13 */
14 public class SecurityToken {
15 private SecurityTokenType tokenType;
16 private String tokenAudience;
17 private String tokenValue;
18 private Instant validFrom;
19 private Instant validUntil;
20
21 /**
22 * Creates an instance of security token.
23 * @param tokenType {@link SecurityTokenType}
24 * @param tokenAudience path of the entity for which this security token is to be presented
25 * @param tokenValue string representation of the token value
26 * @param validFrom Instant from when this token is valid
27 * @param validUntil Instant when this token expires
28 */
29 public SecurityToken(SecurityTokenType tokenType, String tokenAudience, String tokenValue, Instant validFrom, Instant validUntil) {
30 this.tokenType = tokenType;
31 this.tokenAudience = tokenAudience;
32 this.tokenValue = tokenValue;
33 this.validFrom = validFrom;
34 this.validUntil = validUntil;
35 }
36
37 /**
38 * Gets the type of this security token.
39 * @return security token type
40 */
41 public SecurityTokenType getTokenType() {
42 return tokenType;
43 }
44
45 /**
46 * Gets the path of the entity for which this token is to be presented.
47 * @return path of the entity for which this token is created
48 */
49 public String getTokenAudience() {
50 return this.tokenAudience;
51 }
52
53 /**
54 * Gets the value of this token.
55 * @return string representation of the token value
56 */
57 public String getTokenValue() {
58 return this.tokenValue;
59 }
60
61 /**
62 * Gets the start time of this token validity
63 * @return Instant from when this token is valid
64 */
65 public Instant getValidFrom() {
66 return this.validFrom;
67 }
68
69 /**
70 * Gets the end time of this token validity.
71 * @return Instant when this token expires
72 */
73 public Instant getValidUntil() {
74 return this.validUntil;
75 }
76 }