11package com ._4point .aem .fluentforms .spring ;
22
3+ import java .util .Optional ;
4+
35import org .springframework .boot .context .properties .ConfigurationProperties ;
46import org .springframework .boot .context .properties .bind .DefaultValue ;
57
1618 *
1719 */
1820@ EnableEncryptableProperties
19- @ ConfigurationProperties ("fluentforms.aem" )
21+ @ ConfigurationProperties (AemConfiguration . CONFIGURATION_PREFIX )
2022public record AemConfiguration (
2123 String servername , // "aem.servername"
2224 Integer port , // "aem.port"
@@ -26,7 +28,33 @@ public record AemConfiguration(
2628 @ DefaultValue ("aem" ) String sslBundle // "aem.sslBundle" - Spring SSL Bundle for trust store
2729 ) {
2830
31+ public static final String CONFIGURATION_PREFIX = "fluentforms.aem" ;
32+
2933 public String url () {
30- return "http" + (useSsl ? "s" : "" ) + "://" + servername + (port != null && port != 80 ? ":" + port : "" ) + "/" ;
34+ return "http" + (useSsl ? "s" : "" ) + "://" + (servername != null ? servername : "localhost" ) + (port != null && port != 80 ? ":" + port : "" ) + "/" ;
35+ }
36+
37+ public record Credentials (String user , String password ) {}
38+
39+ public Optional <Credentials > getCredentials () {
40+ boolean hasUser = hasUser ();
41+ boolean hasPassword = hasPassword ();
42+ if (hasUser && hasPassword ) {
43+ return Optional .of (new Credentials (user , password ));
44+ } else if (!hasUser && !hasPassword ) {
45+ return Optional .empty ();
46+ } else if (hasUser ) {
47+ throw new IllegalStateException ("AEM user is specified but password is missing. (" + CONFIGURATION_PREFIX + ".password)" );
48+ } else { /* must be hasPassword() */
49+ throw new IllegalStateException ("AEM password is specified but user is missing. (" + CONFIGURATION_PREFIX + ".user)" );
50+ }
51+ }
52+
53+ private boolean hasUser () {
54+ return user != null && !user .isBlank ();
55+ }
56+
57+ private boolean hasPassword () {
58+ return password != null && !password .isBlank ();
3159 }
3260}
0 commit comments