mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
3cb68355b4
@ -62,6 +62,7 @@
|
||||
org.bouncycastle.asn1,
|
||||
org.bouncycastle.asn1.x500,
|
||||
org.bouncycastle.asn1.x509,
|
||||
org.bouncycastle.asn1.pkcs,
|
||||
org.bouncycastle.cert,
|
||||
org.bouncycastle.cert.jcajce,
|
||||
org.bouncycastle.cms,
|
||||
|
||||
@ -20,6 +20,7 @@ package org.wso2.carbon.certificate.mgt.core.impl;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.bouncycastle.asn1.pkcs.Attribute;
|
||||
import org.bouncycastle.asn1.x500.X500Name;
|
||||
import org.bouncycastle.asn1.x509.KeyUsage;
|
||||
import org.bouncycastle.asn1.x509.X509Extension;
|
||||
@ -344,6 +345,7 @@ public class CertificateGenerator {
|
||||
Date validityEndDate = commonUtil.getValidityEndDate();
|
||||
|
||||
X500Name certSubject = request.getSubject();
|
||||
Attribute attributes[] = request.getAttributes();
|
||||
|
||||
if (certSubject == null) {
|
||||
certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL);
|
||||
|
||||
@ -42,6 +42,7 @@ import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.core.config.tenant.TenantConfigurationManagementServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
@ -117,6 +118,7 @@ public class DeviceManagementServiceComponent {
|
||||
|
||||
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
|
||||
DeviceManagementDAOFactory.init(dsConfig);
|
||||
NotificationManagementDAOFactory.init(dsConfig);
|
||||
|
||||
/*Initialize Operation Manager*/
|
||||
this.initOperationsManager();
|
||||
|
||||
@ -42,11 +42,10 @@ public class NotificationDAOImpl implements NotificationDAO {
|
||||
public int addNotification(int deviceId, int tenantId, Notification notification) throws
|
||||
NotificationManagementException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs;
|
||||
int notificationId = -1;
|
||||
try {
|
||||
NotificationManagementDAOFactory.beginTransaction();
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql =
|
||||
"INSERT INTO DM_NOTIFICATION(DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION, TENANT_ID) " +
|
||||
@ -62,14 +61,12 @@ public class NotificationDAOImpl implements NotificationDAO {
|
||||
if (rs.next()) {
|
||||
notificationId = rs.getInt(1);
|
||||
}
|
||||
NotificationManagementDAOFactory.commitTransaction();
|
||||
} catch (Exception e) {
|
||||
NotificationManagementDAOFactory.rollbackTransaction();
|
||||
throw new NotificationManagementException("Error occurred while adding the " +
|
||||
"Notification for device id : " + deviceId,
|
||||
e);
|
||||
} finally {
|
||||
NotificationManagementDAOFactory.closeConnection();
|
||||
NotificationDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return notificationId;
|
||||
}
|
||||
@ -78,10 +75,9 @@ public class NotificationDAOImpl implements NotificationDAO {
|
||||
public int updateNotification(Notification notification)
|
||||
throws NotificationManagementException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt;
|
||||
PreparedStatement stmt = null;
|
||||
int rows;
|
||||
try {
|
||||
NotificationManagementDAOFactory.beginTransaction();
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql = "UPDATE DM_NOTIFICATION SET OPERATION_ID = ?, STATUS = ?, DESCRIPTION = ? " +
|
||||
"WHERE NOTIFICATION_ID = ?";
|
||||
@ -91,13 +87,11 @@ public class NotificationDAOImpl implements NotificationDAO {
|
||||
stmt.setString(3, notification.getDescription());
|
||||
stmt.setInt(4, notification.getNotificationId());
|
||||
rows = stmt.executeUpdate();
|
||||
NotificationManagementDAOFactory.commitTransaction();
|
||||
} catch (Exception e) {
|
||||
NotificationManagementDAOFactory.rollbackTransaction();
|
||||
throw new NotificationManagementException("Error occurred while updating the " +
|
||||
"Notification id : " + notification.getNotificationId(), e);
|
||||
} finally {
|
||||
NotificationManagementDAOFactory.closeConnection();
|
||||
NotificationDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
@ -106,23 +100,20 @@ public class NotificationDAOImpl implements NotificationDAO {
|
||||
public int updateNotificationStatus(int notificationId, Notification.Status status)
|
||||
throws NotificationManagementException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt;
|
||||
PreparedStatement stmt = null;
|
||||
int rows;
|
||||
try {
|
||||
NotificationManagementDAOFactory.beginTransaction();
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql = "UPDATE DM_NOTIFICATION SET STATUS = ? WHERE NOTIFICATION_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, status.toString());
|
||||
stmt.setInt(2, notificationId);
|
||||
rows = stmt.executeUpdate();
|
||||
NotificationManagementDAOFactory.commitTransaction();
|
||||
} catch (Exception e) {
|
||||
NotificationManagementDAOFactory.rollbackTransaction();
|
||||
throw new NotificationManagementException("Error occurred while updating the status of " +
|
||||
"Notification id : " + notificationId, e);
|
||||
} finally {
|
||||
NotificationManagementDAOFactory.closeConnection();
|
||||
NotificationDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.app.mgt;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import java.io.File;
|
||||
|
||||
public class AppManagementConfigurationManagerTest {
|
||||
|
||||
private static final Log log = LogFactory.getLog(AppManagementConfigurationManagerTest.class);
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_ENABLED =
|
||||
"./src/test/resources/config/malformed-app-management-config-no-enabled.xml";
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_CLIENT_KEY =
|
||||
"./src/test/resources/config/malformed-app-management-config-no-client-key-secret.xml";
|
||||
private static final String TEST_CONFIG_SCHEMA_LOCATION =
|
||||
"./src/test/resources/config/schema/app-mgt-config-schema.xsd";
|
||||
|
||||
private Schema schema;
|
||||
|
||||
@BeforeClass
|
||||
private void initSchema() {
|
||||
File deviceManagementSchemaConfig = new File(AppManagementConfigurationManagerTest.TEST_CONFIG_SCHEMA_LOCATION);
|
||||
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
try {
|
||||
schema = factory.newSchema(deviceManagementSchemaConfig);
|
||||
} catch (SAXException e) {
|
||||
Assert.fail("Invalid schema found", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testMandateEnabledElement() {
|
||||
File malformedConfig =
|
||||
new File(AppManagementConfigurationManagerTest.MALFORMED_TEST_CONFIG_LOCATION_NO_ENABLED);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testMandateClientKeySecretElement() {
|
||||
File malformedConfig =
|
||||
new File(AppManagementConfigurationManagerTest.MALFORMED_TEST_CONFIG_LOCATION_NO_CLIENT_KEY);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
private void validateMalformedConfig(File malformedConfig) {
|
||||
try {
|
||||
JAXBContext ctx = JAXBContext.newInstance(AppManagementConfig.class);
|
||||
Unmarshaller um = ctx.createUnmarshaller();
|
||||
um.setSchema(this.getSchema());
|
||||
um.unmarshal(malformedConfig);
|
||||
Assert.assertTrue(false);
|
||||
} catch (JAXBException e) {
|
||||
Throwable linkedException = e.getLinkedException();
|
||||
if (!(linkedException instanceof SAXParseException)) {
|
||||
log.error("Unexpected error occurred while unmarshalling app management config", e);
|
||||
Assert.assertTrue(false);
|
||||
}
|
||||
log.error("JAXB parser occurred while unmarsharlling app management config", e);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
private Schema getSchema() {
|
||||
return schema;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<AppManagementConfig>
|
||||
<Enabled>true</Enabled>
|
||||
<AppManagerUrl>http:/www.google.com</AppManagerUrl>
|
||||
</AppManagementConfig>
|
||||
@ -0,0 +1,24 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<AppManagementConfig>
|
||||
<AppManagerUrl>http:/www.google.com</AppManagerUrl>
|
||||
<ConsumerKey>ConsumerKey</ConsumerKey>
|
||||
<ConsumerSecret>ConsumerSecret</ConsumerSecret>
|
||||
</AppManagementConfig>
|
||||
@ -0,0 +1,31 @@
|
||||
<?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.
|
||||
-->
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
<xs:element name="AppManagementConfig">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="Enabled" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="AppManagerUrl" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="ConsumerKey" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="ConsumerSecret" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@ -28,6 +28,7 @@
|
||||
<class name="org.wso2.carbon.device.mgt.core.dao.DevicePersistTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.app.mgt.AppManagementConfigurationManagerTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.dao.ApplicationPersistenceTests"/>
|
||||
</classes>
|
||||
</test>
|
||||
|
||||
@ -30,4 +30,4 @@ public class ConfigurationServiceImpl implements ConfigurationService {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
#
|
||||
# Copyright 2009 WSO2, Inc. (http://wso2.com)
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#
|
||||
# This is the log4j configuration file used by WSO2 Carbon
|
||||
#
|
||||
# IMPORTANT : Please do not remove or change the names of any
|
||||
# of the Appenders defined here. The layout pattern & log file
|
||||
# can be changed using the WSO2 Carbon Management Console, and those
|
||||
# settings will override the settings in this file.
|
||||
#
|
||||
|
||||
log4j.rootLogger=DEBUG, STD_OUT
|
||||
|
||||
# Redirect log messages to console
|
||||
log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.STD_OUT.Target=System.out
|
||||
log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
||||
@ -0,0 +1,41 @@
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||
|
||||
<suite name="DeviceManagementCore">
|
||||
<parameter name="useDefaultListeners" value="false"/>
|
||||
|
||||
<test name="DAO Unit Tests" preserve-order="true">
|
||||
<classes>
|
||||
<class name="org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.dao.DevicePersistTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.app.mgt.AppManagementConfigurationManagerTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.dao.ApplicationPersistenceTests"/>
|
||||
</classes>
|
||||
</test>
|
||||
<test name="Service Unit Tests" preserve-order="true">
|
||||
<classes>
|
||||
<class name="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServiceTest"/>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
||||
@ -392,7 +392,7 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
|
||||
TENANT_ID INTEGER NOT NULL,
|
||||
STATUS VARCHAR(10) NULL,
|
||||
DESCRIPTION VARCHAR(100) NULL,
|
||||
PRIMARY KEY (ID),
|
||||
PRIMARY KEY (NOTIFICATION_ID),
|
||||
CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES
|
||||
|
||||
Loading…
Reference in New Issue
Block a user