source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/Configuration.java @ 5549

Last change on this file since 5549 was 5549, checked in by olhsha@mpi.nl, 10 years ago

Added group service. Tested via the tomcat on loclahots (test URI and postman), old unit tests are adjusted and work well. Todo: retest on localhost tomcat, look at run-time exceptions, add new unit tests, adjust front-end

File size: 4.2 KB
Line 
1package clarin.cmdi.componentregistry;
2
3import clarin.cmdi.componentregistry.components.CMDComponentSpec;
4import java.security.Principal;
5import java.util.ArrayList;
6import java.util.Arrays;
7import java.util.Collection;
8import java.util.HashMap;
9import java.util.HashSet;
10import java.util.List;
11import java.util.Map;
12import org.slf4j.Logger;
13import org.slf4j.LoggerFactory;
14
15/**
16 *
17 * @author Twan Goosen <twan.goosen@mpi.nl>
18 */
19public 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 boolean isAdminUser(String name) {
77        if (name != null) {
78            return name.trim().length() > 0 // user name must be set (in case an empty entry is in admin users list)
79                    && adminUsers.contains(name);
80        }
81        return false;
82    }
83   
84    public void setAdminUsers(Collection<String> adminUsers) {
85        LOG.debug("Setting adminUsers to {}", Arrays.toString(adminUsers.toArray()));
86        this.adminUsers = adminUsers;
87    }
88   
89   
90    /**
91     *
92     * @param adminUsers Whitespace-separated list of admin users
93     */
94    public void setAdminUsersList(String adminUsersList) {
95        String[] adminUsersArray = adminUsersList.trim().split("\\s+");
96        if (LOG.isDebugEnabled()) {
97            LOG.info("Setting adminUsersList to {}", Arrays.toString(adminUsersArray));
98        }
99        setAdminUsers(Arrays.asList(adminUsersArray));
100    }
101
102    public void setComponent2SchemaXsl(String component2SchemaXsl) {
103        LOG.info("Setting component2SchemaXsl to {}", component2SchemaXsl);
104        this.component2SchemaXsl = component2SchemaXsl;
105    }
106
107    public void setComponentSpecSchemaLocation(String componentSpecSchemaLocation) {
108        LOG.info("Setting componentSpecSchemaLocation to {}", componentSpecSchemaLocation);
109        schemaLocations.put(CMDComponentSpec.class.getName(), componentSpecSchemaLocation);
110    }
111
112    public void setDisplayNameShibbolethKeys(List<String> displayNameShibbolethKeys) {
113        LOG.info("Setting displayNameShibbolethKeys to {}", displayNameShibbolethKeys);
114        this.displayNameShibbolethKeys = displayNameShibbolethKeys;
115    }
116
117    public void setGeneralComponentSchema(String generalComponentSchema) {
118        LOG.info("Setting generalComponentSchema to {}", generalComponentSchema);
119        this.generalComponentSchema = generalComponentSchema;
120    }
121
122    public void setIsocatRestUrl(String isocatRestUrl) {
123        LOG.info("Setting isocatRestUrl to {}", isocatRestUrl);
124        this.isocatRestUrl = isocatRestUrl;
125    }
126
127    public String[] getAdminUsersArray() {
128        return adminUsers.toArray(new String[0]);
129    }
130}
Note: See TracBrowser for help on using the repository browser.