| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.config; |
| 2 | |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 3 | import java.io.File; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 4 | import java.io.IOException; |
| margaretha | 5225ed0 | 2018-06-25 18:38:40 +0200 | [diff] [blame] | 5 | import java.io.InputStream; |
| margaretha | 5225ed0 | 2018-06-25 18:38:40 +0200 | [diff] [blame] | 6 | import java.net.MalformedURLException; |
| 7 | import java.net.URI; |
| 8 | import java.net.URISyntaxException; |
| 9 | import java.net.URL; |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 10 | import java.nio.charset.Charset; |
| margaretha | 5225ed0 | 2018-06-25 18:38:40 +0200 | [diff] [blame] | 11 | import java.security.interfaces.RSAPrivateKey; |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 12 | import java.text.ParseException; |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 13 | import java.util.ArrayList; |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 14 | import java.util.Arrays; |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 15 | import java.util.List; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 16 | import java.util.Properties; |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 17 | import java.util.Set; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 18 | import java.util.regex.Pattern; |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 19 | import java.util.stream.Collectors; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 20 | |
| margaretha | 14686b5 | 2021-07-26 15:24:16 +0200 | [diff] [blame] | 21 | import org.apache.logging.log4j.LogManager; |
| 22 | import org.apache.logging.log4j.Logger; |
| 23 | |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 24 | import com.nimbusds.jose.JOSEException; |
| 25 | import com.nimbusds.jose.jwk.JWK; |
| 26 | import com.nimbusds.jose.jwk.JWKSet; |
| 27 | import com.nimbusds.jose.jwk.RSAKey; |
| 28 | import com.nimbusds.jose.util.IOUtils; |
| margaretha | 5225ed0 | 2018-06-25 18:38:40 +0200 | [diff] [blame] | 29 | |
| margaretha | 6374f72 | 2018-04-17 18:45:57 +0200 | [diff] [blame] | 30 | import de.ids_mannheim.korap.constant.AuthenticationMethod; |
| margaretha | 6d61a55 | 2018-04-10 19:26:44 +0200 | [diff] [blame] | 31 | import de.ids_mannheim.korap.interfaces.EncryptionIface; |
| margaretha | 9c78e1a | 2018-06-27 14:12:35 +0200 | [diff] [blame] | 32 | import de.ids_mannheim.korap.oauth2.openid.OpenIdConfiguration; |
| margaretha | 064eb6f | 2018-07-10 18:33:01 +0200 | [diff] [blame] | 33 | import de.ids_mannheim.korap.utils.TimeUtils; |
| margaretha | 14686b5 | 2021-07-26 15:24:16 +0200 | [diff] [blame] | 34 | import net.sf.ehcache.Cache; |
| 35 | import net.sf.ehcache.CacheManager; |
| 36 | import net.sf.ehcache.config.CacheConfiguration; |
| margaretha | 6d61a55 | 2018-04-10 19:26:44 +0200 | [diff] [blame] | 37 | |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 38 | /** |
| 39 | * Configuration for Kustvakt full version including properties |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 40 | * concerning authentication and licenses. |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 41 | * |
| 42 | * @author margaretha |
| 43 | * |
| 44 | */ |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 45 | |
| margaretha | 2afb97d | 2017-12-07 19:18:44 +0100 | [diff] [blame] | 46 | public class FullConfiguration extends KustvaktConfiguration { |
| margaretha | 14686b5 | 2021-07-26 15:24:16 +0200 | [diff] [blame] | 47 | public static Logger jlog = LogManager.getLogger(FullConfiguration.class); |
| margaretha | 58e1863 | 2018-02-15 13:04:42 +0100 | [diff] [blame] | 48 | // mail configuration |
| 49 | private boolean isMailEnabled; |
| 50 | private String testEmail; |
| margaretha | aecee1b | 2018-02-20 14:44:21 +0100 | [diff] [blame] | 51 | private String noReply; |
| margaretha | 7d0165c | 2018-02-26 15:31:37 +0100 | [diff] [blame] | 52 | private String emailAddressRetrieval; |
| margaretha | 6b3ecdd | 2018-03-01 18:23:56 +0100 | [diff] [blame] | 53 | |
| margaretha | a86b141 | 2018-02-21 20:40:35 +0100 | [diff] [blame] | 54 | private String groupInvitationTemplate; |
| margaretha | 6b3ecdd | 2018-03-01 18:23:56 +0100 | [diff] [blame] | 55 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 56 | private String ldapConfig; |
| 57 | |
| 58 | private String freeOnlyRegex; |
| 59 | private String publicOnlyRegex; |
| 60 | private String allOnlyRegex; |
| 61 | |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 62 | private List<String> freeRegexList; |
| 63 | private List<String> publicRegexList; |
| 64 | private List<String> allRegexList; |
| 65 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 66 | private String authenticationScheme; |
| 67 | |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame] | 68 | private boolean isSoftDeleteAutoGroup; |
| 69 | private boolean isSoftDeleteGroup; |
| 70 | private boolean isSoftDeleteGroupMember; |
| 71 | |
| margaretha | 33fa3d9 | 2018-07-26 13:50:17 +0200 | [diff] [blame] | 72 | private EncryptionIface.Encryption secureHashAlgorithm; |
| margaretha | 6374f72 | 2018-04-17 18:45:57 +0200 | [diff] [blame] | 73 | |
| 74 | private AuthenticationMethod OAuth2passwordAuthentication; |
| 75 | private String nativeClientHost; |
| margaretha | be4c5c9 | 2018-05-03 18:55:49 +0200 | [diff] [blame] | 76 | private Set<String> defaultAccessScopes; |
| 77 | private Set<String> clientCredentialsScopes; |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 78 | private int maxAuthenticationAttempts; |
| margaretha | 6374f72 | 2018-04-17 18:45:57 +0200 | [diff] [blame] | 79 | |
| margaretha | 0afd44a | 2020-02-05 10:49:21 +0100 | [diff] [blame] | 80 | private int accessTokenLongExpiry; |
| margaretha | 064eb6f | 2018-07-10 18:33:01 +0200 | [diff] [blame] | 81 | private int accessTokenExpiry; |
| margaretha | d716312 | 2022-04-11 09:42:41 +0200 | [diff] [blame] | 82 | private int refreshTokenLongExpiry; |
| margaretha | 064eb6f | 2018-07-10 18:33:01 +0200 | [diff] [blame] | 83 | private int refreshTokenExpiry; |
| 84 | private int authorizationCodeExpiry; |
| margaretha | 9e73c0e | 2023-05-05 16:51:49 +0200 | [diff] [blame^] | 85 | |
| 86 | private int maxNumberOfUserQueries; |
| 87 | |
| margaretha | 5225ed0 | 2018-06-25 18:38:40 +0200 | [diff] [blame] | 88 | private URL issuer; |
| 89 | private URI issuerURI; |
| margaretha | 9c78e1a | 2018-06-27 14:12:35 +0200 | [diff] [blame] | 90 | private OpenIdConfiguration openidConfig; |
| 91 | |
| margaretha | 5225ed0 | 2018-06-25 18:38:40 +0200 | [diff] [blame] | 92 | private RSAPrivateKey rsaPrivateKey; |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 93 | private JWKSet publicKeySet; |
| 94 | private String rsaKeyId; |
| margaretha | 339fd2e | 2018-11-13 12:14:53 +0100 | [diff] [blame] | 95 | |
| margaretha | 1b32045 | 2018-08-02 16:56:25 +0200 | [diff] [blame] | 96 | private String namedVCPath; |
| margaretha | 3181b8d | 2022-05-31 11:51:47 +0200 | [diff] [blame] | 97 | |
| 98 | private boolean createInitialSuperClient; |
| margaretha | 5225ed0 | 2018-06-25 18:38:40 +0200 | [diff] [blame] | 99 | |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 100 | public FullConfiguration (Properties properties) throws Exception { |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 101 | super(properties); |
| 102 | } |
| margaretha | 3d55b00 | 2019-03-19 12:00:44 +0100 | [diff] [blame] | 103 | |
| 104 | public FullConfiguration () { |
| 105 | super(); |
| 106 | } |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 107 | |
| 108 | @Override |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 109 | public void load (Properties properties) throws Exception { |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 110 | |
| 111 | super.load(properties); |
| 112 | // EM: regex used for storing vc |
| 113 | setLicenseRegex(properties); |
| 114 | |
| 115 | // EM: pattern for matching availability in Krill matches |
| 116 | setLicensePatterns(properties); |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame] | 117 | setDeleteConfiguration(properties); |
| margaretha | 58e1863 | 2018-02-15 13:04:42 +0100 | [diff] [blame] | 118 | setMailConfiguration(properties); |
| margaretha | 2afb97d | 2017-12-07 19:18:44 +0100 | [diff] [blame] | 119 | ldapConfig = properties.getProperty("ldap.config"); |
| margaretha | 58e1863 | 2018-02-15 13:04:42 +0100 | [diff] [blame] | 120 | |
| margaretha | 33fa3d9 | 2018-07-26 13:50:17 +0200 | [diff] [blame] | 121 | setSecurityConfiguration(properties); |
| margaretha | 6374f72 | 2018-04-17 18:45:57 +0200 | [diff] [blame] | 122 | setOAuth2Configuration(properties); |
| margaretha | 5225ed0 | 2018-06-25 18:38:40 +0200 | [diff] [blame] | 123 | setOpenIdConfiguration(properties); |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 124 | setRSAKeys(properties); |
| margaretha | 339fd2e | 2018-11-13 12:14:53 +0100 | [diff] [blame] | 125 | |
| 126 | setNamedVCPath(properties.getProperty("krill.namedVC", "")); |
| margaretha | 14686b5 | 2021-07-26 15:24:16 +0200 | [diff] [blame] | 127 | |
| 128 | Cache cache = CacheManager.newInstance().getCache("named_vc"); |
| 129 | CacheConfiguration config = cache.getCacheConfiguration(); |
| 130 | config.setMaxBytesLocalHeap(properties.getProperty("cache.max.bytes.local.heap", "256m")); |
| 131 | config.setMaxBytesLocalDisk(properties.getProperty("cache.max.bytes.local.disk", "2G")); |
| 132 | jlog.info("max local heap:"+config.getMaxBytesLocalHeapAsString()); |
| 133 | jlog.info("max local disk:"+config.getMaxBytesLocalDiskAsString()); |
| margaretha | 9e73c0e | 2023-05-05 16:51:49 +0200 | [diff] [blame^] | 134 | |
| 135 | setMaxNumberOfUserQueries(Integer.parseInt( |
| 136 | properties.getProperty("max.user.persistent.queries", "20"))); |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 137 | } |
| 138 | |
| margaretha | 33fa3d9 | 2018-07-26 13:50:17 +0200 | [diff] [blame] | 139 | private void setSecurityConfiguration (Properties properties) { |
| 140 | setSecureHashAlgorithm(Enum.valueOf(EncryptionIface.Encryption.class, |
| 141 | properties.getProperty("security.secure.hash.algorithm", |
| 142 | "BCRYPT"))); |
| margaretha | 33fa3d9 | 2018-07-26 13:50:17 +0200 | [diff] [blame] | 143 | } |
| 144 | |
| margaretha | 9c78e1a | 2018-06-27 14:12:35 +0200 | [diff] [blame] | 145 | private void setOpenIdConfiguration (Properties properties) |
| 146 | throws URISyntaxException, MalformedURLException { |
| 147 | String issuerStr = properties.getProperty("security.jwt.issuer", |
| 148 | "https://korap.ids-mannheim.de"); |
| 149 | |
| 150 | if (!issuerStr.startsWith("http")) { |
| 151 | issuerStr = "http://" + issuerStr; |
| 152 | } |
| 153 | setIssuer(new URL(issuerStr)); |
| 154 | setIssuerURI(issuer.toURI()); |
| 155 | |
| 156 | issuerStr = issuerURI.toString(); |
| 157 | |
| 158 | OpenIdConfiguration openidConfig = new OpenIdConfiguration(); |
| 159 | openidConfig.setIssuer(issuerStr); |
| 160 | openidConfig.setJwks_uri(issuerStr + OpenIdConfiguration.JWKS_ENDPOINT); |
| 161 | openidConfig.setRegistration_endpoint( |
| 162 | issuerStr + OpenIdConfiguration.CLIENT_REGISTRATION_ENDPOINT); |
| 163 | openidConfig.setAuthorization_endpoint( |
| 164 | issuerStr + OpenIdConfiguration.AUTHORIZATION_ENDPOINT); |
| 165 | openidConfig.setToken_endpoint( |
| 166 | issuerStr + OpenIdConfiguration.TOKEN_ENDPOINT); |
| 167 | |
| 168 | String grantTypes = properties.getProperty("openid.grant.types", ""); |
| 169 | openidConfig.setGrant_types_supported(grantTypes.split(" ")); |
| 170 | |
| 171 | String responseTypes = |
| 172 | properties.getProperty("openid.response.types", "code"); |
| 173 | openidConfig.setResponse_types_supported(responseTypes.split(" ")); |
| 174 | |
| 175 | String responseModes = |
| 176 | properties.getProperty("openid.response.modes", ""); |
| 177 | openidConfig.setResponse_modes_supported(responseModes.split(" ")); |
| 178 | |
| 179 | String clientAuthMethods = |
| 180 | properties.getProperty("openid.client.auth.methods", ""); |
| 181 | openidConfig.setToken_endpoint_auth_methods_supported( |
| 182 | clientAuthMethods.split(" ")); |
| 183 | |
| 184 | String tokenSigningAlgorithms = properties |
| 185 | .getProperty("openid.token.signing.algorithms", "RS256"); |
| 186 | openidConfig.setToken_endpoint_auth_signing_alg_values_supported( |
| 187 | tokenSigningAlgorithms.split(" ")); |
| 188 | |
| 189 | String subjectTypes = |
| 190 | properties.getProperty("openid.subject.types", "public"); |
| 191 | openidConfig.setSubject_types_supported(subjectTypes.split(" ")); |
| 192 | |
| 193 | String displayTypes = |
| 194 | properties.getProperty("openid.display.types", ""); |
| 195 | openidConfig.setDisplay_values_supported(displayTypes.split(" ")); |
| 196 | |
| 197 | String supportedScopes = |
| 198 | properties.getProperty("openid.supported.scopes", ""); |
| 199 | openidConfig.setScopes_supported(supportedScopes.split(" ")); |
| 200 | |
| 201 | String claimTypes = |
| 202 | properties.getProperty("openid.claim.types", "normal"); |
| 203 | openidConfig.setClaim_types_supported(claimTypes.split(" ")); |
| 204 | |
| 205 | String supportedClaims = |
| 206 | properties.getProperty("openid.supported.claims", ""); |
| 207 | openidConfig.setClaims_supported(supportedClaims.split(" ")); |
| 208 | |
| 209 | String claimLocales = |
| 210 | properties.getProperty("openid.supported.claim.locales", ""); |
| 211 | openidConfig.setClaims_locales_supported(claimLocales.split(" ")); |
| 212 | |
| 213 | String uiLocales = properties.getProperty("openid.ui.locales", "en"); |
| 214 | openidConfig.setUi_locales_supported(uiLocales.split(" ")); |
| 215 | |
| 216 | boolean supportClaimParam = Boolean.getBoolean( |
| 217 | properties.getProperty("openid.support.claim.param", "false")); |
| 218 | openidConfig.setClaims_parameter_supported(supportClaimParam); |
| 219 | |
| 220 | openidConfig.setRequest_parameter_supported(false); |
| 221 | openidConfig.setRequest_uri_parameter_supported(false); |
| 222 | openidConfig.setRequire_request_uri_registration(false); |
| 223 | openidConfig.setMutual_tls_sender_constrained_access_tokens(false); |
| 224 | |
| 225 | String privacyPolicy = |
| 226 | properties.getProperty("openid.privacy.policy", ""); |
| 227 | openidConfig.setOp_policy_uri(privacyPolicy); |
| 228 | |
| 229 | String termOfService = |
| 230 | properties.getProperty("openid.term.of.service", ""); |
| 231 | openidConfig.setOp_tos_uri(termOfService); |
| 232 | |
| 233 | String serviceDocURL = properties.getProperty("openid.service.doc", ""); |
| 234 | openidConfig.setService_documentation(serviceDocURL); |
| 235 | this.setOpenidConfig(openidConfig); |
| 236 | } |
| 237 | |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 238 | private void setRSAKeys (Properties properties) |
| 239 | throws IOException, ParseException, JOSEException { |
| 240 | setRsaKeyId(properties.getProperty("rsa.key.id", "")); |
| 241 | |
| margaretha | d7cab21 | 2018-07-02 19:01:43 +0200 | [diff] [blame] | 242 | String rsaPublic = properties.getProperty("rsa.public", null); |
| 243 | setPublicKeySet(rsaPublic); |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 244 | |
| margaretha | d7cab21 | 2018-07-02 19:01:43 +0200 | [diff] [blame] | 245 | String rsaPrivate = properties.getProperty("rsa.private", null); |
| 246 | setRsaPrivateKey(rsaPrivate); |
| margaretha | 5225ed0 | 2018-06-25 18:38:40 +0200 | [diff] [blame] | 247 | } |
| 248 | |
| margaretha | 6374f72 | 2018-04-17 18:45:57 +0200 | [diff] [blame] | 249 | private void setOAuth2Configuration (Properties properties) { |
| 250 | setOAuth2passwordAuthentication( |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 251 | Enum.valueOf(AuthenticationMethod.class, properties.getProperty( |
| 252 | "oauth2.password.authentication", "TEST"))); |
| 253 | setNativeClientHost(properties.getProperty("oauth2.native.client.host", |
| margaretha | 6374f72 | 2018-04-17 18:45:57 +0200 | [diff] [blame] | 254 | "korap.ids-mannheim.de")); |
| margaretha | 3181b8d | 2022-05-31 11:51:47 +0200 | [diff] [blame] | 255 | setCreateInitialSuperClient(Boolean.valueOf( |
| 256 | properties.getProperty("oauth2.initial.super.client", "false"))); |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 257 | |
| 258 | setMaxAuthenticationAttempts(Integer |
| margaretha | 064eb6f | 2018-07-10 18:33:01 +0200 | [diff] [blame] | 259 | .parseInt(properties.getProperty("oauth2.max.attempts", "1"))); |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 260 | |
| 261 | String scopes = properties.getProperty("oauth2.default.scopes", |
| margaretha | 9c78e1a | 2018-06-27 14:12:35 +0200 | [diff] [blame] | 262 | "openid preferred_username"); |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 263 | Set<String> scopeSet = |
| 264 | Arrays.stream(scopes.split(" ")).collect(Collectors.toSet()); |
| margaretha | be4c5c9 | 2018-05-03 18:55:49 +0200 | [diff] [blame] | 265 | setDefaultAccessScopes(scopeSet); |
| 266 | |
| margaretha | d7cab21 | 2018-07-02 19:01:43 +0200 | [diff] [blame] | 267 | String clientScopes = properties |
| 268 | .getProperty("oauth2.client.credentials.scopes", "client_info"); |
| margaretha | be4c5c9 | 2018-05-03 18:55:49 +0200 | [diff] [blame] | 269 | setClientCredentialsScopes(Arrays.stream(clientScopes.split(" ")) |
| 270 | .collect(Collectors.toSet())); |
| margaretha | 064eb6f | 2018-07-10 18:33:01 +0200 | [diff] [blame] | 271 | |
| 272 | accessTokenExpiry = TimeUtils.convertTimeToSeconds( |
| 273 | properties.getProperty("oauth2.access.token.expiry", "1D")); |
| 274 | refreshTokenExpiry = TimeUtils.convertTimeToSeconds( |
| 275 | properties.getProperty("oauth2.refresh.token.expiry", "90D")); |
| 276 | authorizationCodeExpiry = TimeUtils.convertTimeToSeconds(properties |
| 277 | .getProperty("oauth2.authorization.code.expiry", "10M")); |
| margaretha | 0afd44a | 2020-02-05 10:49:21 +0100 | [diff] [blame] | 278 | |
| 279 | setAccessTokenLongExpiry(TimeUtils.convertTimeToSeconds( |
| 280 | properties.getProperty("oauth2.access.token.long.expiry", "365D"))); |
| margaretha | d716312 | 2022-04-11 09:42:41 +0200 | [diff] [blame] | 281 | setRefreshTokenLongExpiry(TimeUtils.convertTimeToSeconds( |
| 282 | properties.getProperty("oauth2.refresh.token.long.expiry", "365D"))); |
| margaretha | 58e1863 | 2018-02-15 13:04:42 +0100 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | private void setMailConfiguration (Properties properties) { |
| margaretha | 6b3ecdd | 2018-03-01 18:23:56 +0100 | [diff] [blame] | 286 | setMailEnabled(Boolean |
| 287 | .valueOf(properties.getProperty("mail.enabled", "false"))); |
| 288 | if (isMailEnabled) { |
| margaretha | 58e1863 | 2018-02-15 13:04:42 +0100 | [diff] [blame] | 289 | // other properties must be set in the kustvakt.conf |
| margaretha | 6b3ecdd | 2018-03-01 18:23:56 +0100 | [diff] [blame] | 290 | setTestEmail( |
| 291 | properties.getProperty("mail.receiver", "test@localhost")); |
| margaretha | aecee1b | 2018-02-20 14:44:21 +0100 | [diff] [blame] | 292 | setNoReply(properties.getProperty("mail.sender")); |
| margaretha | 6b3ecdd | 2018-03-01 18:23:56 +0100 | [diff] [blame] | 293 | setGroupInvitationTemplate( |
| 294 | properties.getProperty("template.group.invitation")); |
| 295 | setEmailAddressRetrieval( |
| 296 | properties.getProperty("mail.address.retrieval", "test")); |
| margaretha | 58e1863 | 2018-02-15 13:04:42 +0100 | [diff] [blame] | 297 | } |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame] | 300 | private void setDeleteConfiguration (Properties properties) { |
| margaretha | 58e1863 | 2018-02-15 13:04:42 +0100 | [diff] [blame] | 301 | setSoftDeleteGroup( |
| 302 | parseDeleteConfig(properties.getProperty("delete.group", ""))); |
| 303 | setSoftDeleteAutoGroup(parseDeleteConfig( |
| 304 | properties.getProperty("delete.auto.group", ""))); |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame] | 305 | setSoftDeleteGroupMember(parseDeleteConfig( |
| 306 | properties.getProperty("delete.group.member", ""))); |
| 307 | } |
| 308 | |
| 309 | private boolean parseDeleteConfig (String deleteConfig) { |
| 310 | return deleteConfig.equals("soft") ? true : false; |
| 311 | } |
| 312 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 313 | private void setLicensePatterns (Properties properties) { |
| margaretha | 979a2e6 | 2017-12-12 19:47:04 +0100 | [diff] [blame] | 314 | setFreeLicensePattern(compilePattern(getFreeOnlyRegex())); |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame] | 315 | setPublicLicensePattern(compilePattern( |
| 316 | getFreeOnlyRegex() + "|" + getPublicOnlyRegex())); |
| 317 | setAllLicensePattern(compilePattern(getFreeOnlyRegex() + "|" |
| 318 | + getPublicOnlyRegex() + "|" + getAllOnlyRegex())); |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | private void setLicenseRegex (Properties properties) { |
| margaretha | 979a2e6 | 2017-12-12 19:47:04 +0100 | [diff] [blame] | 322 | setFreeOnlyRegex(properties.getProperty("availability.regex.free", "")); |
| 323 | freeRegexList = splitAndAddToList(getFreeOnlyRegex()); |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 324 | |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame] | 325 | setPublicOnlyRegex( |
| 326 | properties.getProperty("availability.regex.public", "")); |
| margaretha | 979a2e6 | 2017-12-12 19:47:04 +0100 | [diff] [blame] | 327 | publicRegexList = splitAndAddToList(getPublicOnlyRegex()); |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 328 | |
| margaretha | 979a2e6 | 2017-12-12 19:47:04 +0100 | [diff] [blame] | 329 | setAllOnlyRegex(properties.getProperty("availability.regex.all", "")); |
| 330 | allRegexList = splitAndAddToList(getAllOnlyRegex()); |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | private List<String> splitAndAddToList (String regex) { |
| 334 | List<String> list; |
| 335 | if (regex.contains("|")) { |
| 336 | String[] regexes = regex.split("\\|"); |
| 337 | list = new ArrayList<>(regexes.length); |
| 338 | for (String s : regexes) { |
| 339 | list.add(s.trim()); |
| 340 | } |
| 341 | } |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame] | 342 | else { |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 343 | list = new ArrayList<>(1); |
| 344 | list.add(regex); |
| 345 | } |
| 346 | return list; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 347 | } |
| 348 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 349 | private Pattern compilePattern (String patternStr) { |
| 350 | if (!patternStr.isEmpty()) { |
| 351 | return Pattern.compile(patternStr); |
| 352 | } |
| 353 | else { |
| 354 | return null; |
| 355 | } |
| 356 | } |
| 357 | |
| margaretha | dfecb4b | 2017-12-12 19:32:30 +0100 | [diff] [blame] | 358 | public String getLdapConfig () { |
| 359 | return ldapConfig; |
| 360 | } |
| 361 | |
| 362 | public Pattern getPublicLicensePattern () { |
| 363 | return publicLicensePattern; |
| 364 | } |
| 365 | |
| 366 | public void setPublicLicensePattern (Pattern publicLicensePattern) { |
| 367 | this.publicLicensePattern = publicLicensePattern; |
| 368 | } |
| 369 | |
| 370 | public Pattern getFreeLicensePattern () { |
| 371 | return freeLicensePattern; |
| 372 | } |
| 373 | |
| 374 | public void setFreeLicensePattern (Pattern freeLicensePattern) { |
| 375 | this.freeLicensePattern = freeLicensePattern; |
| 376 | } |
| 377 | |
| 378 | public Pattern getAllLicensePattern () { |
| 379 | return allLicensePattern; |
| 380 | } |
| 381 | |
| 382 | public void setAllLicensePattern (Pattern allLicensePattern) { |
| 383 | this.allLicensePattern = allLicensePattern; |
| 384 | } |
| 385 | |
| 386 | public String getAuthenticationScheme () { |
| 387 | return authenticationScheme; |
| 388 | } |
| 389 | |
| 390 | public void setAuthenticationScheme (String authenticationScheme) { |
| 391 | this.authenticationScheme = authenticationScheme; |
| 392 | } |
| 393 | |
| 394 | public List<String> getFreeRegexList () { |
| 395 | return freeRegexList; |
| 396 | } |
| 397 | |
| 398 | public void setFreeRegexList (List<String> freeRegexList) { |
| 399 | this.freeRegexList = freeRegexList; |
| 400 | } |
| 401 | |
| 402 | public List<String> getPublicRegexList () { |
| 403 | return publicRegexList; |
| 404 | } |
| 405 | |
| 406 | public void setPublicRegexList (List<String> publicRegexList) { |
| 407 | this.publicRegexList = publicRegexList; |
| 408 | } |
| 409 | |
| 410 | public List<String> getAllRegexList () { |
| 411 | return allRegexList; |
| 412 | } |
| 413 | |
| 414 | public void setAllRegexList (List<String> allRegexList) { |
| 415 | this.allRegexList = allRegexList; |
| 416 | } |
| 417 | |
| margaretha | 979a2e6 | 2017-12-12 19:47:04 +0100 | [diff] [blame] | 418 | public String getFreeOnlyRegex () { |
| 419 | return freeOnlyRegex; |
| 420 | } |
| 421 | |
| 422 | public void setFreeOnlyRegex (String freeOnlyRegex) { |
| 423 | this.freeOnlyRegex = freeOnlyRegex; |
| 424 | } |
| 425 | |
| 426 | public String getPublicOnlyRegex () { |
| 427 | return publicOnlyRegex; |
| 428 | } |
| 429 | |
| 430 | public void setPublicOnlyRegex (String publicOnlyRegex) { |
| 431 | this.publicOnlyRegex = publicOnlyRegex; |
| 432 | } |
| 433 | |
| 434 | public String getAllOnlyRegex () { |
| 435 | return allOnlyRegex; |
| 436 | } |
| 437 | |
| 438 | public void setAllOnlyRegex (String allOnlyRegex) { |
| 439 | this.allOnlyRegex = allOnlyRegex; |
| 440 | } |
| 441 | |
| margaretha | 2c019fa | 2018-02-01 19:50:51 +0100 | [diff] [blame] | 442 | public boolean isSoftDeleteGroup () { |
| 443 | return isSoftDeleteGroup; |
| 444 | } |
| 445 | |
| 446 | public void setSoftDeleteGroup (boolean isSoftDeleteGroup) { |
| 447 | this.isSoftDeleteGroup = isSoftDeleteGroup; |
| 448 | } |
| 449 | |
| 450 | public boolean isSoftDeleteGroupMember () { |
| 451 | return isSoftDeleteGroupMember; |
| 452 | } |
| 453 | |
| 454 | public void setSoftDeleteGroupMember (boolean isSoftDeleteGroupMember) { |
| 455 | this.isSoftDeleteGroupMember = isSoftDeleteGroupMember; |
| 456 | } |
| 457 | |
| 458 | public boolean isSoftDeleteAutoGroup () { |
| 459 | return isSoftDeleteAutoGroup; |
| 460 | } |
| 461 | |
| 462 | public void setSoftDeleteAutoGroup (boolean isSoftDeleteAutoGroup) { |
| 463 | this.isSoftDeleteAutoGroup = isSoftDeleteAutoGroup; |
| 464 | } |
| 465 | |
| margaretha | 58e1863 | 2018-02-15 13:04:42 +0100 | [diff] [blame] | 466 | public String getTestEmail () { |
| 467 | return testEmail; |
| 468 | } |
| 469 | |
| 470 | public void setTestEmail (String testEmail) { |
| 471 | this.testEmail = testEmail; |
| 472 | } |
| 473 | |
| margaretha | 58e1863 | 2018-02-15 13:04:42 +0100 | [diff] [blame] | 474 | public boolean isMailEnabled () { |
| 475 | return isMailEnabled; |
| 476 | } |
| 477 | |
| 478 | public void setMailEnabled (boolean isMailEnabled) { |
| 479 | this.isMailEnabled = isMailEnabled; |
| 480 | } |
| 481 | |
| margaretha | aecee1b | 2018-02-20 14:44:21 +0100 | [diff] [blame] | 482 | public String getNoReply () { |
| 483 | return noReply; |
| 484 | } |
| 485 | |
| 486 | public void setNoReply (String noReply) { |
| 487 | this.noReply = noReply; |
| 488 | } |
| 489 | |
| margaretha | a86b141 | 2018-02-21 20:40:35 +0100 | [diff] [blame] | 490 | public String getGroupInvitationTemplate () { |
| 491 | return groupInvitationTemplate; |
| 492 | } |
| 493 | |
| 494 | public void setGroupInvitationTemplate (String groupInvitationTemplate) { |
| 495 | this.groupInvitationTemplate = groupInvitationTemplate; |
| 496 | } |
| 497 | |
| margaretha | 7d0165c | 2018-02-26 15:31:37 +0100 | [diff] [blame] | 498 | public String getEmailAddressRetrieval () { |
| 499 | return emailAddressRetrieval; |
| 500 | } |
| 501 | |
| 502 | public void setEmailAddressRetrieval (String emailAddressRetrieval) { |
| 503 | this.emailAddressRetrieval = emailAddressRetrieval; |
| 504 | } |
| 505 | |
| margaretha | 33fa3d9 | 2018-07-26 13:50:17 +0200 | [diff] [blame] | 506 | public EncryptionIface.Encryption getSecureHashAlgorithm () { |
| 507 | return secureHashAlgorithm; |
| margaretha | 6d61a55 | 2018-04-10 19:26:44 +0200 | [diff] [blame] | 508 | } |
| 509 | |
| margaretha | 33fa3d9 | 2018-07-26 13:50:17 +0200 | [diff] [blame] | 510 | public void setSecureHashAlgorithm ( |
| 511 | EncryptionIface.Encryption secureHashAlgorithm) { |
| 512 | this.secureHashAlgorithm = secureHashAlgorithm; |
| margaretha | 6d61a55 | 2018-04-10 19:26:44 +0200 | [diff] [blame] | 513 | } |
| 514 | |
| margaretha | 6374f72 | 2018-04-17 18:45:57 +0200 | [diff] [blame] | 515 | public AuthenticationMethod getOAuth2passwordAuthentication () { |
| 516 | return OAuth2passwordAuthentication; |
| 517 | } |
| 518 | |
| 519 | public void setOAuth2passwordAuthentication ( |
| 520 | AuthenticationMethod oAuth2passwordAuthentication) { |
| 521 | OAuth2passwordAuthentication = oAuth2passwordAuthentication; |
| 522 | } |
| 523 | |
| 524 | public String getNativeClientHost () { |
| 525 | return nativeClientHost; |
| 526 | } |
| 527 | |
| 528 | public void setNativeClientHost (String nativeClientHost) { |
| 529 | this.nativeClientHost = nativeClientHost; |
| 530 | } |
| 531 | |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 532 | public int getMaxAuthenticationAttempts () { |
| 533 | return maxAuthenticationAttempts; |
| 534 | } |
| 535 | |
| 536 | public void setMaxAuthenticationAttempts (int maxAuthenticationAttempts) { |
| 537 | this.maxAuthenticationAttempts = maxAuthenticationAttempts; |
| 538 | } |
| 539 | |
| margaretha | be4c5c9 | 2018-05-03 18:55:49 +0200 | [diff] [blame] | 540 | public Set<String> getDefaultAccessScopes () { |
| 541 | return defaultAccessScopes; |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 542 | } |
| 543 | |
| margaretha | be4c5c9 | 2018-05-03 18:55:49 +0200 | [diff] [blame] | 544 | public void setDefaultAccessScopes (Set<String> accessScopes) { |
| 545 | this.defaultAccessScopes = accessScopes; |
| 546 | } |
| 547 | |
| 548 | public Set<String> getClientCredentialsScopes () { |
| 549 | return clientCredentialsScopes; |
| 550 | } |
| 551 | |
| 552 | public void setClientCredentialsScopes ( |
| 553 | Set<String> clientCredentialsScopes) { |
| 554 | this.clientCredentialsScopes = clientCredentialsScopes; |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 555 | } |
| 556 | |
| margaretha | 5225ed0 | 2018-06-25 18:38:40 +0200 | [diff] [blame] | 557 | public URL getIssuer () { |
| 558 | return issuer; |
| 559 | } |
| 560 | |
| 561 | public void setIssuer (URL issuer) { |
| 562 | this.issuer = issuer; |
| 563 | } |
| 564 | |
| 565 | public URI getIssuerURI () { |
| 566 | return issuerURI; |
| 567 | } |
| 568 | |
| 569 | public void setIssuerURI (URI issuerURI) { |
| 570 | this.issuerURI = issuerURI; |
| 571 | } |
| 572 | |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 573 | public JWKSet getPublicKeySet () { |
| 574 | return publicKeySet; |
| 575 | } |
| 576 | |
| margaretha | d7cab21 | 2018-07-02 19:01:43 +0200 | [diff] [blame] | 577 | public void setPublicKeySet (String rsaPublic) |
| 578 | throws IOException, ParseException { |
| 579 | if (rsaPublic == null || rsaPublic.isEmpty()) { |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | File rsaPublicFile = new File(rsaPublic); |
| 584 | JWKSet jwkSet = null; |
| 585 | InputStream is = null; |
| 586 | if (rsaPublicFile.exists()) { |
| 587 | jwkSet = JWKSet.load(rsaPublicFile); |
| 588 | } |
| 589 | else if ((is = getClass().getClassLoader() |
| 590 | .getResourceAsStream(rsaPublic)) != null) { |
| 591 | jwkSet = JWKSet.load(is); |
| 592 | } |
| 593 | this.publicKeySet = jwkSet; |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | public RSAPrivateKey getRsaPrivateKey () { |
| 597 | return rsaPrivateKey; |
| 598 | } |
| 599 | |
| margaretha | d7cab21 | 2018-07-02 19:01:43 +0200 | [diff] [blame] | 600 | public void setRsaPrivateKey (String rsaPrivate) |
| 601 | throws IOException, ParseException, JOSEException { |
| 602 | if (rsaPrivate == null || rsaPrivate.isEmpty()) { |
| 603 | return; |
| 604 | } |
| 605 | File rsaPrivateFile = new File(rsaPrivate); |
| 606 | String keyString = null; |
| 607 | InputStream is = null; |
| 608 | if (rsaPrivateFile.exists()) { |
| 609 | keyString = IOUtils.readFileToString(rsaPrivateFile, |
| 610 | Charset.forName("UTF-8")); |
| 611 | } |
| 612 | else if ((is = getClass().getClassLoader() |
| 613 | .getResourceAsStream(rsaPrivate)) != null) { |
| 614 | keyString = IOUtils.readInputStreamToString(is, |
| 615 | Charset.forName("UTF-8")); |
| 616 | } |
| 617 | RSAKey rsaKey = (RSAKey) JWK.parse(keyString); |
| 618 | this.rsaPrivateKey = (RSAPrivateKey) rsaKey.toPrivateKey(); |
| margaretha | 1929596 | 2018-06-26 16:00:47 +0200 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | public String getRsaKeyId () { |
| 622 | return rsaKeyId; |
| 623 | } |
| 624 | |
| 625 | public void setRsaKeyId (String rsaKeyId) { |
| 626 | this.rsaKeyId = rsaKeyId; |
| 627 | } |
| 628 | |
| margaretha | 9c78e1a | 2018-06-27 14:12:35 +0200 | [diff] [blame] | 629 | public OpenIdConfiguration getOpenidConfig () { |
| 630 | return openidConfig; |
| 631 | } |
| 632 | |
| 633 | public void setOpenidConfig (OpenIdConfiguration openidConfig) { |
| 634 | this.openidConfig = openidConfig; |
| 635 | } |
| margaretha | 064eb6f | 2018-07-10 18:33:01 +0200 | [diff] [blame] | 636 | |
| 637 | public int getAccessTokenExpiry () { |
| 638 | return accessTokenExpiry; |
| 639 | } |
| 640 | |
| 641 | public void setAccessTokenExpiry (int accessTokenExpiry) { |
| 642 | this.accessTokenExpiry = accessTokenExpiry; |
| 643 | } |
| 644 | |
| 645 | public int getRefreshTokenExpiry () { |
| 646 | return refreshTokenExpiry; |
| 647 | } |
| 648 | |
| 649 | public void setRefreshTokenExpiry (int refreshTokenExpiry) { |
| 650 | this.refreshTokenExpiry = refreshTokenExpiry; |
| 651 | } |
| 652 | |
| 653 | public int getAuthorizationCodeExpiry () { |
| 654 | return authorizationCodeExpiry; |
| 655 | } |
| 656 | |
| 657 | public void setAuthorizationCodeExpiry (int authorizationCodeExpiry) { |
| 658 | this.authorizationCodeExpiry = authorizationCodeExpiry; |
| 659 | } |
| margaretha | 33fa3d9 | 2018-07-26 13:50:17 +0200 | [diff] [blame] | 660 | |
| margaretha | 1b32045 | 2018-08-02 16:56:25 +0200 | [diff] [blame] | 661 | public String getNamedVCPath () { |
| 662 | return namedVCPath; |
| 663 | } |
| 664 | |
| 665 | public void setNamedVCPath (String namedVCPath) { |
| 666 | this.namedVCPath = namedVCPath; |
| 667 | } |
| margaretha | 0afd44a | 2020-02-05 10:49:21 +0100 | [diff] [blame] | 668 | |
| 669 | public int getAccessTokenLongExpiry () { |
| 670 | return accessTokenLongExpiry; |
| 671 | } |
| 672 | |
| 673 | public void setAccessTokenLongExpiry (int accessTokenLongExpiry) { |
| 674 | this.accessTokenLongExpiry = accessTokenLongExpiry; |
| 675 | } |
| margaretha | d716312 | 2022-04-11 09:42:41 +0200 | [diff] [blame] | 676 | |
| 677 | public int getRefreshTokenLongExpiry () { |
| 678 | return refreshTokenLongExpiry; |
| 679 | } |
| 680 | |
| 681 | public void setRefreshTokenLongExpiry (int refreshTokenLongExpiry) { |
| 682 | this.refreshTokenLongExpiry = refreshTokenLongExpiry; |
| 683 | } |
| margaretha | 3181b8d | 2022-05-31 11:51:47 +0200 | [diff] [blame] | 684 | |
| 685 | public boolean createInitialSuperClient () { |
| 686 | return createInitialSuperClient; |
| 687 | } |
| 688 | |
| 689 | public void setCreateInitialSuperClient (boolean initialSuperClient) { |
| 690 | this.createInitialSuperClient = initialSuperClient; |
| 691 | } |
| margaretha | 9e73c0e | 2023-05-05 16:51:49 +0200 | [diff] [blame^] | 692 | |
| 693 | public int getMaxNumberOfUserQueries () { |
| 694 | return maxNumberOfUserQueries; |
| 695 | } |
| 696 | |
| 697 | public void setMaxNumberOfUserQueries (int maxNumberOfUserQueries) { |
| 698 | this.maxNumberOfUserQueries = maxNumberOfUserQueries; |
| 699 | } |
| margaretha | 3181b8d | 2022-05-31 11:51:47 +0200 | [diff] [blame] | 700 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 701 | } |