blob: f8eab927643bc69796f4cf476f3f4069c82c1f86 (
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
45
46
47
48
49
50
51
52
53
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.http.filter.security.athenz;
import com.yahoo.jdisc.http.filter.DiscFilterRequest;
import com.yahoo.vespa.athenz.api.AthenzResourceName;
import java.util.Optional;
/**
* Maps a request to an {@link AthenzResourceName} and an action.
*
* @author bjorncs
*/
public interface RequestResourceMapper {
/**
* @return A resource name + action to use for access control, empty if no access control should be performed.
*/
Optional<ResourceNameAndAction> getResourceNameAndAction(String method, String uriPath, String uriQuery);
/**
* @return A resource name + action to use for access control, empty if no access control should be performed.
*/
default Optional<ResourceNameAndAction> getResourceNameAndAction(DiscFilterRequest request) {
return getResourceNameAndAction(request.getMethod(), request.getRequestURI(), request.getQueryString());
}
class ResourceNameAndAction {
private final AthenzResourceName resourceName;
private final String action;
public ResourceNameAndAction(AthenzResourceName resourceName, String action) {
this.resourceName = resourceName;
this.action = action;
}
public AthenzResourceName resourceName() {
return resourceName;
}
public String action() {
return action;
}
@Override
public String toString() {
return "ResourceNameAndAction{" +
"resourceName=" + resourceName +
", action='" + action + '\'' +
'}';
}
}
}
|