feat: Support config metadata

This commit is contained in:
Sven-Torben Janus 2022-05-21 21:26:31 +02:00
parent c065dc86e4
commit 1dfecd0482

View file

@ -5,10 +5,15 @@ import de.sventorben.keycloak.authorization.client.access.AccessProviderFactory;
import org.keycloak.Config;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty;
import org.keycloak.provider.ProviderConfigurationBuilder;
import org.keycloak.provider.ServerInfoAwareProviderFactory;
import java.util.List;
import java.util.Map;
import static org.keycloak.provider.ProviderConfigProperty.STRING_TYPE;
public final class ClientRoleBasedAccessProviderFactory implements AccessProviderFactory, ServerInfoAwareProviderFactory {
public static final String PROVIDER_ID = "client-role";
@ -52,6 +57,19 @@ public final class ClientRoleBasedAccessProviderFactory implements AccessProvide
return Map.of("Version", version, CLIENT_ROLE_NAME, getClientRoleName());
}
@Override
public List<ProviderConfigProperty> getConfigMetadata() {
return ProviderConfigurationBuilder.create()
.property()
.name(CLIENT_ROLE_NAME)
.label("Client role name")
.defaultValue(CLIENT_ROLE_NAME_DEFAULT)
.helpText("The name of the client role used to enable the authenticator and grant access.")
.type(STRING_TYPE)
.add()
.build();
}
private String getClientRoleName() {
return config.get(CLIENT_ROLE_NAME, CLIENT_ROLE_NAME_DEFAULT);
}