Gültigkeitsdauer von Tokens editierbar gemacht
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -64,6 +64,7 @@ public class Constants {
|
||||
public static final String START_TLS = "start_tls";
|
||||
public static final String TOKEN = "token";
|
||||
public static final String TOKEN_TYPE = "token_type";
|
||||
public static final String TOKEN_VALIDITY = "token_validity";
|
||||
public static final String TRUST = "trust";
|
||||
public static final String UNAUTHORIZED_CLIENT = "unauthorized_client";
|
||||
public static final String USER = "user";
|
||||
|
||||
@@ -5,6 +5,7 @@ package de.srsoftware.oidc.api.data;
|
||||
import static de.srsoftware.oidc.api.Constants.*;
|
||||
import static de.srsoftware.utils.Optionals.nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
public final class Client {
|
||||
@@ -14,15 +15,36 @@ public final class Client {
|
||||
private final String name;
|
||||
private final String secret;
|
||||
private final Set<String> redirectUris;
|
||||
private Duration tokenValidity;
|
||||
|
||||
public Client(String id, String name, String secret, Set<String> redirectUris) {
|
||||
this.id = id;
|
||||
landingPage = null;
|
||||
this.name = name;
|
||||
this.secret = secret;
|
||||
this.redirectUris = redirectUris;
|
||||
this.id = id;
|
||||
landingPage = null;
|
||||
this.name = name;
|
||||
this.secret = secret;
|
||||
this.redirectUris = redirectUris;
|
||||
this.tokenValidity = Duration.ofMinutes(10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) return true;
|
||||
if (obj == null || obj.getClass() != this.getClass()) return false;
|
||||
var that = (Client)obj;
|
||||
return Objects.equals(this.id, that.id) //
|
||||
&& Objects.equals(this.name, that.name) //
|
||||
&& Objects.equals(this.secret, that.secret) //
|
||||
&& Objects.equals(this.redirectUris, that.redirectUris) //
|
||||
&& Objects.equals(landingPage, that.landingPage) //
|
||||
&& Objects.equals(tokenValidity, that.tokenValidity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name, secret, redirectUris);
|
||||
}
|
||||
|
||||
|
||||
public String id() {
|
||||
return id;
|
||||
}
|
||||
@@ -53,6 +75,7 @@ public final class Client {
|
||||
map.put(NAME, name);
|
||||
nullable(redirectUris).ifPresent(uris -> map.put(REDIRECT_URIS, uris));
|
||||
nullable(landingPage).ifPresent(lp -> map.put(LANDING_PAGE, lp));
|
||||
nullable(tokenValidity).ifPresent(tv -> map.put(TOKEN_VALIDITY, tv.toMinutes()));
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -65,17 +88,14 @@ public final class Client {
|
||||
return redirectUris;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) return true;
|
||||
if (obj == null || obj.getClass() != this.getClass()) return false;
|
||||
var that = (Client)obj;
|
||||
return Objects.equals(this.id, that.id) && Objects.equals(this.name, that.name) && Objects.equals(this.secret, that.secret) && Objects.equals(this.redirectUris, that.redirectUris);
|
||||
|
||||
public Duration tokenValidity() {
|
||||
return tokenValidity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name, secret, redirectUris);
|
||||
public Client tokenValidity(Duration newValue) {
|
||||
this.tokenValidity = newValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import de.srsoftware.oidc.api.data.Client;
|
||||
import java.time.Duration;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -23,7 +24,7 @@ public abstract class ClientServiceTest {
|
||||
var clientId = uuid();
|
||||
var clientSecret = uuid();
|
||||
var landingPage = uuid();
|
||||
var client = new Client(clientId, NAME, clientSecret, Set.of(URI)).landingPage(landingPage);
|
||||
var client = new Client(clientId, NAME, clientSecret, Set.of(URI));
|
||||
var list = cs.save(client).listClients();
|
||||
assertEquals(1, list.size());
|
||||
assertTrue(list.contains(client));
|
||||
@@ -37,7 +38,7 @@ public abstract class ClientServiceTest {
|
||||
var clientId = uuid();
|
||||
var clientSecret = uuid();
|
||||
var landingPage = uuid();
|
||||
var client = new Client(clientId, NAME, clientSecret, Set.of(URI)).landingPage(landingPage);
|
||||
var client = new Client(clientId, NAME, clientSecret, Set.of(URI)).landingPage(landingPage).tokenValidity(Duration.ofMinutes(23));
|
||||
var optClient = cs.save(client).getClient(clientId);
|
||||
assertTrue(optClient.isPresent());
|
||||
assertEquals(client, optClient.get());
|
||||
|
||||
Reference in New Issue
Block a user