forked from OpenConext/OpenConext-pdp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PdpApplication.java
78 lines (65 loc) · 3.01 KB
/
PdpApplication.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package pdp;
import org.apache.openaz.xacml.util.FactoryException;
import org.apache.openaz.xacml.util.XACMLProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.audit.AuditAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.trace.http.HttpTraceAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import pdp.policies.PolicyLoader;
import pdp.repositories.PdpPolicyRepository;
import pdp.sab.SabClient;
import pdp.stats.StatsContextHolder;
import pdp.teams.VootClient;
import pdp.web.SessionAliveInterceptor;
import pdp.xacml.PDPEngineHolder;
import java.io.IOException;
@SpringBootApplication(exclude = {
FreeMarkerAutoConfiguration.class,
AuditAutoConfiguration.class,
SecurityAutoConfiguration.class,
HttpTraceAutoConfiguration.class,
MetricsAutoConfiguration.class})
public class PdpApplication {
@Autowired
private ResourceLoader resourceLoader;
public static void main(String[] args) {
SpringApplication.run(PdpApplication.class, args);
}
@Bean
public StatsContextHolder statsContextHolder() {
return new StatsContextHolder("decide/policy");
}
@Bean
public PDPEngineHolder pdpEngine(
@Value("${xacml.properties.path}") final String xacmlPropertiesFileLocation,
final PdpPolicyRepository pdpPolicyRepository,
final VootClient vootClient,
final SabClient sabClient,
final PolicyLoader policyLoader
) throws IOException, FactoryException {
Resource resource = resourceLoader.getResource(xacmlPropertiesFileLocation);
String absolutePath = resource.getFile().getAbsolutePath();
//This will be picked up by the XACML bootstrapping when creating a new PDPEngine
System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, absolutePath);
policyLoader.loadPolicies();
return new PDPEngineHolder(pdpPolicyRepository, vootClient, sabClient);
}
@Configuration
public static class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new SessionAliveInterceptor());
}
}
}