26 lines
834 B
Java
26 lines
834 B
Java
|
package org.gcube.smartgears.health;
|
||
|
|
||
|
import java.util.Set;
|
||
|
|
||
|
import org.gcube.smartgears.health.response.HealthCheckResponse;
|
||
|
import org.gcube.smartgears.provider.ProviderFactory;
|
||
|
|
||
|
@ReadinessChecker
|
||
|
public class KeyCloakHealthCheck implements HealthCheck{
|
||
|
|
||
|
private static final String CHECK_NAME = "authorizationCheck" ;
|
||
|
|
||
|
@Override
|
||
|
public HealthCheckResponse check() {
|
||
|
try {
|
||
|
Set<String> contexts = ProviderFactory.provider().containerContext().authorizationProvider().getContexts();
|
||
|
if (contexts.isEmpty())
|
||
|
return HealthCheckResponse.builder(CHECK_NAME).down().withMessage("no contexts are defined for this server").build();
|
||
|
return HealthCheckResponse.builder(CHECK_NAME).up().build();
|
||
|
}catch (Exception e) {
|
||
|
return HealthCheckResponse.builder(CHECK_NAME).down().withMessage(e.getMessage()).build();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|