forked from Apicurio/apicurio-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeaderRoleProvider.java
40 lines (31 loc) · 1.1 KB
/
HeaderRoleProvider.java
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
package io.apicurio.registry.auth;
import io.apicurio.common.apps.config.Info;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.ws.rs.core.Context;
import java.util.Objects;
@RequestScoped
public class HeaderRoleProvider implements RoleProvider {
@ConfigProperty(name = "apicurio.auth.role-source.header.name")
@Info(category = "auth", description = "Header authorization name", availableSince = "2.4.3.Final")
String roleHeader;
@Inject
AuthConfig authConfig;
@Inject
@Context
HttpServletRequest request;
@Override
public boolean isReadOnly() {
return Objects.equals(request.getHeader(roleHeader), authConfig.readOnlyRole);
}
@Override
public boolean isDeveloper() {
return Objects.equals(request.getHeader(roleHeader), authConfig.developerRole);
}
@Override
public boolean isAdmin() {
return Objects.equals(request.getHeader(roleHeader), authConfig.adminRole);
}
}