aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com/ufund/api/ufundapi/model/UserAuth.java
blob: 78dcceccf9c6bf568b940db38404a6be454fe97a (plain) (blame)
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.ufund.api.ufundapi.model;

import java.time.LocalDateTime;
import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonProperty;

public class UserAuth {
    @JsonProperty("key") String key;
    @JsonProperty("username") String username;
    @JsonProperty("expiration") LocalDateTime expiration;

    public UserAuth(@JsonProperty("key") String key, @JsonProperty("username") String username, @JsonProperty("expiration") LocalDateTime expiration) {
        this.key = key;
        this.username = username;
        this.expiration = expiration;
    }

    /**
     * Generate a new user authentication profile
     * 
     * @param username the username the key will belong to
     * @return The new user authentication profile
     */
    public static UserAuth generate(String username) {
        return new UserAuth(
                UUID.randomUUID().toString(),
                username,
                LocalDateTime.now().plusDays(30)
        );
    }

    public String getKey() {
        return key;
    }

    public String getUsername() {
        return username;
    }

    public LocalDateTime getExpiration() {
        return expiration;
    }
}