Skip to content
Permalink
Browse files
JUDDI-861 done
  • Loading branch information
spyhunter99 committed Jan 29, 2015
1 parent e06b6c5 commit f367a947a7ae02a771358acc7e8c5d0826298b52
Showing 4 changed files with 118 additions and 10 deletions.
@@ -227,9 +227,10 @@ public void deletePublisher(DeletePublisher body)
new ValidatePublish(publisher).validateDeletePublisher(em, body);

List<String> entityKeyList = body.getPublisherId();
List<Publisher> deletedPubs = new ArrayList<Publisher>();
for (String entityKey : entityKeyList) {
Publisher obj = em.find(org.apache.juddi.model.Publisher.class, entityKey);

deletedPubs.add(obj);
//get an authtoken for this publisher so that we can get its registeredInfo
UDDISecurityImpl security = new UDDISecurityImpl();
AuthToken authToken = security.getAuthToken(entityKey);
@@ -277,6 +278,9 @@ public void deletePublisher(DeletePublisher body)
}

tx.commit();
for (Publisher p: deletedPubs){
USERFRIENDLYSMTPNotifier.notifyAccountDeleted(new TemporaryMailContainer(null, p, (Publisher) publisher));
}
long procTime = System.currentTimeMillis() - startTime;
serviceCounter.update(JUDDIQuery.DELETE_PUBLISHER,
QueryStatus.SUCCESS, procTime);
@@ -75,10 +75,12 @@ public class USERFRIENDLYSMTPNotifier extends SMTPNotifier {

public static void notifySubscriptionDeleted(TemporaryMailContainer container) {
try {
Publisher publisher=container.getPublisher();
Publisher publisher = container.getPublisher();
Publisher deletedBy = container.getDeletedBy();
Subscription obj = container.getObj();

String emailaddress = publisher.getEmailAddress();
if (emailaddress==null || emailaddress.trim().equals(""))
return;
Properties properties = new Properties();
Session session = null;
String mailPrefix = AppConfig.getConfiguration().getString(Property.JUDDI_EMAIL_PREFIX, Property.DEFAULT_JUDDI_EMAIL_PREFIX);
@@ -92,7 +94,7 @@ public static void notifySubscriptionDeleted(TemporaryMailContainer container) {
properties.put(key, System.getProperty(mailPrefix + key));
}
}
String emailaddress = publisher.getEmailAddress();

boolean auth = (properties.getProperty("mail.smtp.auth", "false")).equalsIgnoreCase("true");
if (auth) {
final String username = properties.getProperty("mail.smtp.user");
@@ -137,7 +139,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
Address[] to = {address};
message.setRecipients(RecipientType.TO, to);
message.setFrom(new InternetAddress(properties.getProperty("mail.smtp.from", "jUDDI")));
//Hello %s,<br><br>Your subscription UDDI subscription was deleted. Attached is what the subscription was. It was deleted by %s, %s at %s. This node is %s
//Hello %s,<br><br>Your subscription UDDI subscription was deleted. Attached is what the subscription was. It was deleted by %s, %s at %s. This node is %s
//maybe nice to use a template rather then sending raw xml.
org.uddi.sub_v3.Subscription api = new org.uddi.sub_v3.Subscription();
MappingModelToApi.mapSubscription(obj, api);
@@ -146,15 +148,17 @@ protected PasswordAuthentication getPasswordAuthentication() {

MimeBodyPart content = new MimeBodyPart();
String msg_content = ResourceConfig.getGlobalMessage("notifications.smtp.subscriptionDeleted");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ddTkk:mm:ssZ");
//Hello %s,<br><br>Your subscription UDDI subscription was deleted. Attached is what the subscription was. It was deleted by %s, %s at %s. This node is %s
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd kk:mm:ssZ");
//Hello %s, %s<br><br>Your subscription UDDI subscription was deleted. Attached is what the subscription was. It was deleted by %s, %s at %s. This node is %s.
msg_content = String.format(msg_content,
StringEscapeUtils.escapeHtml(publisher.getPublisherName()),
StringEscapeUtils.escapeHtml(publisher.getAuthorizedName()),
StringEscapeUtils.escapeHtml(deletedBy.getPublisherName()),
StringEscapeUtils.escapeHtml(deletedBy.getAuthorizedName()),
StringEscapeUtils.escapeHtml(sdf.format(new Date())),
StringEscapeUtils.escapeHtml(AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID, "(unknown node id!)"))
StringEscapeUtils.escapeHtml(AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID, "(unknown node id!)")),
AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL, "(unknown url)"),
AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL_SECURE, "(unknown url)")
);

content.setContent(msg_content, "text/html; charset=UTF-8;");
@@ -171,7 +175,103 @@ protected PasswordAuthentication getPasswordAuthentication() {
Transport.send(message);

} catch (Throwable t) {
log.error(t);
log.error("Error sending email!" + t.getMessage(), t);
}
}

