Enabled custom implementation for email address retrieval.
Change-Id: I9e45117dedf23c5005745ff81e60aa98bebfb34e
diff --git a/README.md b/README.md
index 634aae8..7b649c7 100644
--- a/README.md
+++ b/README.md
@@ -156,14 +156,22 @@
In kustvakt.conf or kustvakt-test.conf, set
mail.enabled = true
- mail.receiver = test@localhost
mail.sender = noreply@ids-mannheim.de
+ mail.receiver = test@localhost
+ mail.address.retrieval = test
+You can change ```mail.sender``` value to any email address (beware
+of spam in your mail server configuration). ```mail.receiver```
+is an email address used for testing. All mails are to be sent to this
+email address. Change ```test``` to any username available in your system,
+or create an alias for ```test@localhost```.
-You can change ```mail.sender``` value to any email address.
-```mail.receiver``` is only used for testing purpose. Change
-```test``` to any username available in your system, or create an alias for
-```test@localhost```.
+```mail.address.retrieval```
+determines how user email addresses are retrieved. By default and
+for testing, only the ```mail.receiver``` value is used as the
+email address of all users. For custom implementation,
+please refer to ```de.ids_mannheim.korap.authentication.KustvaktAuthenticationManager.getUser(String, String)```
+
To view the mailbox, you can use ```mailx```
diff --git a/core/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java b/core/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
index 09d495f..f968b61 100644
--- a/core/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
+++ b/core/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
@@ -123,4 +123,9 @@
public String providerList () {
return "provider list: " + this.providers.toString();
}
+
+
+ public abstract User getUser (String username, String method)
+ throws KustvaktException;
+
}
diff --git a/full/Changes b/full/Changes
index 7d83752..7c82ed6 100644
--- a/full/Changes
+++ b/full/Changes
@@ -1,9 +1,11 @@
version 0.60 release
-21/02/2018
+26/02/2018
- set up mail settings using localhost port 25 (margaretha)
- added mail template in kustvakt configuration (margaretha)
- added mail settings to readme (margaretha)
- disabled email notification for auto group (margaretha)
+ - added metadata retrieval (diewald)
+ - enabled custom implementation for email address retrieval (margaretha)
version 0.59.10
20/02/2018
diff --git a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
index 0015e89..8a8ac3d 100644
--- a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
+++ b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
@@ -139,11 +139,27 @@
//EM:copied from EntityDao
KorAPUser user = new KorAPUser(); // oder eigentlich new DemoUser oder new DefaultUser.
user.setUsername(username);
- // get user data
- user.setEmail(config.getTestEmail());
return user;
// return entHandler.getAccount(username);
}
+
+ @Override
+ public User getUser (String username, String method)
+ throws KustvaktException {
+ KorAPUser user = new KorAPUser();
+ user.setUsername(username);
+ String email = null;
+ switch (method.toLowerCase()) {
+ case "ldap":
+ email = config.getTestEmail();
+ break;
+ default:
+ email = config.getTestEmail();
+ break;
+ }
+ user.setEmail(email);
+ return user;
+ }
public TokenContext refresh(TokenContext context) throws KustvaktException {
AuthenticationIface provider = getProvider(context.getTokenType(), null);
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/FullConfiguration.java b/full/src/main/java/de/ids_mannheim/korap/config/FullConfiguration.java
index 201fc4b..aee009b 100644
--- a/full/src/main/java/de/ids_mannheim/korap/config/FullConfiguration.java
+++ b/full/src/main/java/de/ids_mannheim/korap/config/FullConfiguration.java
@@ -18,7 +18,8 @@
private boolean isMailEnabled;
private String testEmail;
private String noReply;
-
+ private String emailAddressRetrieval;
+
private String groupInvitationTemplate;
private String ldapConfig;
@@ -64,9 +65,10 @@
setMailEnabled(Boolean.valueOf(properties.getProperty("mail.enabled", "false")));
if (isMailEnabled){
// other properties must be set in the kustvakt.conf
- setTestEmail(properties.getProperty("mail.receiver"));
+ setTestEmail(properties.getProperty("mail.receiver","test@localhost"));
setNoReply(properties.getProperty("mail.sender"));
setGroupInvitationTemplate(properties.getProperty("template.group.invitation"));
+ setEmailAddressRetrieval(properties.getProperty("mail.address.retrieval","test"));
}
}
@@ -269,4 +271,12 @@
this.groupInvitationTemplate = groupInvitationTemplate;
}
+ public String getEmailAddressRetrieval () {
+ return emailAddressRetrieval;
+ }
+
+ public void setEmailAddressRetrieval (String emailAddressRetrieval) {
+ this.emailAddressRetrieval = emailAddressRetrieval;
+ }
+
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/MailService.java b/full/src/main/java/de/ids_mannheim/korap/service/MailService.java
index 866a0a9..5051815 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/MailService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/MailService.java
@@ -42,7 +42,8 @@
public void prepare (MimeMessage mimeMessage) throws Exception {
- User invitee = authManager.getUser(inviteeName);
+ User invitee = authManager.getUser(inviteeName,
+ config.getEmailAddressRetrieval());
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(new InternetAddress(invitee.getEmail()));
diff --git a/full/src/main/resources/kustvakt.conf b/full/src/main/resources/kustvakt.conf
index d737a06..ab20bad 100644
--- a/full/src/main/resources/kustvakt.conf
+++ b/full/src/main/resources/kustvakt.conf
@@ -18,6 +18,7 @@
mail.enabled = false
mail.receiver = test@localhost
mail.sender = noreply@ids-mannheim.de
+mail.address.retrieval = test
## mail.templates
template.group.invitation = notification.vm
diff --git a/full/src/test/resources/kustvakt-test.conf b/full/src/test/resources/kustvakt-test.conf
index ca6b233..1de6cb1 100644
--- a/full/src/test/resources/kustvakt-test.conf
+++ b/full/src/test/resources/kustvakt-test.conf
@@ -18,6 +18,7 @@
mail.enabled = false
mail.receiver = test@localhost
mail.sender = noreply@ids-mannheim.de
+mail.address.retrieval = test
## mail.templates
template.group.invitation = notification.vm