You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by am...@apache.org on 2013/12/03 23:14:56 UTC
svn commit: r1547606 - in /airavata/trunk/modules/credential-store: ./
src/main/java/org/apache/airavata/credential/store/notifier/
src/main/java/org/apache/airavata/credential/store/notifier/impl/
Author: amilaj
Date: Tue Dec 3 22:14:55 2013
New Revision: 1547606
URL: http://svn.apache.org/r1547606
Log:
Adding preliminary files for email notifier in credential store
Added:
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/CredentialStoreNotifier.java
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/NotificationMessage.java
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotificationMessage.java
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotifier.java
airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotifierConfiguration.java
Modified:
airavata/trunk/modules/credential-store/pom.xml
Modified: airavata/trunk/modules/credential-store/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/pom.xml?rev=1547606&r1=1547605&r2=1547606&view=diff
==============================================================================
--- airavata/trunk/modules/credential-store/pom.xml (original)
+++ airavata/trunk/modules/credential-store/pom.xml Tue Dec 3 22:14:55 2013
@@ -105,6 +105,11 @@
<version>2.5</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-email</artifactId>
+ <version>1.3.2</version>
+ </dependency>
</dependencies>
<build>
<plugins>
Added: airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/CredentialStoreNotifier.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/CredentialStoreNotifier.java?rev=1547606&view=auto
==============================================================================
--- airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/CredentialStoreNotifier.java (added)
+++ airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/CredentialStoreNotifier.java Tue Dec 3 22:14:55 2013
@@ -0,0 +1,42 @@
+package org.apache.airavata.credential.store.notifier;/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import org.apache.airavata.credential.store.store.CredentialStoreException;
+
+/**
+ * This class is used to notify particular entity with expiring credentials.
+ * The default implementation uses email messages.
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 12/3/13
+ * Time: 4:17 PM
+ */
+public interface CredentialStoreNotifier {
+
+ /**
+ * The specific notifier implementation needs to implement following method.
+ * This method should actually deliver message to desired entity.
+ * @param message The actual message encapsulated
+ * @throws CredentialStoreException
+ */
+ void notifyMessage(NotificationMessage message) throws CredentialStoreException;
+
+}
Added: airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/NotificationMessage.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/NotificationMessage.java?rev=1547606&view=auto
==============================================================================
--- airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/NotificationMessage.java (added)
+++ airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/NotificationMessage.java Tue Dec 3 22:14:55 2013
@@ -0,0 +1,46 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.credential.store.notifier;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 12/3/13
+ * Time: 4:21 PM
+ */
+
+/**
+ * Encapsulates the notification message.
+ * Usually says particular credential is expiring and need to renew.
+ */
+public class NotificationMessage {
+
+ protected String message;
+
+ public NotificationMessage(String msg) {
+ this.message = msg;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+}
Added: airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotificationMessage.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotificationMessage.java?rev=1547606&view=auto
==============================================================================
--- airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotificationMessage.java (added)
+++ airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotificationMessage.java Tue Dec 3 22:14:55 2013
@@ -0,0 +1,58 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.credential.store.notifier.impl;
+
+import org.apache.airavata.credential.store.notifier.NotificationMessage;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 12/3/13
+ * Time: 5:01 PM
+ */
+
+public class EmailNotificationMessage extends NotificationMessage {
+
+ public EmailNotificationMessage(String subject, String senderEmail, String msg) {
+ super(msg);
+ this.subject = subject;
+ this.senderEmail = senderEmail;
+ }
+
+ private String subject;
+ private String senderEmail;
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public void setSubject(String subject) {
+ this.subject = subject;
+ }
+
+ public String getSenderEmail() {
+ return senderEmail;
+ }
+
+ public void setSenderEmail(String senderEmail) {
+ this.senderEmail = senderEmail;
+ }
+}
Added: airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotifier.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotifier.java?rev=1547606&view=auto
==============================================================================
--- airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotifier.java (added)
+++ airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotifier.java Tue Dec 3 22:14:55 2013
@@ -0,0 +1,71 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.credential.store.notifier.impl;
+
+import org.apache.airavata.credential.store.notifier.CredentialStoreNotifier;
+import org.apache.airavata.credential.store.notifier.NotificationMessage;
+import org.apache.airavata.credential.store.store.CredentialStoreException;
+import org.apache.commons.mail.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 12/3/13
+ * Time: 4:25 PM
+ */
+
+public class EmailNotifier implements CredentialStoreNotifier {
+
+ protected static Logger log = LoggerFactory.getLogger(EmailNotifier.class);
+
+ private EmailNotifierConfiguration emailNotifierConfiguration;
+
+ public EmailNotifier(EmailNotifierConfiguration notifierConfiguration) {
+ this.emailNotifierConfiguration = notifierConfiguration;
+ }
+
+ public void notifyMessage(NotificationMessage message) throws CredentialStoreException {
+ try {
+ Email email = new SimpleEmail();
+ email.setHostName(this.emailNotifierConfiguration.getEmailServer());
+ email.setSmtpPort(this.emailNotifierConfiguration.getEmailServerPort());
+ email.setAuthenticator(new DefaultAuthenticator(this.emailNotifierConfiguration.getEmailUserName(),
+ this.emailNotifierConfiguration.getEmailPassword()));
+ email.setSSLOnConnect(this.emailNotifierConfiguration.isSslConnect());
+ email.setFrom(this.emailNotifierConfiguration.getFromAddress());
+
+ EmailNotificationMessage emailMessage = (EmailNotificationMessage)message;
+
+ email.setSubject(emailMessage.getSubject());
+ email.setMsg(emailMessage.getMessage());
+ email.addTo(emailMessage.getSenderEmail());
+ email.send();
+
+ } catch (EmailException e) {
+ log.error("[CredentialStore]Error sending email notification message.");
+ throw new CredentialStoreException("Error sending email notification message", e);
+ }
+
+
+ }
+}
Added: airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotifierConfiguration.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotifierConfiguration.java?rev=1547606&view=auto
==============================================================================
--- airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotifierConfiguration.java (added)
+++ airavata/trunk/modules/credential-store/src/main/java/org/apache/airavata/credential/store/notifier/impl/EmailNotifierConfiguration.java Tue Dec 3 22:14:55 2013
@@ -0,0 +1,71 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.credential.store.notifier.impl;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 12/3/13
+ * Time: 5:06 PM
+ */
+
+public class EmailNotifierConfiguration {
+ private String emailServer;
+ private int emailServerPort;
+ private String emailUserName;
+ private String emailPassword;
+ private boolean sslConnect;
+ private String fromAddress;
+
+ public EmailNotifierConfiguration(String emailServer, int emailServerPort, String emailUserName,
+ String emailPassword, boolean sslConnect, String fromAddress) {
+ this.emailServer = emailServer;
+ this.emailServerPort = emailServerPort;
+ this.emailUserName = emailUserName;
+ this.emailPassword = emailPassword;
+ this.sslConnect = sslConnect;
+ this.fromAddress = fromAddress;
+ }
+
+ public String getEmailServer() {
+ return emailServer;
+ }
+
+ public int getEmailServerPort() {
+ return emailServerPort;
+ }
+
+ public String getEmailUserName() {
+ return emailUserName;
+ }
+
+ public String getEmailPassword() {
+ return emailPassword;
+ }
+
+ public boolean isSslConnect() {
+ return sslConnect;
+ }
+
+ public String getFromAddress() {
+ return fromAddress;
+ }
+}