forked from community/device-mgt-core
commit
61073f0a4b
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.common;
|
||||||
|
|
||||||
|
|
||||||
|
public class EmailMessageProperties {
|
||||||
|
|
||||||
|
private String messageBody;
|
||||||
|
private String[] mailTo;
|
||||||
|
private String[] ccList;
|
||||||
|
private String[] bccList;
|
||||||
|
private String subject;
|
||||||
|
|
||||||
|
public String getMessageBody() {
|
||||||
|
return messageBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageBody(String messageBody) {
|
||||||
|
this.messageBody = messageBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getMailTo() {
|
||||||
|
return mailTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMailTo(String[] mailTo) {
|
||||||
|
this.mailTo = mailTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getCcList() {
|
||||||
|
return ccList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCcList(String[] ccList) {
|
||||||
|
this.ccList = ccList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getBccList() {
|
||||||
|
return bccList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBccList(String[] bccList) {
|
||||||
|
this.bccList = bccList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubject() {
|
||||||
|
return subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubject(String subject) {
|
||||||
|
this.subject = subject;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.core;
|
||||||
|
|
||||||
|
import org.apache.axiom.om.OMAbstractFactory;
|
||||||
|
import org.apache.axiom.om.OMElement;
|
||||||
|
import org.apache.axis2.AxisFault;
|
||||||
|
import org.apache.axis2.Constants;
|
||||||
|
import org.apache.axis2.addressing.EndpointReference;
|
||||||
|
import org.apache.axis2.client.Options;
|
||||||
|
import org.apache.axis2.client.ServiceClient;
|
||||||
|
import org.apache.axis2.context.ConfigurationContext;
|
||||||
|
import org.apache.axis2.context.MessageContext;
|
||||||
|
import org.apache.axis2.transport.base.BaseConstants;
|
||||||
|
import org.apache.axis2.transport.mail.MailConstants;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EmailMessageProperties;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.EmailService;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class EmailServiceProviderImpl implements EmailService {
|
||||||
|
|
||||||
|
private static ThreadPoolExecutor threadPoolExecutor;
|
||||||
|
private static final int MIN_THREAD = 8;
|
||||||
|
private static final int MAX_THREAD = 100;
|
||||||
|
private static final long DEFAULT_KEEP_ALIVE_TIME = 20;
|
||||||
|
private static final String EMAIL_URI_SCHEME = "mailto:";
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(EmailServiceProviderImpl.class);
|
||||||
|
|
||||||
|
public EmailServiceProviderImpl() {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
if (threadPoolExecutor == null) {
|
||||||
|
threadPoolExecutor = new ThreadPoolExecutor(MIN_THREAD, MAX_THREAD, DEFAULT_KEEP_ALIVE_TIME,
|
||||||
|
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEmail(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
|
||||||
|
for(String toAddr:emailMessageProperties.getMailTo()) {
|
||||||
|
threadPoolExecutor
|
||||||
|
.submit(new EmailSender(toAddr, emailMessageProperties.getSubject(),
|
||||||
|
emailMessageProperties.getMessageBody()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EmailSender implements Runnable {
|
||||||
|
|
||||||
|
String to;
|
||||||
|
String subject;
|
||||||
|
String body;
|
||||||
|
|
||||||
|
EmailSender(String to, String subject, String body) {
|
||||||
|
this.to = to;
|
||||||
|
this.subject = subject;
|
||||||
|
this.body = body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
Map<String, String> headerMap = new HashMap<String, String>();
|
||||||
|
headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, subject);
|
||||||
|
OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(
|
||||||
|
BaseConstants.DEFAULT_TEXT_WRAPPER, null);
|
||||||
|
payload.setText(body);
|
||||||
|
try {
|
||||||
|
ServiceClient serviceClient;
|
||||||
|
ConfigurationContext configContext = EmailServiceDataHolder.getInstance()
|
||||||
|
.getConfigurationContextService().getClientConfigContext();
|
||||||
|
//Set configuration service client if available, else create new service client
|
||||||
|
if (configContext != null) {
|
||||||
|
serviceClient = new ServiceClient(configContext, null);
|
||||||
|
} else {
|
||||||
|
serviceClient = new ServiceClient();
|
||||||
|
}
|
||||||
|
Options options = new Options();
|
||||||
|
options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
|
||||||
|
options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
|
||||||
|
options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT,
|
||||||
|
MailConstants.TRANSPORT_FORMAT_TEXT);
|
||||||
|
options.setTo(new EndpointReference(EMAIL_URI_SCHEME + to));
|
||||||
|
serviceClient.setOptions(options);
|
||||||
|
serviceClient.fireAndForget(payload);
|
||||||
|
log.debug("Sending confirmation mail to " + to);
|
||||||
|
} catch (AxisFault e) {
|
||||||
|
String msg = "Error in delivering the message, " +
|
||||||
|
"subject: " + subject + ", to: " + to + ".";
|
||||||
|
log.error(msg);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
String msg = "Error in delivering the message, " +
|
||||||
|
"subject: " + subject + ", to: " + to + ".";
|
||||||
|
log.error(msg);
|
||||||
|
log.error(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.core.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
|
||||||
|
import org.wso2.carbon.device.mgt.core.EmailServiceProviderImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.EmailService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.EmailServiceImpl;
|
||||||
|
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component component.name="org.wso2.carbon.device.emailmanager" immediate="true"
|
||||||
|
* @scr.reference name="configurationcontext.service"
|
||||||
|
* interface="org.wso2.carbon.utils.ConfigurationContextService" cardinality="1..1"
|
||||||
|
* policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService"
|
||||||
|
*/
|
||||||
|
public class EmailServiceComponent {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(EmailServiceComponent.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize the email service here service here.
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
protected void activate(ComponentContext context) {
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initializing email service bundle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initializing Email Service Configurations */
|
||||||
|
|
||||||
|
EmailService emailServiceProvider = new EmailServiceProviderImpl();
|
||||||
|
EmailServiceDataHolder.getInstance().setEmailServiceProvider(emailServiceProvider); ;
|
||||||
|
|
||||||
|
this.registerServices(context);
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Email management core bundle has been successfully initialized");
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
String msg = "Error occurred while initializing device management core bundle";
|
||||||
|
log.error(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||||
|
EmailServiceDataHolder.getInstance().setConfigurationContextService(configurationContextService);
|
||||||
|
}
|
||||||
|
protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||||
|
EmailServiceDataHolder.getInstance().setConfigurationContextService(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerServices(ComponentContext componentContext) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Registering OSGi service Email Service Impl");
|
||||||
|
}
|
||||||
|
/* Registering Email Service */
|
||||||
|
BundleContext bundleContext = componentContext.getBundleContext();
|
||||||
|
bundleContext.registerService(EmailService.class.getName(),
|
||||||
|
new EmailServiceImpl(), null);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.core.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.EmailService;
|
||||||
|
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||||
|
|
||||||
|
public class EmailServiceDataHolder {
|
||||||
|
|
||||||
|
private static EmailServiceDataHolder thisInstance = new EmailServiceDataHolder();
|
||||||
|
private ConfigurationContextService configurationContextService;
|
||||||
|
private EmailService emailServiceProvider;
|
||||||
|
|
||||||
|
public static EmailServiceDataHolder getThisInstance() {
|
||||||
|
return thisInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setThisInstance(EmailServiceDataHolder thisInstance) {
|
||||||
|
EmailServiceDataHolder.thisInstance = thisInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private EmailServiceDataHolder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EmailServiceDataHolder getInstance() {
|
||||||
|
return thisInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationContextService getConfigurationContextService() {
|
||||||
|
return configurationContextService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||||
|
this.configurationContextService = configurationContextService;
|
||||||
|
}
|
||||||
|
public EmailService getEmailServiceProvider() {
|
||||||
|
return emailServiceProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmailServiceProvider(EmailService emailServiceProvider) {
|
||||||
|
this.emailServiceProvider = emailServiceProvider;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.core.service;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EmailMessageProperties;
|
||||||
|
|
||||||
|
public interface EmailService {
|
||||||
|
|
||||||
|
public void sendEmail(EmailMessageProperties emailMessageProperties) throws DeviceManagementException;
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.core.service;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EmailMessageProperties;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
|
||||||
|
|
||||||
|
public class EmailServiceImpl implements EmailService{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEmail(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
|
||||||
|
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ WSO2 Inc. 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>user-mgt</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.user.common</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<version>1.4.0</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||||
|
<Bundle-Description>Device Management User Common Bundle</Bundle-Description>
|
||||||
|
<Export-Package>
|
||||||
|
org.wso2.carbon.device.mgt.user.common.*
|
||||||
|
</Export-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.user.common;
|
||||||
|
|
||||||
|
public class Claims {
|
||||||
|
|
||||||
|
private String dialectUrl;
|
||||||
|
private String description;
|
||||||
|
private String claimUrl;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public String getDialectUrl() {
|
||||||
|
return dialectUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDialectUrl(String dialectUrl) {
|
||||||
|
this.dialectUrl = dialectUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClaimUrl() {
|
||||||
|
return claimUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClaimUrl(String claimUrl) {
|
||||||
|
this.claimUrl = claimUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.user.common;
|
||||||
|
|
||||||
|
public class Role {
|
||||||
|
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
public Role(String roleName) {
|
||||||
|
this.roleName = roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoleName() {
|
||||||
|
return roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleName(String roleName) {
|
||||||
|
this.roleName = roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.user.common;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private String userName;
|
||||||
|
private String roleName;
|
||||||
|
private ArrayList<Claims> claimList;
|
||||||
|
|
||||||
|
public User(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User(String userName, String roleName) {
|
||||||
|
this.userName = userName;
|
||||||
|
this.roleName = roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoleName() {
|
||||||
|
return roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleName(String roleName) {
|
||||||
|
this.roleName = roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Claims> getClaimList() {
|
||||||
|
return claimList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClaimList(ArrayList<Claims> claimList) {
|
||||||
|
this.claimList = claimList;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.user.common;
|
||||||
|
|
||||||
|
public class UserManagementException extends Exception{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -312678248574816874L;
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserManagementException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserManagementException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
setErrorMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserManagementException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserManagementException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserManagementException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ WSO2 Inc. 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.
|
||||||
|
-->
|
||||||
|
<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/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>user-mgt</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.user.core</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<name>WSO2 Carbon - Device Management user core</name>
|
||||||
|
<description>WSO2 Carbon - Device Management user core</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-scr-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<version>1.4.0</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||||
|
<Bundle-Description>Device Management Core User Bundle</Bundle-Description>
|
||||||
|
<Private-Package>org.wso2.carbon.device.mgt.user.core.internal</Private-Package>
|
||||||
|
<Import-Package>
|
||||||
|
org.wso2.carbon.device.mgt.user.common.*,
|
||||||
|
org.wso2.carbon.user.core.*,
|
||||||
|
org.apache.commons.logging.*,
|
||||||
|
org.osgi.framework.*,
|
||||||
|
org.osgi.service.component.*,
|
||||||
|
org.wso2.carbon.user.api.*
|
||||||
|
</Import-Package>
|
||||||
|
<Export-Package>
|
||||||
|
!org.wso2.carbon.device.mgt.user.core.internal,
|
||||||
|
org.wso2.carbon.device.mgt.user.core.*
|
||||||
|
</Export-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.user.common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.user.core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.osgi</groupId>
|
||||||
|
<artifactId>org.eclipse.osgi</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.user.core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.user.api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.base</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.user.core;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.user.common.Role;
|
||||||
|
import org.wso2.carbon.device.mgt.user.common.User;
|
||||||
|
import org.wso2.carbon.device.mgt.user.common.UserManagementException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface UserManager {
|
||||||
|
public List<User> getUsersForTenantAndRole(int tenantId, String roleName) throws UserManagementException;
|
||||||
|
public List<Role> getRolesForTenant(int tenantId) throws UserManagementException;
|
||||||
|
public List<User> getUsersForTenant(int tenantId) throws UserManagementException;
|
||||||
|
}
|
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.user.core;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.user.common.Claims;
|
||||||
|
import org.wso2.carbon.device.mgt.user.common.Role;
|
||||||
|
import org.wso2.carbon.device.mgt.user.common.User;
|
||||||
|
import org.wso2.carbon.device.mgt.user.common.UserManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.user.core.internal.DeviceMgtUserDataHolder;
|
||||||
|
import org.wso2.carbon.user.api.Claim;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserManagerImpl implements UserManager {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(UserManagerImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> getUsersForTenantAndRole(int tenantId, String roleName) throws UserManagementException {
|
||||||
|
|
||||||
|
UserStoreManager userStoreManager;
|
||||||
|
String[] userNames;
|
||||||
|
ArrayList usersList = new ArrayList();
|
||||||
|
|
||||||
|
try {
|
||||||
|
userStoreManager = DeviceMgtUserDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
||||||
|
.getUserStoreManager();
|
||||||
|
|
||||||
|
userNames = userStoreManager.getUserListOfRole(roleName);
|
||||||
|
User newUser;
|
||||||
|
for (String userName : userNames) {
|
||||||
|
newUser = new User(userName);
|
||||||
|
setUserClaims(newUser, userStoreManager.getUserClaimValues(userName, null));
|
||||||
|
usersList.add(newUser);
|
||||||
|
}
|
||||||
|
} catch (UserStoreException userStoreEx) {
|
||||||
|
String errorMsg = "User store error in fetching user list for role and tenant tenant id:" + tenantId
|
||||||
|
+ " role name:" + roleName;
|
||||||
|
log.error(errorMsg, userStoreEx);
|
||||||
|
throw new UserManagementException(errorMsg, userStoreEx);
|
||||||
|
}
|
||||||
|
return usersList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Role> getRolesForTenant(int tenantId) throws UserManagementException {
|
||||||
|
|
||||||
|
String[] roleNames;
|
||||||
|
ArrayList<Role> rolesList = new ArrayList<Role>();
|
||||||
|
Role newRole;
|
||||||
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtUserDataHolder.getInstance().getRealmService()
|
||||||
|
.getTenantUserRealm(tenantId)
|
||||||
|
.getUserStoreManager();
|
||||||
|
|
||||||
|
roleNames = userStoreManager.getRoleNames();
|
||||||
|
for (String roleName : roleNames) {
|
||||||
|
newRole = new Role(roleName);
|
||||||
|
rolesList.add(newRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (UserStoreException userStoreEx) {
|
||||||
|
String errorMsg = "User store error in fetching user list for role and tenant tenant id:" + tenantId;
|
||||||
|
log.error(errorMsg, userStoreEx);
|
||||||
|
throw new UserManagementException(errorMsg, userStoreEx);
|
||||||
|
}
|
||||||
|
return rolesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> getUsersForTenant(int tenantId) throws UserManagementException {
|
||||||
|
|
||||||
|
UserStoreManager userStoreManager;
|
||||||
|
String[] userNames;
|
||||||
|
ArrayList usersList = new ArrayList();
|
||||||
|
|
||||||
|
try {
|
||||||
|
userStoreManager = DeviceMgtUserDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
||||||
|
.getUserStoreManager();
|
||||||
|
|
||||||
|
userNames = userStoreManager.listUsers("",-1);
|
||||||
|
User newUser;
|
||||||
|
for (String userName : userNames) {
|
||||||
|
newUser = new User(userName);
|
||||||
|
setUserClaims(newUser, userStoreManager.getUserClaimValues(userName, null));
|
||||||
|
usersList.add(newUser);
|
||||||
|
}
|
||||||
|
} catch (UserStoreException userStoreEx) {
|
||||||
|
String errorMsg = "User store error in fetching user list for tenant id:" + tenantId;
|
||||||
|
log.error(errorMsg, userStoreEx);
|
||||||
|
throw new UserManagementException(errorMsg, userStoreEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
return usersList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUserClaims(User newUser, Claim[] userClaimValues) {
|
||||||
|
|
||||||
|
Claims userClaims;
|
||||||
|
ArrayList<Claims> claimsList = new ArrayList<Claims>();
|
||||||
|
for (Claim claim : userClaimValues) {
|
||||||
|
userClaims = new Claims();
|
||||||
|
userClaims.setClaimUrl(claim.getClaimUri());
|
||||||
|
userClaims.setDescription(claim.getDescription());
|
||||||
|
userClaims.setDialectUrl(claim.getDialectURI());
|
||||||
|
userClaims.setValue(claim.getValue());
|
||||||
|
claimsList.add(userClaims);
|
||||||
|
}
|
||||||
|
newUser.setClaimList(claimsList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.user.core.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.user.core.UserManager;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
import org.wso2.carbon.user.core.tenant.TenantManager;
|
||||||
|
|
||||||
|
public class DeviceMgtUserDataHolder {
|
||||||
|
|
||||||
|
private RealmService realmService;
|
||||||
|
private TenantManager tenantManager;
|
||||||
|
private static DeviceMgtUserDataHolder thisInstance = new DeviceMgtUserDataHolder();
|
||||||
|
private UserManager userManager;
|
||||||
|
|
||||||
|
private DeviceMgtUserDataHolder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeviceMgtUserDataHolder getInstance() {
|
||||||
|
return thisInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RealmService getRealmService() {
|
||||||
|
return realmService;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTenantManager(RealmService realmService) {
|
||||||
|
if (realmService == null) {
|
||||||
|
throw new IllegalStateException("Realm service is not initialized properly");
|
||||||
|
}
|
||||||
|
this.tenantManager = realmService.getTenantManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRealmService(RealmService realmService) {
|
||||||
|
this.realmService = realmService;
|
||||||
|
this.setTenantManager(realmService);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TenantManager getTenantManager() {
|
||||||
|
return tenantManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserManager getUserManager() {
|
||||||
|
return userManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserManager(UserManager userManager) {
|
||||||
|
this.userManager = userManager;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.user.core.internal;
|
||||||
|
|
||||||
|
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.wso2.carbon.device.mgt.user.core.UserManager;
|
||||||
|
import org.wso2.carbon.device.mgt.user.core.UserManagerImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.user.core.service.UserManagementService;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.device.usermanager" immediate="true"
|
||||||
|
* @scr.reference name="user.realmservice.default"
|
||||||
|
* interface="org.wso2.carbon.user.core.service.RealmService"
|
||||||
|
* cardinality="1..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setRealmService"
|
||||||
|
* unbind="unsetRealmService"
|
||||||
|
*/
|
||||||
|
public class DeviceMgtUserServiceComponent {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(DeviceMgtUserServiceComponent.class);
|
||||||
|
|
||||||
|
protected void activate(ComponentContext componentContext) {
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initializing user management core bundle");
|
||||||
|
}
|
||||||
|
|
||||||
|
UserManager userMgr = new UserManagerImpl();
|
||||||
|
DeviceMgtUserDataHolder.getInstance().setUserManager(userMgr);
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Registering OSGi service User Management Service");
|
||||||
|
}
|
||||||
|
/* Registering User Management service */
|
||||||
|
BundleContext bundleContext = componentContext.getBundleContext();
|
||||||
|
bundleContext.registerService(UserManagementService.class.getName(),
|
||||||
|
new UserManagementService(), null);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User management core bundle has been successfully initialized");
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
String msg = "Error occurred while initializing user management core bundle";
|
||||||
|
log.error(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Sets Realm Service.
|
||||||
|
*
|
||||||
|
* @param realmService An instance of RealmService
|
||||||
|
*/
|
||||||
|
protected void setRealmService(RealmService realmService) {
|
||||||
|
DeviceMgtUserDataHolder.getInstance().setRealmService(realmService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Un sets Realm Service.
|
||||||
|
*
|
||||||
|
* @param realmService An instance of RealmService
|
||||||
|
*/
|
||||||
|
protected void unsetRealmService(RealmService realmService) {
|
||||||
|
DeviceMgtUserDataHolder.getInstance().setRealmService(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. 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.wso2.carbon.device.mgt.user.core.service;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.user.common.Role;
|
||||||
|
import org.wso2.carbon.device.mgt.user.common.User;
|
||||||
|
import org.wso2.carbon.device.mgt.user.common.UserManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.user.core.UserManager;
|
||||||
|
import org.wso2.carbon.device.mgt.user.core.internal.DeviceMgtUserDataHolder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserManagementService implements UserManager{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> getUsersForTenantAndRole(int tenantId, String roleName) throws UserManagementException {
|
||||||
|
return DeviceMgtUserDataHolder.getInstance().getUserManager().getUsersForTenantAndRole(tenantId, roleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Role> getRolesForTenant(int tenantId) throws UserManagementException {
|
||||||
|
return DeviceMgtUserDataHolder.getInstance().getUserManager().getRolesForTenant(tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> getUsersForTenant(int tenantId) throws UserManagementException {
|
||||||
|
return DeviceMgtUserDataHolder.getInstance().getUserManager().getUsersForTenant(tenantId);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ WSO2 Inc. 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.
|
||||||
|
-->
|
||||||
|
<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/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>user-mgt</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<name>WSO2 Carbon - Device Management User Component</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>org.wso2.carbon.device.mgt.user.common</module>
|
||||||
|
<module>org.wso2.carbon.device.mgt.user.core</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-scr-plugin</artifactId>
|
||||||
|
<version>1.7.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>generate-scr-scrdescriptor</id>
|
||||||
|
<goals>
|
||||||
|
<goal>scr</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,117 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ /*
|
||||||
|
~ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~ *
|
||||||
|
~ * WSO2 Inc. 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.
|
||||||
|
~ *
|
||||||
|
~ */
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>user-mgt-feature</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.devicemgt.user.server.feature</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<name>WSO2 Carbon - User Management Server Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
<description>This feature contains the core bundles required for Back-end Device Management User
|
||||||
|
related functionality
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.user.core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.user.common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-resources</id>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>src/main/resources</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>build.properties</include>
|
||||||
|
<include>p2.inf</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.wso2.maven</groupId>
|
||||||
|
<artifactId>carbon-p2-plugin</artifactId>
|
||||||
|
<version>${carbon.p2.plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>p2-feature-generation</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>p2-feature-gen</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<id>org.wso2.carbon.devicemgt.user.server</id>
|
||||||
|
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||||
|
<adviceFile>
|
||||||
|
<properties>
|
||||||
|
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||||
|
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||||
|
</properties>
|
||||||
|
</adviceFile>
|
||||||
|
<bundles>
|
||||||
|
<bundleDef>org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.user.core:${carbon.device.mgt.version}
|
||||||
|
</bundleDef>
|
||||||
|
<bundleDef>org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.user.common:${carbon.device.mgt.version}
|
||||||
|
</bundleDef>
|
||||||
|
</bundles>
|
||||||
|
<importFeatures>
|
||||||
|
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
|
||||||
|
</importFeatures>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1 @@
|
|||||||
|
custom = true
|
@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ /*
|
||||||
|
~ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~ *
|
||||||
|
~ * WSO2 Inc. 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.
|
||||||
|
~ *
|
||||||
|
~ */
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>user-mgt-feature</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>WSO2 Carbon - User Management Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>org.wso2.carbon.devicemgt.user.server.feature</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
</project>
|
Loading…
Reference in new issue