-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2205 from bakdata/feature/api-keys
api keys reopend
- Loading branch information
Showing
112 changed files
with
2,165 additions
and
836 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
backend/src/main/java/com/bakdata/conquery/apiv1/auth/ApiTokenDataRepresentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.bakdata.conquery.apiv1.auth; | ||
|
||
import com.bakdata.conquery.io.storage.MetaStorage; | ||
import com.bakdata.conquery.models.auth.apitoken.ApiTokenData; | ||
import com.bakdata.conquery.models.auth.apitoken.ApiTokenRealm; | ||
import com.bakdata.conquery.models.auth.apitoken.Scopes; | ||
import com.bakdata.conquery.models.auth.entities.User; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import io.dropwizard.validation.ValidationMethod; | ||
import lombok.*; | ||
import lombok.experimental.Accessors; | ||
|
||
import javax.validation.constraints.NotEmpty; | ||
import javax.validation.constraints.NotNull; | ||
import java.time.LocalDate; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Container class for how tokens are represented through the API. | ||
* This is necessary so that the actual token and it's hash are not leaked (with except for the token on creation). | ||
* @implNote We don't use fluent accessors here, because that does not work well with Jackson | ||
*/ | ||
@Data | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public abstract class ApiTokenDataRepresentation { | ||
|
||
@NotNull | ||
protected String name; | ||
@NotNull | ||
protected LocalDate expirationDate; | ||
@NotEmpty | ||
protected Set<Scopes> scopes; | ||
|
||
@ValidationMethod | ||
@JsonIgnore | ||
boolean isNotExpired() { | ||
final LocalDate now = LocalDate.now(); | ||
return expirationDate.isAfter(now) || expirationDate.isEqual(now); | ||
} | ||
|
||
/** | ||
* Container that is send with an incoming request to create a token. | ||
*/ | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public static class Request extends ApiTokenDataRepresentation { | ||
// Intentionally left blank | ||
} | ||
|
||
/** | ||
* Container that is send with an outgoing response to give information about created tokens. | ||
*/ | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public static class Response extends ApiTokenDataRepresentation { | ||
|
||
private UUID id; | ||
private LocalDate lastUsed; | ||
private LocalDate creationDate; | ||
private boolean isExpired; | ||
|
||
} | ||
} |
Oops, something went wrong.