1 | package clarin.cmdi.componentregistry; |
---|
2 | |
---|
3 | import clarin.cmdi.componentregistry.components.CMDComponentSpec; |
---|
4 | import java.security.Principal; |
---|
5 | import java.util.ArrayList; |
---|
6 | import java.util.Arrays; |
---|
7 | import java.util.Collection; |
---|
8 | import java.util.HashMap; |
---|
9 | import java.util.HashSet; |
---|
10 | import java.util.List; |
---|
11 | import java.util.Map; |
---|
12 | import org.slf4j.Logger; |
---|
13 | import org.slf4j.LoggerFactory; |
---|
14 | |
---|
15 | /** |
---|
16 | * |
---|
17 | * @author Twan Goosen <twan.goosen@mpi.nl> |
---|
18 | */ |
---|
19 | public class Configuration { |
---|
20 | |
---|
21 | private static Logger LOG = LoggerFactory.getLogger(Configuration.class); |
---|
22 | //NOTE: Default values, can be overwritten in applicationContext.xml |
---|
23 | private String generalComponentSchema = "https://infra.clarin.eu/cmd/general-component-schema.xsd"; |
---|
24 | private String component2SchemaXsl = "https://infra.clarin.eu/cmd/xslt/comp2schema-v2/comp2schema.xsl";//"http://www.clarin.eu/cmd/comp2schema.xsl"; |
---|
25 | private String isocatRestUrl = "http://www.isocat.org/rest/"; |
---|
26 | private Collection<String> adminUsers = new HashSet<String>(); |
---|
27 | private List<String> displayNameShibbolethKeys = new ArrayList<String>(); |
---|
28 | |
---|
29 | {//Default values |
---|
30 | displayNameShibbolethKeys.add("displayName"); |
---|
31 | displayNameShibbolethKeys.add("commonName"); |
---|
32 | } |
---|
33 | private Map<String, String> schemaLocations = new HashMap<String, String>(); |
---|
34 | |
---|
35 | {//Default values |
---|
36 | schemaLocations.put(CMDComponentSpec.class.getName(), |
---|
37 | "http://www.clarin.eu/cmd/ http://infra.clarin.eu/cmd/general-component-schema.xsd"); |
---|
38 | } |
---|
39 | private final static Configuration INSTANCE = new Configuration(); |
---|
40 | |
---|
41 | private Configuration() { |
---|
42 | } |
---|
43 | |
---|
44 | public static Configuration getInstance() { |
---|
45 | return INSTANCE; |
---|
46 | } |
---|
47 | |
---|
48 | public String getComponent2SchemaXsl() { |
---|
49 | return component2SchemaXsl; |
---|
50 | } |
---|
51 | |
---|
52 | public List<String> getDisplayNameShibbolethKeys() { |
---|
53 | return displayNameShibbolethKeys; |
---|
54 | } |
---|
55 | |
---|
56 | public String getGeneralComponentSchema() { |
---|
57 | return generalComponentSchema; |
---|
58 | } |
---|
59 | |
---|
60 | public String getIsocatRestUrl() { |
---|
61 | return isocatRestUrl; |
---|
62 | } |
---|
63 | |
---|
64 | public String getSchemaLocation(String key) { |
---|
65 | return schemaLocations.get(key); |
---|
66 | } |
---|
67 | |
---|
68 | public boolean isAdminUser(Principal principal) { |
---|
69 | if (principal != null) { |
---|
70 | return principal.getName().trim().length() > 0 // user name must be set (in case an empty entry is in admin users list) |
---|
71 | && adminUsers.contains(principal.getName()); |
---|
72 | } |
---|
73 | return false; |
---|
74 | } |
---|
75 | |
---|
76 | public void setAdminUsers(Collection<String> adminUsers) { |
---|
77 | LOG.debug("Setting adminUsers to {}", Arrays.toString(adminUsers.toArray())); |
---|
78 | this.adminUsers = adminUsers; |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * |
---|
83 | * @param adminUsers Whitespace-separated list of admin users |
---|
84 | */ |
---|
85 | public void setAdminUsersList(String adminUsersList) { |
---|
86 | String[] adminUsersArray = adminUsersList.trim().split("\\s+"); |
---|
87 | if (LOG.isDebugEnabled()) { |
---|
88 | LOG.info("Setting adminUsersList to {}", Arrays.toString(adminUsersArray)); |
---|
89 | } |
---|
90 | setAdminUsers(Arrays.asList(adminUsersArray)); |
---|
91 | } |
---|
92 | |
---|
93 | public void setComponent2SchemaXsl(String component2SchemaXsl) { |
---|
94 | LOG.info("Setting component2SchemaXsl to {}", component2SchemaXsl); |
---|
95 | this.component2SchemaXsl = component2SchemaXsl; |
---|
96 | } |
---|
97 | |
---|
98 | public void setComponentSpecSchemaLocation(String componentSpecSchemaLocation) { |
---|
99 | LOG.info("Setting componentSpecSchemaLocation to {}", componentSpecSchemaLocation); |
---|
100 | schemaLocations.put(CMDComponentSpec.class.getName(), componentSpecSchemaLocation); |
---|
101 | } |
---|
102 | |
---|
103 | public void setDisplayNameShibbolethKeys(List<String> displayNameShibbolethKeys) { |
---|
104 | LOG.info("Setting displayNameShibbolethKeys to {}", displayNameShibbolethKeys); |
---|
105 | this.displayNameShibbolethKeys = displayNameShibbolethKeys; |
---|
106 | } |
---|
107 | |
---|
108 | public void setGeneralComponentSchema(String generalComponentSchema) { |
---|
109 | LOG.info("Setting generalComponentSchema to {}", generalComponentSchema); |
---|
110 | this.generalComponentSchema = generalComponentSchema; |
---|
111 | } |
---|
112 | |
---|
113 | public void setIsocatRestUrl(String isocatRestUrl) { |
---|
114 | LOG.info("Setting isocatRestUrl to {}", isocatRestUrl); |
---|
115 | this.isocatRestUrl = isocatRestUrl; |
---|
116 | } |
---|
117 | |
---|
118 | public String[] getAdminUsersArray() { |
---|
119 | return adminUsers.toArray(new String[0]); |
---|
120 | } |
---|
121 | } |
---|