All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloud.security.ams.spring.autoconfig.PolicyDecisionPointAutoConfiguration Maven / Gradle / Ivy

Go to download

Client Library for integrating Spring applications with SAP Authorization Management Service (AMS)

The newest version!
/************************************************************************
* © 2019-2023 SAP SE or an SAP affiliate company. All rights reserved. *
************************************************************************/
package com.sap.cloud.security.ams.spring.autoconfig;

import com.sap.cloud.security.ams.dcl.client.pdp.PolicyDecisionPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

import static com.sap.cloud.security.ams.dcl.client.pdp.PolicyDecisionPoint.Parameters.FAIL_ON_STARTUP_HEALTH_CHECK;
import static com.sap.cloud.security.ams.dcl.client.pdp.PolicyDecisionPoint.Parameters.STARTUP_HEALTH_CHECK_TIMEOUT;

import static com.sap.cloud.security.ams.factory.AmsPolicyDecisionPointFactory.DEFAULT;

@Configuration
@ConditionalOnProperty(name = "com.sap.cloud.security.ams.auto", havingValue = "true", matchIfMissing = true)
public class PolicyDecisionPointAutoConfiguration {
	private final Logger logger = LoggerFactory.getLogger(getClass());
	@Value("${com.sap.dcl.client.startupHealthCheckTimeout:#{null}}")
	private Long startupCheckTimeout;

	@Value("${com.sap.dcl.client.failOnStartupCheck:#{null}}")
	private Boolean failOnStartup;

	@Bean
	@ConditionalOnMissingBean(PolicyDecisionPoint.class)
	public PolicyDecisionPoint policyDecisionPoint() {
		logger.debug("auto-configures PolicyDecisionPoint.");
		return PolicyDecisionPoint.create(DEFAULT, processPdpArgs());
	}

	private Object[] processPdpArgs() {
		List args = new ArrayList<>();
		if (startupCheckTimeout != null) {
			args.add(STARTUP_HEALTH_CHECK_TIMEOUT);
			args.add(startupCheckTimeout);
		}
		if (failOnStartup != null) {
			args.add(FAIL_ON_STARTUP_HEALTH_CHECK);
			args.add(failOnStartup);
		}
		return args.toArray();
	}
}