Skip to content

Commit 7a99f14

Browse files
committed
feat: Add public Credential sealed type and SchemeValidator interface
1 parent 017ea20 commit 7a99f14

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.retailsvc.http;
2+
3+
/**
4+
* A credential extracted from a request by the library, handed to a {@link SchemeValidator} for
5+
* verification. Sealed so consumers can pattern-match across scheme types.
6+
*/
7+
public sealed interface Credential
8+
permits Credential.ApiKeyCredential, Credential.BearerCredential, Credential.BasicCredential {
9+
10+
record ApiKeyCredential(String value) implements Credential {}
11+
12+
record BearerCredential(String token) implements Credential {}
13+
14+
record BasicCredential(String username, String password) implements Credential {}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.retailsvc.http;
2+
3+
import java.util.Optional;
4+
5+
/**
6+
* Consumer-provided callback that validates an extracted {@link Credential}. Return a non-empty
7+
* {@link Optional} carrying the principal on success, or {@link Optional#empty()} to deny.
8+
*/
9+
@FunctionalInterface
10+
public interface SchemeValidator {
11+
Optional<Object> validate(Request request, Credential credential);
12+
}

0 commit comments

Comments
 (0)