Author: [email protected]
Date: Tue Nov 22 14:45:55 2011
New Revision: 1745
Log:
Added:
sandbox/ivol/amdatu-gadget-container/gadget-container-release/src/main/resources/config/org.amdatu.gadgetcontainer.mail.service.cfg
sandbox/ivol/amdatu-gadget-container/mail-service/
sandbox/ivol/amdatu-gadget-container/mail-service/pom.xml
sandbox/ivol/amdatu-gadget-container/mail-service/src/
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/EMailService.java
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/osgi/
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/osgi/Activator.java
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/service/
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/service/EMailServiceImpl.java
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/TenantAccountService.java
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/TenantListener.java
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantAccountServiceImpl.java
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantListenerImpl.java
Removed:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/EMailService.java
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/EMailServiceImpl.java
Modified:
sandbox/ivol/amdatu-gadget-container/gadget-container-release/pom.xml
sandbox/ivol/amdatu-gadget-container/pom.xml
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/pom.xml
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
Modified: sandbox/ivol/amdatu-gadget-container/gadget-container-release/pom.xml
==============================================================================
--- sandbox/ivol/amdatu-gadget-container/gadget-container-release/pom.xml
(original)
+++ sandbox/ivol/amdatu-gadget-container/gadget-container-release/pom.xml
Tue Nov 22 14:45:55 2011
@@ -257,11 +257,13 @@
<dependency>
<groupId>org.amdatu.auth</groupId>
<artifactId>org.amdatu.auth.login.gadget</artifactId>
+ <version>0.2.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.amdatu.auth</groupId>
<artifactId>org.amdatu.auth.login.service</artifactId>
+ <version>0.2.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Added:
sandbox/ivol/amdatu-gadget-container/gadget-container-release/src/main/resources/config/org.amdatu.gadgetcontainer.mail.service.cfg
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-gadget-container/gadget-container-release/src/main/resources/config/org.amdatu.gadgetcontainer.mail.service.cfg
Tue Nov 22 14:45:55 2011
@@ -0,0 +1,17 @@
+# The SMTP server
+smtp.server=smtp.gx.nl
+
+# The SMTP server port
+smtp.port=21
+
+# Authorization mechanism of the SMTP server
+smtp.auth=
+
+# Username required to send emails
+smtp.username=
+
+# Password of that user
+smtp.password=
+
+# The email address on who's behalf the mail is send
[email protected]
\ No newline at end of file
Added: sandbox/ivol/amdatu-gadget-container/mail-service/pom.xml
==============================================================================
--- (empty file)
+++ sandbox/ivol/amdatu-gadget-container/mail-service/pom.xml Tue Nov 22
14:45:55 2011
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2010, 2011 The Amdatu Foundation
+
+ Licensed 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.verning permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.amdatu.gadgetcontainer</groupId>
+ <artifactId>org.amdatu.gadgetcontainer</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>org.amdatu.gadgetcontainer.mail.service</artifactId>
+ <packaging>bundle</packaging>
+ <name>Amdatu Gadget Container - EMail service</name>
+ <description>Provides an E-Mail service</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>1.4.4</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+
<Bundle-Activator>org.amdatu.gadgetcontainer.email.osgi.Activator</Bundle-Activator>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+
<Embed-Dependency>*;scope=compile;artifactId=json|mail|org.amdatu.libraries.utilities</Embed-Dependency>
+ <Embed-Transitive>false</Embed-Transitive>
+ <Export-Package>org.amdatu.gadgetcontainer.email</Export-Package>
+ <Import-Package>*;resolution:=optional</Import-Package>
+
+ <!--
+ !sun.security.util,
+ !javax.microedition.io,
+ !org.apache.coyote.*,
+ !org.apache.tomcat.*,
+ !org.apache.tools.ant.*,
+ !org.apache.xalan.*,
+ !org.apache.xml.utils,
+ !org.apache.xpath.*,
+ *
+ -->
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <!-- Profile that will copy the jar to the configured
amdatu.deploy.directory when
+ the deploy profile is activated -->
+ <id>deploy</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
Added:
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/EMailService.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/EMailService.java
Tue Nov 22 14:45:55 2011
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.gadgetcontainer.email;
+
+
+public interface EMailService {
+ /**
+ * Validates if the specified email address is a valid mail address.
+ * @param email The email address to validate
+ * @return true if the address is valid, false otherwise.
+ */
+ boolean validateEmailAddress(String email);
+
+ void send(String[] to, String subject, String HtmlMessage);
+}
Added:
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/osgi/Activator.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/osgi/Activator.java
Tue Nov 22 14:45:55 2011
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.gadgetcontainer.email.osgi;
+
+import org.amdatu.gadgetcontainer.email.EMailService;
+import org.amdatu.gadgetcontainer.email.service.EMailServiceImpl;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * This is the OSGi activator for this gadget bundle.
+ *
+ * @author ivol
+ */
+public class Activator extends DependencyActivatorBase {
+ // The PID of the configuration of this service
+ public static final String PID = "org.amdatu.gadgetcontainer.mail.service";
+
+ @Override
+ public void init(BundleContext context, DependencyManager manager) throws
Exception {
+ // Create and register the EMail service
+ manager.add(createComponent()
+ .setInterface(EMailService.class.getName(), null)
+ .setImplementation(EMailServiceImpl.class)
+ .add(createConfigurationDependency().setPid(PID))
+
.add(createServiceDependency().setService(LogService.class).setRequired(true)));
+ }
+
+ @Override
+ public void destroy(final BundleContext arg0, final DependencyManager
arg1) throws Exception {
+ }
+}
Added:
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/service/EMailServiceImpl.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/service/EMailServiceImpl.java
Tue Nov 22 14:45:55 2011
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.gadgetcontainer.email.service;
+
+import java.util.Dictionary;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
+import org.amdatu.gadgetcontainer.email.EMailService;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.log.LogService;
+
+public class EMailServiceImpl implements EMailService, ManagedService {
+ // Regular expression that a valid email address must match
+ private final static Pattern VALID_EMAIL_ADDRESS =
Pattern.compile(".+@.+\\.[a-z]+");
+
+ // Java mail Properties
+ private final static String HOST = "mail.smtp.host";
+ private final static String PORT = "mail.smtp.port";
+ private final static String AUTH = "mail.smtp.auth";
+ private final static String USERNAME = "mail.smtp.username";
+ private final static String PASSWORD = "mail.smtp.password";
+
+ // Injected service dependencies
+ private volatile LogService m_logService;
+
+ // Configuration settings, managed by Config Admin
+ private Properties m_properties;
+ private String m_username;
+ private String m_password;
+
+ private String m_fromAddress = "[email protected]";
+
+ @SuppressWarnings("rawtypes")
+ public void updated(Dictionary properties) throws ConfigurationException {
+ if (properties != null) {
+ m_properties = new Properties();
+ m_properties.setProperty(HOST, properties.get(HOST).toString());
+ if (!properties.get(PORT).toString().isEmpty()) {
+ m_properties.setProperty(PORT,
properties.get(PORT).toString());
+ } else {
+ m_properties.remove(PORT);
+ }
+ m_properties.setProperty(AUTH, properties.get(AUTH).toString());
+
+ m_username = properties.get(USERNAME).toString();
+ m_password = properties.get(PASSWORD).toString();
+
+ m_fromAddress = properties.get("from.address").toString();
+ }
+ }
+
+ public boolean validateEmailAddress(String email) {
+ if (email == null || email.isEmpty()) {
+ return true;
+ }
+ Matcher m = VALID_EMAIL_ADDRESS.matcher(email);
+ return m.matches();
+ }
+
+ public void send(String[] to, String subject, String HtmlMessage) {
+ Transport transport = null;
+ try {
+ Session mailSession = Session.getDefaultInstance(m_properties);
+ transport = mailSession.getTransport("smtp");
+ MimeMessage message = prepareMessage(mailSession, "ISO-8859-2",
m_fromAddress, subject, HtmlMessage, to);
+ transport.connect();
+ Transport.send(message);
+ }
+ catch (MessagingException e) {
+ m_logService.log(LogService.LOG_ERROR, "Failed to send mail to " +
to, e);
+ }
+ finally {
+ try {
+ transport.close();
+ }
+ catch (MessagingException e) {
+ m_logService.log(LogService.LOG_ERROR, "Failed to send mail to
" + to, e);
+ }
+ }
+ }
+
+ private MimeMessage prepareMessage(Session mailSession, String charset,
+ String from, String subject,
+ String HtmlMessage, String[] recipient) {
+ // Multipurpose Internet Mail Extensions
+ MimeMessage message = null;
+ try {
+ message = new MimeMessage(mailSession);
+ message.setFrom(new InternetAddress(from));
+ message.setSubject(subject);
+ for (int i = 0; i < recipient.length; i++) {
+ message.addRecipient(Message.RecipientType.TO, new
InternetAddress(recipient[i]));
+ }
+ message.setContent(HtmlMessage, "text/plain; charset=\"" + charset
+ "\"");
+ }
+ catch (Exception e) {
+ m_logService.log(LogService.LOG_ERROR, "Failed to send mail", e);
+ }
+ return message;
+ }
+}
Modified: sandbox/ivol/amdatu-gadget-container/pom.xml
==============================================================================
--- sandbox/ivol/amdatu-gadget-container/pom.xml (original)
+++ sandbox/ivol/amdatu-gadget-container/pom.xml Tue Nov 22 14:45:55 2011
@@ -423,11 +423,17 @@
<artifactId>org.amdatu.gadgetcontainer.tenant.service</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.amdatu.gadgetcontainer</groupId>
+ <artifactId>org.amdatu.gadgetcontainer.mail.service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>gadget-container-release</module>
+ <module>mail-service</module>
<module>tenant-management-gadget</module>
<module>tenant-management-service</module>
</modules>
Modified: sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/pom.xml
==============================================================================
--- sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/pom.xml
(original)
+++ sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/pom.xml
Tue Nov 22 14:45:55 2011
@@ -57,6 +57,10 @@
<groupId>org.amdatu.gadgetcontainer</groupId>
<artifactId>org.amdatu.gadgetcontainer.tenant.service</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.amdatu.gadgetcontainer</groupId>
+ <artifactId>org.amdatu.gadgetcontainer.mail.service</artifactId>
+ </dependency>
<dependency>
<groupId>org.amdatu.libraries</groupId>
<artifactId>org.amdatu.libraries.utilities</artifactId>
@@ -75,6 +79,13 @@
<type>bundle</type>
</dependency>
<dependency>
+ <groupId>org.amdatu.auth</groupId>
+ <artifactId>org.amdatu.auth.login.service</artifactId>
+ <version>0.2.2-SNAPSHOT</version>
+ <scope>provided</scope>
+ <type>bundle</type>
+ </dependency>
+ <dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
@@ -91,6 +102,12 @@
<version>1.4.4</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.4</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<build>
@@ -102,7 +119,7 @@
<instructions>
<Bundle-Activator>org.amdatu.opensocial.tenant.gadget.osgi.Activator</Bundle-Activator>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
-
<Embed-Dependency>*;scope=compile;artifactId=json|mail|org.amdatu.libraries.utilities</Embed-Dependency>
+
<Embed-Dependency>*;scope=compile;artifactId=json|mail|org.amdatu.libraries.utilities|commons-codec</Embed-Dependency>
<Embed-Transitive>false</Embed-Transitive>
<Import-Package>*;resolution:=optional</Import-Package>
Added:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/TenantAccountService.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/TenantAccountService.java
Tue Nov 22 14:45:55 2011
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.opensocial.tenant.gadget;
+
+import org.amdatu.opensocial.tenant.gadget.service.TenantBean;
+
+public interface TenantAccountService {
+ void createAccount(TenantBean tenant, String emailAddress);
+}
Added:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/TenantListener.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/TenantListener.java
Tue Nov 22 14:45:55 2011
@@ -0,0 +1,5 @@
+package org.amdatu.opensocial.tenant.gadget;
+
+public interface TenantListener {
+ void addToQueue(String id, String name, String host, String email);
+}
Modified:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java
==============================================================================
---
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java
(original)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java
Tue Nov 22 14:45:55 2011
@@ -19,14 +19,17 @@
import java.util.Hashtable;
import org.amdatu.core.tenant.Tenant;
+import org.amdatu.gadgetcontainer.email.EMailService;
import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
import org.amdatu.opensocial.gadgetmanagement.GadgetDefinitionProvider;
-import org.amdatu.opensocial.tenant.gadget.service.EMailService;
-import org.amdatu.opensocial.tenant.gadget.service.EMailServiceImpl;
+import org.amdatu.opensocial.tenant.gadget.TenantAccountService;
+import org.amdatu.opensocial.tenant.gadget.TenantListener;
+import org.amdatu.opensocial.tenant.gadget.service.TenantAccountServiceImpl;
import org.amdatu.opensocial.tenant.gadget.service.TenantConfigDAO;
import org.amdatu.opensocial.tenant.gadget.service.TenantConfigDAOImpl;
import org.amdatu.opensocial.tenant.gadget.service.TenantGadgetDefinition;
import org.amdatu.opensocial.tenant.gadget.service.TenantGadgetImpl;
+import org.amdatu.opensocial.tenant.gadget.service.TenantListenerImpl;
import org.amdatu.opensocial.tenant.gadget.service.TenantRESTServiceImpl;
import org.amdatu.web.dispatcher.DispatcherService;
import org.amdatu.web.httpcontext.ResourceProvider;
@@ -87,12 +90,7 @@
manager.add(createAdapterService(Tenant.class, null)
.setInterface(GadgetDefinitionProvider.class.getName(), null)
.setImplementation(TenantGadgetDefinition.class));
-
- // Create and register the EMail service
- manager.add(createComponent()
- .setInterface(EMailService.class.getName(), null)
- .setImplementation(EMailServiceImpl.class));
-
+
// Create and register the TenantConfigDAO service
manager.add(
createComponent()
@@ -100,6 +98,23 @@
.setImplementation(TenantConfigDAOImpl.class)
.add(createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true)));
+ // Create and register the tenant account service
+ manager.add(
+ createComponent()
+ .setInterface(new String[] {
TenantAccountService.class.getName() }, null)
+ .setImplementation(TenantAccountServiceImpl.class)
+
.add(createServiceDependency().setService(EMailService.class).setRequired(true)));
+
+ // Create and register the tenant listener service
+ manager.add(
+ createComponent()
+ .setInterface(new String[] { TenantListener.class.getName() },
null)
+ .setImplementation(TenantListenerImpl.class)
+
.add(createServiceDependency().setService(EMailService.class).setRequired(true))
+ .add(
+
createServiceDependency().setService(UserAdmin.class).setCallbacks("userAdminAdded",
+ "userAdminRemoved")));
+
// Create and register the REST tenant service
manager.add(
createAdapterService(Tenant.class, null)
@@ -107,6 +122,7 @@
.setImplementation(TenantRESTServiceImpl.class)
.add(createServiceDependency().setService(LogService.class).setRequired(true))
.add(createServiceDependency().setService(EMailService.class).setRequired(true))
+
.add(createServiceDependency().setService(TenantListener.class).setRequired(true))
.add(createServiceDependency().setService(TenantConfigDAO.class).setRequired(true)));
}
Added:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantAccountServiceImpl.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantAccountServiceImpl.java
Tue Nov 22 14:45:55 2011
@@ -0,0 +1,26 @@
+package org.amdatu.opensocial.tenant.gadget.service;
+
+import org.amdatu.gadgetcontainer.email.EMailService;
+import org.amdatu.opensocial.tenant.gadget.TenantAccountService;
+
+public class TenantAccountServiceImpl implements TenantAccountService {
+ // End of line separator
+ private final static String EOL = System.getProperty("line.separator");
+
+ // Injected service dependencies
+ private volatile EMailService m_mailService;
+
+ public void createAccount(TenantBean tenant, String emailAddress) {
+ String subject = "Amdatu tenant created";
+ String content = "A new tenant has been created wih the following
properties:" + EOL;
+ content += " Tenant id: " + tenant.getId() + EOL;
+ content += " Tenant name: " + tenant.getName() + EOL;
+ content += " Tenant hostname: " + tenant.getHostname() + EOL + EOL;
+ content += "A default Administrator account has been created for you
with the following credentials:" + EOL;
+ content += " Username: admin" + EOL;
+ content += " Password: amdatu" + EOL + EOL;
+ content += "You will be asked to change your password the first time
you login.";
+
+ m_mailService.send(new String[]{emailAddress}, subject, content);
+ }
+}
Added:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantListenerImpl.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantListenerImpl.java
Tue Nov 22 14:45:55 2011
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed 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.amdatu.opensocial.tenant.gadget.service;
+
+import static
org.amdatu.auth.login.service.LoginService.PASSWORD_CREDENTIAL_KEY;
+import static org.amdatu.auth.login.service.LoginService.TENANT_CREDENTIAL_KEY;
+import static
org.amdatu.auth.login.service.LoginService.CHANGE_PASSWORD_UPON_FIRST_LOGIN;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.amdatu.core.tenant.Tenant;
+import org.amdatu.gadgetcontainer.email.EMailService;
+import org.amdatu.opensocial.tenant.gadget.TenantListener;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+import org.osgi.service.useradmin.UserAdmin;
+
+/**
+ * Tenants are created asynchronously. This means that if a tenant is added,
it is not
+ * immediately available but it may take some time. In our case we need to do
some stuff
+ * (like creating admin account) on the new tenant after it has come
available. This stuff
+ * is handled by this class.
+ * @author ivol
+ *
+ */
+public class TenantListenerImpl implements TenantListener {
+ // End of line separator
+ private final static String EOL = System.getProperty("line.separator");
+
+ // Injected service dependencies
+ private volatile EMailService m_mailService;
+
+ // Tenants in the queue to handle
+ private List<TenantQueueItem> m_tenantQueue = new
ArrayList<TenantQueueItem>();
+
+ // Default Administrator credentials
+ private static final String DEFAULT_USERNAME = "Administrator";
+ private static final String DEFAULT_ADMIN_GROUP = "Administrators";
+
+ public void addToQueue(String id, String name, String host, String email) {
+ TenantQueueItem tenant = new TenantQueueItem(id, name, host, email);
+ m_tenantQueue.add(tenant);
+ }
+
+ /**
+ * Note that instead of listening to new tenant coming available we listen
to UserAdmin
+ * (which is tenant aware). We need UserAdmin to create the new admin
account for, availability
+ * of the Tenant service is not enough.
+ * @param userAdmin
+ */
+ @SuppressWarnings("unchecked")
+ public void userAdminAdded(ServiceReference serviceReference, Object
userAdminObj) {
+ // Verify that the tenant associated with this UserAdmin service is in
our 'to be handled' queue
+ Object tenantId =
serviceReference.getProperty(Tenant.TENANT_ID_SERVICEPROPERTY);
+ if (tenantId != null) {
+ for (TenantQueueItem tenant : m_tenantQueue) {
+ if (tenant.getId().equals(tenantId.toString())) {
+ // This tenant is in our queue. We now create a new
account for it
+ // in the UserAdmin of this tenant
+ if (userAdminObj instanceof UserAdmin) {
+ UserAdmin userAdmin = (UserAdmin) userAdminObj;
+
+ // Create Admin user with generated password
+ String password = generatePassword();
+ User adminUser = (User)
userAdmin.createRole(DEFAULT_USERNAME, Role.USER);
+ if (adminUser == null) {
+ // This should never happen, an admin user exists
already for a newly created tenant.
+ // But if this happens then we send an email about
the new tenant and the notice
+ // that an admin account is already available for
it
+ sendMail(tenant);
+ } else {
+
adminUser.getCredentials().put(PASSWORD_CREDENTIAL_KEY, password);
+
adminUser.getCredentials().put(TENANT_CREDENTIAL_KEY, tenant.getId());
+
adminUser.getProperties().put(CHANGE_PASSWORD_UPON_FIRST_LOGIN, "true");
+
+ // Add the user to a new Administrators group
+ Group adminGroup = (Group)
userAdmin.createRole(DEFAULT_ADMIN_GROUP, Role.GROUP);
+ adminGroup.addMember(adminUser);
+
+ // Now send an email to the specified email
address with the username and generated password
+ sendMail(tenant, password);
+ }
+
+ }
+ }
+ }
+ }
+ }
+
+ public void userAdminRemoved(UserAdmin userAdmin) {
+
+ }
+
+ private String generatePassword() {
+ return DigestUtils.md5Hex(new Long(System.nanoTime()).toString());
+ }
+
+ private void sendMail(TenantQueueItem tenant) {
+ String subject = "Amdatu tenant created";
+ String content = "A new tenant has been created for you with the
following properties:" + EOL;
+ content += " Tenant id: " + tenant.getId() + EOL;
+ content += " Tenant name: " + tenant.getName() + EOL;
+ content += " Tenant hostname: " + tenant.getHost() + EOL + EOL;
+ content += "An Administrator account was already available for this
new tenant and has not been chnaged." + EOL;
+ content += "The dashboard to this new application can be reached on
this URL: " + EOL;
+ content += "http://" + tenant.getHost() +
":2204/dashboard/jsp/dashboard.jsp";
+
+ m_mailService.send(new String[]{tenant.getEmail()}, subject, content);
+ }
+
+ private void sendMail(TenantQueueItem tenant, String password) {
+ String subject = "Amdatu tenant created";
+ String content = "A new tenant has been created for you with the
following properties:" + EOL;
+ content += " Tenant id: " + tenant.getId() + EOL;
+ content += " Tenant name: " + tenant.getName() + EOL;
+ content += " Tenant hostname: " + tenant.getHost() + EOL + EOL;
+ content += "A default Administrator account has been created for you
with the following credentials:" + EOL;
+ content += " Username: " + DEFAULT_USERNAME + EOL;
+ content += " Password: " + password + EOL + EOL;
+ content += "The dashboard to this new application can be reached on
this URL: " + EOL;
+ content += "http://" + tenant.getHost() +
":2204/dashboard/jsp/dashboard.jsp" + EOL + EOL;
+ content += "You will be asked to change your password the first time
you login.";
+
+ m_mailService.send(new String[]{tenant.getEmail()}, subject, content);
+ }
+}
+
+class TenantQueueItem {
+ private String m_id, m_name, m_host, m_email;
+
+ TenantQueueItem(String id, String name, String host, String email) {
+ m_id = id;
+ m_name = name;
+ m_host = host;
+ m_email = email;
+ }
+
+ public String getId() {
+ return m_id;
+ }
+
+ public String getName() {
+ return m_name;
+ }
+
+ public String getHost() {
+ return m_host;
+ }
+
+ public String getEmail() {
+ return m_email;
+ }
+}
Modified:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
==============================================================================
---
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
(original)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
Tue Nov 22 14:45:55 2011
@@ -36,7 +36,9 @@
import javax.ws.rs.core.Response.Status;
import org.amdatu.core.tenant.Tenant;
+import org.amdatu.gadgetcontainer.email.EMailService;
import org.amdatu.libraries.utilities.rest.AtomSyndicationLink;
+import org.amdatu.opensocial.tenant.gadget.TenantListener;
import org.amdatu.web.rest.jaxrs.RESTService;
import org.osgi.service.log.LogService;
@@ -59,7 +61,8 @@
private volatile Tenant m_tenant;
private volatile TenantConfigDAO m_tenantDAO;
private volatile EMailService m_mailService;
-
+ private volatile TenantListener m_tenantListener;
+
public void start() {
m_logService.log(LogService.LOG_INFO, "Tenant management REST service
started");
}
@@ -136,19 +139,9 @@
return
Response.status(Status.BAD_REQUEST).cacheControl(NO_CACHE_CONTROL).build();
}
if (m_tenantDAO.setTenant(id, name, hostname)) {
- // Create an account and send it to the specified email address
- String subject = "A new tenant has been created";
- String content = "A new tenant has been created wih the
following properties : \r\n";
- content += "Tenant id: " + id + "\r\n";
- content += "Tenant name: " + name + "\r\n";
- content += "Tenant hostname: " + hostname + "\r\n";
- content += "\r\n";
- content += "A default Administrator account has been created
for you with the following credentials:\r\n";
- content += "Username: admin\r\n";
- content += "Password: amdatu\r\n";
- content += "You will be asked to change your password the
first time you login.\r\n";
-
- m_mailService.send(email, subject, content);
+ // Add the created tenant to the listener service, such that
an account
+ // is created and send to the email address as soon as the
tenant is created
+ m_tenantListener.addToQueue(id, name, hostname, email);
}
}
catch (Exception e) {
@@ -160,9 +153,9 @@
}
private boolean validate(String id, String hostname, String email) throws
IOException {
- boolean valid = validateHostname(hostname);
+ boolean valid = true;//validateHostname(hostname);
valid &= validateHostnameInUse(id, hostname);
- valid &= validateEmail(email);
+ valid &= m_mailService.validateEmailAddress(email);
return valid;
}
@@ -188,15 +181,6 @@
return true;
}
- private boolean validateEmail(String email) {
- if (email == null || email.isEmpty()) {
- return true;
- }
- Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
- Matcher m = p.matcher(email);
- return m.matches();
- }
-
/**
* Deletes an existing tenant.
* Example: DELETE /rest/tenants/default_tenant
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits