Commit 11a2ce08 authored by michael.simon's avatar michael.simon
Browse files

Try to get hostname to e-mail templates

In order to craft specific links to the same url, the user is visiting
right now.
parent 91862af0
......@@ -21,14 +21,21 @@ public class AbstractEvent<E extends Serializable> implements Event<E> {
private E entity;
private AuditEntryEntity audit;
private String serverName;
public AbstractEvent(E entity, AuditEntryEntity audit) {
public AbstractEvent(E entity, AuditEntryEntity audit, String serverName) {
this.entity = entity;
this.audit = audit;
this.serverName = serverName;
}
public AbstractEvent(E entity, AuditEntryEntity audit) {
this(entity, audit, null);
}
public AbstractEvent(E entity) {
this(entity, null);
this(entity, null, null);
}
public E getEntity() {
......@@ -38,4 +45,12 @@ public class AbstractEvent<E extends Serializable> implements Event<E> {
public AuditEntryEntity getAudit() {
return audit;
}
public String getServerName() {
return serverName;
}
public void setServerName(String serverName) {
this.serverName = serverName;
}
}
......@@ -49,13 +49,14 @@ public class SshPubKeyRegistrySendMailExecutor extends
TemplateMailService templateMailService = (TemplateMailService) ic.lookup("global/bwreg/bwreg-service/TemplateMailServiceImpl!edu.kit.scc.webreg.service.mail.TemplateMailService");
SshPubKeyRegistryEntity sshPubKeyRegistry = getEvent().getEntity();
Map<String, Object> context = new HashMap<String, Object>(3);
Map<String, Object> context = new HashMap<String, Object>();
context.put("sshPubKeyRegistry", sshPubKeyRegistry);
context.put("sshPubKey", sshPubKeyRegistry.getSshPubKey());
context.put("registry", sshPubKeyRegistry.getRegistry());
context.put("service", sshPubKeyRegistry.getRegistry().getService());
context.put("user", sshPubKeyRegistry.getSshPubKey().getUser());
context.put("user", sshPubKeyRegistry.getSshPubKey().getIdentity().getPrefUser());
context.put("identity", sshPubKeyRegistry.getSshPubKey().getIdentity());
context.put("serverName", getEvent().getServerName());
templateMailService.sendMail(templateName, context, true);
......
......@@ -49,10 +49,11 @@ public class SshPubKeySendMailExecutor extends
TemplateMailService templateMailService = (TemplateMailService) ic.lookup("global/bwreg/bwreg-service/TemplateMailServiceImpl!edu.kit.scc.webreg.service.mail.TemplateMailService");
SshPubKeyEntity sshPubKey = getEvent().getEntity();
Map<String, Object> context = new HashMap<String, Object>(3);
Map<String, Object> context = new HashMap<String, Object>();
context.put("sshPubKey", sshPubKey);
context.put("user", sshPubKey.getUser());
context.put("user", sshPubKey.getIdentity().getPrefUser());
context.put("identity", sshPubKey.getIdentity());
context.put("serverName", getEvent().getServerName());
templateMailService.sendMail(templateName, context, true);
......
......@@ -16,6 +16,7 @@ import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
......@@ -52,6 +53,9 @@ public class SshPubKeyRegistryServiceImpl extends BaseServiceImpl<SshPubKeyRegis
@Inject
private EventSubmitter eventSubmitter;
@Inject
private HttpServletRequest request;
@Override
public List<SshPubKeyRegistryEntity> findByUserAndService(Long userId, Long serviceId) {
return dao.findByUserAndService(userId, serviceId);
......@@ -72,6 +76,7 @@ public class SshPubKeyRegistryServiceImpl extends BaseServiceImpl<SshPubKeyRegis
entity = dao.persist(entity);
SshPubKeyRegistryEvent event = new SshPubKeyRegistryEvent(entity);
event.setServerName(request.getServerName());
try {
if (entity.getKeyStatus().equals(SshPubKeyRegistryStatus.PENDING)) {
eventSubmitter.submit(event, EventType.SSH_KEY_REGISTRY_APPROVAL, executor);
......@@ -135,6 +140,7 @@ public class SshPubKeyRegistryServiceImpl extends BaseServiceImpl<SshPubKeyRegis
dao.delete(entity);
SshPubKeyRegistryEvent event = new SshPubKeyRegistryEvent(entity);
event.setServerName(request.getServerName());
try {
eventSubmitter.submit(event, EventType.SSH_KEY_REGISTRY_DELETED, executor);
......
......@@ -15,6 +15,7 @@ import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
......@@ -49,6 +50,9 @@ public class SshPubKeyServiceImpl extends BaseServiceImpl<SshPubKeyEntity, Long>
@Inject
private EventSubmitter eventSubmitter;
@Inject
private HttpServletRequest request;
@Override
public List<SshPubKeyEntity> findByIdentity(Long identityId) {
return dao.findByIdentity(identityId);
......@@ -138,6 +142,7 @@ public class SshPubKeyServiceImpl extends BaseServiceImpl<SshPubKeyEntity, Long>
sshPubKeyRegistryDao.delete(regKey);
logger.debug("Deleting registry connection {} for key {}", regKey.getId(), entity.getId());
SshPubKeyRegistryEvent event = new SshPubKeyRegistryEvent(regKey);
event.setServerName(request.getServerName());
try {
eventSubmitter.submit(event, EventType.SSH_KEY_REGISTRY_DELETED, executor);
} catch (EventSubmitException e) {
......@@ -163,6 +168,7 @@ public class SshPubKeyServiceImpl extends BaseServiceImpl<SshPubKeyEntity, Long>
throw new SshPubKeyBlacklistedException("Key already used by user");
}
SshPubKeyEvent event = new SshPubKeyEvent(entity);
event.setServerName(request.getServerName());
try {
eventSubmitter.submit(event, EventType.SSH_KEY_DEPLOYED, executor);
} catch (EventSubmitException e) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment