add basic auth support
This commit is contained in:
parent
ff58a5664b
commit
2bb7eba346
3 changed files with 42 additions and 3 deletions
23
src/main/java/sh/libre/scim/core/BasicAuthentication.java
Normal file
23
src/main/java/sh/libre/scim/core/BasicAuthentication.java
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package sh.libre.scim.core;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.ClientRequestContext;
|
||||||
|
import javax.ws.rs.client.ClientRequestFilter;
|
||||||
|
|
||||||
|
public class BasicAuthentication implements ClientRequestFilter {
|
||||||
|
private final String user;
|
||||||
|
private final String password;
|
||||||
|
|
||||||
|
BasicAuthentication(String user, String password) {
|
||||||
|
this.user = user;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void filter(ClientRequestContext requestContext) throws IOException {
|
||||||
|
var token = Base64.getEncoder().encodeToString((user + ":" + password).getBytes());
|
||||||
|
requestContext.getHeaders().add("Authorization", "Basic " + token);
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,8 +36,14 @@ public class ScimClient {
|
||||||
|
|
||||||
this.session = session;
|
this.session = session;
|
||||||
var target = client.target(model.get("endpoint"));
|
var target = client.target(model.get("endpoint"));
|
||||||
if (model.get("auth-mode").equals("BEARER")) {
|
switch (model.get("auth-mode")) {
|
||||||
|
case "BEARER":
|
||||||
target = target.register(new BearerAuthentication(model.get("auth-bearer-token")));
|
target = target.register(new BearerAuthentication(model.get("auth-bearer-token")));
|
||||||
|
break;
|
||||||
|
case "BASIC_AUTH":
|
||||||
|
target = target.register(new BasicAuthentication(
|
||||||
|
model.get("auth-basic-auth-user"),
|
||||||
|
model.get("auth-basic-auth-pass")));
|
||||||
}
|
}
|
||||||
|
|
||||||
scimService = new ScimService(target);
|
scimService = new ScimService(target);
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class ScimStorageProviderFactory
|
||||||
.type(ProviderConfigProperty.LIST_TYPE)
|
.type(ProviderConfigProperty.LIST_TYPE)
|
||||||
.label("Auth mode")
|
.label("Auth mode")
|
||||||
.helpText("Select the authorization mode")
|
.helpText("Select the authorization mode")
|
||||||
.options("NONE", "BEARER")
|
.options("NONE", "BEARER", "BASIC_AUTH")
|
||||||
.defaultValue("NONE")
|
.defaultValue("NONE")
|
||||||
.add()
|
.add()
|
||||||
.property()
|
.property()
|
||||||
|
@ -62,6 +62,16 @@ public class ScimStorageProviderFactory
|
||||||
.helpText("Add a bearer token in the authorization header")
|
.helpText("Add a bearer token in the authorization header")
|
||||||
.add()
|
.add()
|
||||||
.property()
|
.property()
|
||||||
|
.name("auth-basic-auth-user")
|
||||||
|
.type(ProviderConfigProperty.STRING_TYPE)
|
||||||
|
.label("BasicAuth user")
|
||||||
|
.add()
|
||||||
|
.property()
|
||||||
|
.name("auth-basic-auth-pass")
|
||||||
|
.type(ProviderConfigProperty.PASSWORD)
|
||||||
|
.label("BasicAuth password")
|
||||||
|
.add()
|
||||||
|
.property()
|
||||||
.name("sync-import")
|
.name("sync-import")
|
||||||
.type(ProviderConfigProperty.BOOLEAN_TYPE)
|
.type(ProviderConfigProperty.BOOLEAN_TYPE)
|
||||||
.label("Enable import during sync")
|
.label("Enable import during sync")
|
||||||
|
|
Loading…
Reference in a new issue