Skip to content

Commit

Permalink
refactor: Centralize logic to determine version number for operationa…
Browse files Browse the repository at this point in the history
…l info
  • Loading branch information
sventorben committed Jul 23, 2022
1 parent 83ffc90 commit 3c464d1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.sventorben.keycloak.authorization.client;

import de.sventorben.keycloak.authorization.client.access.AccessProvider;
import de.sventorben.keycloak.authorization.client.common.OperationalInfo;
import org.jboss.logging.Logger;
import org.keycloak.Config;
import org.keycloak.authentication.Authenticator;
Expand Down Expand Up @@ -93,10 +94,6 @@ public String getId() {

@Override
public Map<String, String> getOperationalInfo() {
String version = getClass().getPackage().getImplementationVersion();
if (version == null) {
version = "unknown";
}
return Map.of("Version", version);
return OperationalInfo.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.sventorben.keycloak.authorization.client.access.AccessProvider;
import de.sventorben.keycloak.authorization.client.access.AccessProviderFactory;
import de.sventorben.keycloak.authorization.client.common.OperationalInfo;
import org.keycloak.Config;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
Expand Down Expand Up @@ -41,11 +42,7 @@ public String getId() {

@Override
public Map<String, String> getOperationalInfo() {
String version = getClass().getPackage().getImplementationVersion();
if (version == null) {
version = "unknown";
}
return Map.of("Version", version);
return OperationalInfo.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import de.sventorben.keycloak.authorization.client.access.AccessProvider;
import de.sventorben.keycloak.authorization.client.access.AccessProviderFactory;
import de.sventorben.keycloak.authorization.client.common.OperationalInfo;
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.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -50,11 +52,9 @@ public String getId() {

@Override
public Map<String, String> getOperationalInfo() {
String version = getClass().getPackage().getImplementationVersion();
if (version == null) {
version = "unknown";
}
return Map.of("Version", version, CLIENT_ROLE_NAME, getClientRoleName());
Map<String, String> operationalInfo = new HashMap<>(OperationalInfo.get());
operationalInfo.put(CLIENT_ROLE_NAME, getClientRoleName());
return operationalInfo;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.sventorben.keycloak.authorization.client.clientpolicy.condition;

import de.sventorben.keycloak.authorization.client.common.OperationalInfo;
import org.keycloak.models.KeycloakSession;
import org.keycloak.provider.ProviderConfigProperty;
import org.keycloak.provider.ServerInfoAwareProviderFactory;
Expand Down Expand Up @@ -39,10 +40,6 @@ public String getId() {

@Override
public Map<String, String> getOperationalInfo() {
String version = getClass().getPackage().getImplementationVersion();
if (version == null) {
version = "unknown";
}
return Map.of("Version", version);
return OperationalInfo.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

import de.sventorben.keycloak.authorization.client.RestrictClientAuthConfigProperties;
import de.sventorben.keycloak.authorization.client.access.AccessProvider;
import de.sventorben.keycloak.authorization.client.common.OperationalInfo;
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.ProviderFactory;
import org.keycloak.provider.ServerInfoAwareProviderFactory;
import org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider;
import org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProviderFactory;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static de.sventorben.keycloak.authorization.client.RestrictClientAuthConfigProperties.ACCESS_PROVIDER_ID_PROPERTY;

public class AutoConfigClientPolicyExecutorFactory implements ClientPolicyExecutorProviderFactory {
public class AutoConfigClientPolicyExecutorFactory implements ClientPolicyExecutorProviderFactory, ServerInfoAwareProviderFactory {

private static final List<ProviderConfigProperty> CONFIG_PROPERTIES = ProviderConfigurationBuilder.create()
.property(ACCESS_PROVIDER_ID_PROPERTY)
Expand Down Expand Up @@ -59,4 +62,9 @@ public void close() {
public String getId() {
return AutoConfigClientPolicyExecutor.PROVIDER_ID;
}

@Override
public Map<String, String> getOperationalInfo() {
return OperationalInfo.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.sventorben.keycloak.authorization.client.common;

import java.util.Map;

public class OperationalInfo {

public static Map<String, String> get() {
String version = OperationalInfo.class.getPackage().getImplementationVersion();
if (version == null) {
version = "unknown";
}
return Map.of("Version", version);
}
}

0 comments on commit 3c464d1

Please sign in to comment.