| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.config; |
| 2 | |
| 3 | import java.io.IOException; |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 4 | import java.util.ArrayList; |
| 5 | import java.util.List; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 6 | import java.util.Properties; |
| 7 | import java.util.regex.Pattern; |
| 8 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 9 | /** Configuration for Kustvakt full version including properties concerning |
| 10 | * authentication and licenses. |
| 11 | * |
| 12 | * @author margaretha |
| 13 | * |
| 14 | */ |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 15 | |
| margaretha | 2afb97d | 2017-12-07 19:18:44 +0100 | [diff] [blame] | 16 | public class FullConfiguration extends KustvaktConfiguration { |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 17 | |
| 18 | private String ldapConfig; |
| 19 | |
| 20 | private String freeOnlyRegex; |
| 21 | private String publicOnlyRegex; |
| 22 | private String allOnlyRegex; |
| 23 | |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 24 | private List<String> freeRegexList; |
| 25 | private List<String> publicRegexList; |
| 26 | private List<String> allRegexList; |
| 27 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 28 | private Pattern publicLicensePattern; |
| 29 | private Pattern freeLicensePattern; |
| 30 | private Pattern allLicensePattern; |
| 31 | |
| 32 | private String authenticationScheme; |
| 33 | |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame^] | 34 | private boolean isSoftDeleteAutoGroup; |
| 35 | private boolean isSoftDeleteGroup; |
| 36 | private boolean isSoftDeleteGroupMember; |
| 37 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 38 | public FullConfiguration (Properties properties) throws IOException { |
| 39 | super(properties); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public void load (Properties properties) throws IOException { |
| 44 | |
| 45 | super.load(properties); |
| 46 | // EM: regex used for storing vc |
| 47 | setLicenseRegex(properties); |
| 48 | |
| 49 | // EM: pattern for matching availability in Krill matches |
| 50 | setLicensePatterns(properties); |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame^] | 51 | setDeleteConfiguration(properties); |
| margaretha | 2afb97d | 2017-12-07 19:18:44 +0100 | [diff] [blame] | 52 | ldapConfig = properties.getProperty("ldap.config"); |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame^] | 55 | private void setDeleteConfiguration (Properties properties) { |
| 56 | setSoftDeleteGroup(parseDeleteConfig(properties.getProperty("delete.group", ""))); |
| 57 | setSoftDeleteAutoGroup(parseDeleteConfig(properties.getProperty("delete.auto.group", ""))); |
| 58 | setSoftDeleteGroupMember(parseDeleteConfig( |
| 59 | properties.getProperty("delete.group.member", ""))); |
| 60 | } |
| 61 | |
| 62 | private boolean parseDeleteConfig (String deleteConfig) { |
| 63 | return deleteConfig.equals("soft") ? true : false; |
| 64 | } |
| 65 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 66 | private void setLicensePatterns (Properties properties) { |
| margaretha | 979a2e6 | 2017-12-12 19:47:04 +0100 | [diff] [blame] | 67 | setFreeLicensePattern(compilePattern(getFreeOnlyRegex())); |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame^] | 68 | setPublicLicensePattern(compilePattern( |
| 69 | getFreeOnlyRegex() + "|" + getPublicOnlyRegex())); |
| 70 | setAllLicensePattern(compilePattern(getFreeOnlyRegex() + "|" |
| 71 | + getPublicOnlyRegex() + "|" + getAllOnlyRegex())); |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | private void setLicenseRegex (Properties properties) { |
| margaretha | 979a2e6 | 2017-12-12 19:47:04 +0100 | [diff] [blame] | 75 | setFreeOnlyRegex(properties.getProperty("availability.regex.free", "")); |
| 76 | freeRegexList = splitAndAddToList(getFreeOnlyRegex()); |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 77 | |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame^] | 78 | setPublicOnlyRegex( |
| 79 | properties.getProperty("availability.regex.public", "")); |
| margaretha | 979a2e6 | 2017-12-12 19:47:04 +0100 | [diff] [blame] | 80 | publicRegexList = splitAndAddToList(getPublicOnlyRegex()); |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 81 | |
| margaretha | 979a2e6 | 2017-12-12 19:47:04 +0100 | [diff] [blame] | 82 | setAllOnlyRegex(properties.getProperty("availability.regex.all", "")); |
| 83 | allRegexList = splitAndAddToList(getAllOnlyRegex()); |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | private List<String> splitAndAddToList (String regex) { |
| 87 | List<String> list; |
| 88 | if (regex.contains("|")) { |
| 89 | String[] regexes = regex.split("\\|"); |
| 90 | list = new ArrayList<>(regexes.length); |
| 91 | for (String s : regexes) { |
| 92 | list.add(s.trim()); |
| 93 | } |
| 94 | } |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame^] | 95 | else { |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 96 | list = new ArrayList<>(1); |
| 97 | list.add(regex); |
| 98 | } |
| 99 | return list; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | |
| 103 | private Pattern compilePattern (String patternStr) { |
| 104 | if (!patternStr.isEmpty()) { |
| 105 | return Pattern.compile(patternStr); |
| 106 | } |
| 107 | else { |
| 108 | return null; |
| 109 | } |
| 110 | } |
| 111 | |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 112 | public String getLdapConfig () { |
| 113 | return ldapConfig; |
| 114 | } |
| 115 | |
| 116 | public Pattern getPublicLicensePattern () { |
| 117 | return publicLicensePattern; |
| 118 | } |
| 119 | |
| 120 | public void setPublicLicensePattern (Pattern publicLicensePattern) { |
| 121 | this.publicLicensePattern = publicLicensePattern; |
| 122 | } |
| 123 | |
| 124 | public Pattern getFreeLicensePattern () { |
| 125 | return freeLicensePattern; |
| 126 | } |
| 127 | |
| 128 | public void setFreeLicensePattern (Pattern freeLicensePattern) { |
| 129 | this.freeLicensePattern = freeLicensePattern; |
| 130 | } |
| 131 | |
| 132 | public Pattern getAllLicensePattern () { |
| 133 | return allLicensePattern; |
| 134 | } |
| 135 | |
| 136 | public void setAllLicensePattern (Pattern allLicensePattern) { |
| 137 | this.allLicensePattern = allLicensePattern; |
| 138 | } |
| 139 | |
| 140 | public String getAuthenticationScheme () { |
| 141 | return authenticationScheme; |
| 142 | } |
| 143 | |
| 144 | public void setAuthenticationScheme (String authenticationScheme) { |
| 145 | this.authenticationScheme = authenticationScheme; |
| 146 | } |
| 147 | |
| 148 | public List<String> getFreeRegexList () { |
| 149 | return freeRegexList; |
| 150 | } |
| 151 | |
| 152 | public void setFreeRegexList (List<String> freeRegexList) { |
| 153 | this.freeRegexList = freeRegexList; |
| 154 | } |
| 155 | |
| 156 | public List<String> getPublicRegexList () { |
| 157 | return publicRegexList; |
| 158 | } |
| 159 | |
| 160 | public void setPublicRegexList (List<String> publicRegexList) { |
| 161 | this.publicRegexList = publicRegexList; |
| 162 | } |
| 163 | |
| 164 | public List<String> getAllRegexList () { |
| 165 | return allRegexList; |
| 166 | } |
| 167 | |
| 168 | public void setAllRegexList (List<String> allRegexList) { |
| 169 | this.allRegexList = allRegexList; |
| 170 | } |
| 171 | |
| margaretha | 979a2e6 | 2017-12-12 19:47:04 +0100 | [diff] [blame] | 172 | public String getFreeOnlyRegex () { |
| 173 | return freeOnlyRegex; |
| 174 | } |
| 175 | |
| 176 | public void setFreeOnlyRegex (String freeOnlyRegex) { |
| 177 | this.freeOnlyRegex = freeOnlyRegex; |
| 178 | } |
| 179 | |
| 180 | public String getPublicOnlyRegex () { |
| 181 | return publicOnlyRegex; |
| 182 | } |
| 183 | |
| 184 | public void setPublicOnlyRegex (String publicOnlyRegex) { |
| 185 | this.publicOnlyRegex = publicOnlyRegex; |
| 186 | } |
| 187 | |
| 188 | public String getAllOnlyRegex () { |
| 189 | return allOnlyRegex; |
| 190 | } |
| 191 | |
| 192 | public void setAllOnlyRegex (String allOnlyRegex) { |
| 193 | this.allOnlyRegex = allOnlyRegex; |
| 194 | } |
| 195 | |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame^] | 196 | public boolean isSoftDeleteGroup () { |
| 197 | return isSoftDeleteGroup; |
| 198 | } |
| 199 | |
| 200 | public void setSoftDeleteGroup (boolean isSoftDeleteGroup) { |
| 201 | this.isSoftDeleteGroup = isSoftDeleteGroup; |
| 202 | } |
| 203 | |
| 204 | public boolean isSoftDeleteGroupMember () { |
| 205 | return isSoftDeleteGroupMember; |
| 206 | } |
| 207 | |
| 208 | public void setSoftDeleteGroupMember (boolean isSoftDeleteGroupMember) { |
| 209 | this.isSoftDeleteGroupMember = isSoftDeleteGroupMember; |
| 210 | } |
| 211 | |
| 212 | public boolean isSoftDeleteAutoGroup () { |
| 213 | return isSoftDeleteAutoGroup; |
| 214 | } |
| 215 | |
| 216 | public void setSoftDeleteAutoGroup (boolean isSoftDeleteAutoGroup) { |
| 217 | this.isSoftDeleteAutoGroup = isSoftDeleteAutoGroup; |
| 218 | } |
| 219 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 220 | } |