public static void notifyAccountDeleted(TemporaryMailContainer container) {
try {
Publisher publisher = container.getPublisher();
Publisher deletedBy = container.getDeletedBy();
String emailaddress = publisher.getEmailAddress();
if (emailaddress==null || emailaddress.trim().equals(""))
return;
Properties properties = new Properties();
Session session = null;
String mailPrefix = AppConfig.getConfiguration().getString(Property.JUDDI_EMAIL_PREFIX, Property.DEFAULT_JUDDI_EMAIL_PREFIX);
if (!mailPrefix.endsWith(".")) {
mailPrefix = mailPrefix + ".";
}
for (String key : mailProps) {
if (AppConfig.getConfiguration().containsKey(mailPrefix + key)) {
properties.put(key, AppConfig.getConfiguration().getProperty(mailPrefix + key));
} else if (System.getProperty(mailPrefix + key) != null) {
properties.put(key, System.getProperty(mailPrefix + key));
}
}

boolean auth = (properties.getProperty("mail.smtp.auth", "false")).equalsIgnoreCase("true");
if (auth) {
final String username = properties.getProperty("mail.smtp.user");
String pwd = properties.getProperty("mail.smtp.password");
//decrypt if possible
if (properties.getProperty("mail.smtp.password" + Property.ENCRYPTED_ATTRIBUTE, "false").equalsIgnoreCase("true")) {
try {
pwd = CryptorFactory.getCryptor().decrypt(pwd);
} catch (NoSuchPaddingException ex) {
log.error("Unable to decrypt settings", ex);
} catch (NoSuchAlgorithmException ex) {
log.error("Unable to decrypt settings", ex);
} catch (InvalidAlgorithmParameterException ex) {
log.error("Unable to decrypt settings", ex);
} catch (InvalidKeyException ex) {
log.error("Unable to decrypt settings", ex);
} catch (IllegalBlockSizeException ex) {
log.error("Unable to decrypt settings", ex);
} catch (BadPaddingException ex) {
log.error("Unable to decrypt settings", ex);
}
}
final String password = pwd;
log.debug("SMTP username = " + username + " from address = " + emailaddress);
Properties eMailProperties = properties;
eMailProperties.remove("mail.smtp.user");
eMailProperties.remove("mail.smtp.password");
session = Session.getInstance(properties, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
} else {
Properties eMailProperties = properties;
eMailProperties.remove("mail.smtp.user");
eMailProperties.remove("mail.smtp.password");
session = Session.getInstance(eMailProperties);
}

MimeMessage message = new MimeMessage(session);
InternetAddress address = new InternetAddress(emailaddress);
Address[] to = {address};
message.setRecipients(RecipientType.TO, to);
message.setFrom(new InternetAddress(properties.getProperty("mail.smtp.from", "jUDDI")));
//Hello %s,<br><br>Your subscription UDDI subscription was deleted. Attached is what the subscription was. It was deleted by %s, %s at %s. This node is %s

Multipart mp = new MimeMultipart();

MimeBodyPart content = new MimeBodyPart();
String msg_content = ResourceConfig.getGlobalMessage("notifications.smtp.accountDeleted");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd kk:mm:ssZ");
//Hello %s, %s,<br><br>Your account has been deleted by %s, %s at %s. This node is %s.
msg_content = String.format(msg_content,
StringEscapeUtils.escapeHtml(publisher.getPublisherName()),
StringEscapeUtils.escapeHtml(publisher.getAuthorizedName()),
StringEscapeUtils.escapeHtml(deletedBy.getPublisherName()),
StringEscapeUtils.escapeHtml(deletedBy.getAuthorizedName()),
StringEscapeUtils.escapeHtml(sdf.format(new Date())),
StringEscapeUtils.escapeHtml(AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID, "(unknown node id!)")),
AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL, "(unknown url)"),
AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL_SECURE, "(unknown url)")
);

content.setContent(msg_content, "text/html; charset=UTF-8;");
mp.addBodyPart(content);

message.setContent(mp);
message.setSubject(ResourceConfig.getGlobalMessage("notifications.smtp.accountDeleted.subject"));
Transport.send(message);

} catch (Throwable t) {
log.error("Error sending email!" + t.getMessage(), t);
}
}

@@ -282,7 +282,9 @@ notifications.smtp.default.subject=UDDI Subscription Notification for subscripti

notifications.smtp.userfriendly.subject=UDDI Subscription Notification for subscription
notifications.smtp.userfriendly.body=Hello %s,<br><br>You are currently registered to receive subscription updates in the UDDI Node <b>%s</b> for %s. A change was registered that triggered an update notification to be sent. The attachment contains the XML containing the details of the change.<br><br><b>Summary of changes</b>: <br><br>%s
notifications.smtp.subscriptionDeleted=Hello %s,<br><br>Your subscription UDDI subscription was deleted. Attached is what the subscription was. It was deleted by %s, %s at %s. This node is %s
notifications.smtp.subscriptionDeleted=Hello %s, %s,<br><br>Your UDDI subscription was deleted. Attached is what the subscription was. It was deleted by %s, %s at %s. This node is %s.<br><br><a href="%s">Non-secure web site</a><br><a href="%s">Secure web site</a>
notifications.smtp.accountDeleted=Hello %s, %s,<br><br>Your account has been deleted by %s, %s at %s. This node is %s.<br><br><a href="%s">Non-secure web site</a><br><a href="%s">Secure web site</a>
notifications.smtp.accountDeleted.subject=UDDI Account Management
#username
#node
#search results or a specific item
@@ -24,6 +24,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.Duration;
@@ -169,6 +170,7 @@ service that implements notify_subscriptionListener (see below), or an email
"maxEntities",
"expiresAfter"
})
@XmlRootElement
public class Subscription implements Serializable{
@XmlTransient
private static final long serialVersionUID = -1016771256986173140L;

0 comments on commit f367a94

Please sign in to comment.