forked from community/device-mgt-plugins
commit
b702a72b2f
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the mapping between device and operations.
|
||||
*/
|
||||
public interface MobileDeviceOperationDAO {
|
||||
/**
|
||||
* Add a new mapping to plugin device_operation table.
|
||||
*
|
||||
* @param deviceOperation DeviceOperation object that holds data related to the DeviceOperation
|
||||
* to be inserted.
|
||||
* @return The status of the operation. If the insert was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean addMobileDeviceOperation(MobileDeviceOperation deviceOperation)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update a feature in the feature table.
|
||||
*
|
||||
* @param deviceOperation DeviceOperation object that holds data has to be updated.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileDeviceOperation(MobileDeviceOperation deviceOperation)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a given device operation from device operation table.
|
||||
*
|
||||
* @param deviceId Device id of the mapping to be deleted.
|
||||
* @param operationId Operation id of the mapping to be deleted.
|
||||
* @return The status of the operation. If the deletion was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteMobileDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a given device operation from plugin database.
|
||||
*
|
||||
* @param deviceId Device id of the mapping to be retrieved.
|
||||
* @param operationId Operation id of the mapping to be retrieved.
|
||||
* @return DeviceOperation object that holds data of the device operation mapping represented by
|
||||
* deviceId and operationId.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
MobileDeviceOperation getMobileDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve all the device operation mapping from plugin database.
|
||||
*
|
||||
* @return Device operation mapping object list.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
List<MobileDeviceOperation> getAllMobileDeviceOperationsOfDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the mapping between mobile device and operations.
|
||||
*/
|
||||
public interface MobileDeviceOperationMappingDAO {
|
||||
/**
|
||||
* Add a new mobile device operation mapping to the table.
|
||||
*
|
||||
* @param deviceOperation MobileDeviceOperation object that holds data related to the MobileDeviceOperation
|
||||
* to be inserted.
|
||||
* @return The status of the operation. If the insert was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean addMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Updates a mobile device operation mapping.
|
||||
*
|
||||
* @param deviceOperation MobileDeviceOperation object that holds data has to be updated.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Updates a mobile device operation mapping to In-Progress state.
|
||||
*
|
||||
* @param deviceId Device id of the mapping to be deleted.
|
||||
* @param operationId Operation id of the mapping to be deleted.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileDeviceOperationToInProgress(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Updates a mobile device operation mapping to completed state.
|
||||
*
|
||||
* @param deviceId Device id of the mapping to be deleted.
|
||||
* @param operationId Operation id of the mapping to be deleted.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileDeviceOperationToCompleted(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a given mobile device operation mapping from table.
|
||||
*
|
||||
* @param deviceId Device id of the mapping to be deleted.
|
||||
* @param operationId Operation id of the mapping to be deleted.
|
||||
* @return The status of the operation. If the deletion was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteMobileDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieves a given mobile device operation from the plugin database.
|
||||
*
|
||||
* @param deviceId Device id of the mapping to be retrieved.
|
||||
* @param operationId Operation id of the mapping to be retrieved.
|
||||
* @return MobileDeviceOperation object that holds data of the device operation mapping represented by
|
||||
* deviceId and operationId.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
MobileDeviceOperationMapping getMobileDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieves all the of mobile device operation mappings relavent to the given mobile device.
|
||||
*
|
||||
* @return Device operation mapping object list.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
List<MobileDeviceOperationMapping> getAllMobileDeviceOperationsOfDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieves all the pending device operation mappings of a mobiel device.
|
||||
*
|
||||
* @return Device operation mapping object list.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
List<MobileDeviceOperationMapping> getAllPendingOperationsOfMobileDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
}
|
@ -1,218 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of MobileDeviceOperationDAO.
|
||||
*/
|
||||
public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(MobileDeviceOperationDAOImpl.class);
|
||||
|
||||
public MobileDeviceOperationDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addMobileDeviceOperation(MobileDeviceOperation deviceOperation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO MBL_DEVICE_OPERATION(DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE) VALUES (?, ?, ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, deviceOperation.getDeviceId());
|
||||
stmt.setLong(2, deviceOperation.getOperationId());
|
||||
stmt.setLong(3, deviceOperation.getSentDate());
|
||||
stmt.setLong(4, deviceOperation.getReceivedDate());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding device id - '" +
|
||||
deviceOperation.getDeviceId() + " and operation id - " +
|
||||
deviceOperation.getOperationId() +
|
||||
" to mapping table MBL_DEVICE_OPERATION";
|
||||
;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileDeviceOperation(MobileDeviceOperation deviceOperation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE MBL_DEVICE_OPERATION SET SENT_DATE = ?, RECEIVED_DATE = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setLong(1, deviceOperation.getSentDate());
|
||||
stmt.setLong(2, deviceOperation.getReceivedDate());
|
||||
stmt.setString(3, deviceOperation.getDeviceId());
|
||||
stmt.setInt(4, deviceOperation.getOperationId());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating device id - '" +
|
||||
deviceOperation.getDeviceId() + " and operation id - " +
|
||||
deviceOperation.getOperationId() + " in table MBL_DEVICE_OPERATION";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteMobileDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
stmt.setInt(2, operationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while deleting the table entry MBL_DEVICE_OPERATION with device id - '" +
|
||||
deviceId + " and operation id - " + operationId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileDeviceOperation getMobileDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileDeviceOperation deviceOperation = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
stmt.setInt(2, operationId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
deviceOperation = new MobileDeviceOperation();
|
||||
deviceOperation.setDeviceId(resultSet.getString(1));
|
||||
deviceOperation.setOperationId(resultSet.getInt(2));
|
||||
deviceOperation.setSentDate(resultSet.getInt(3));
|
||||
deviceOperation.setReceivedDate(resultSet.getInt(4));
|
||||
break;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching table MBL_DEVICE_OPERATION entry with device id - '" +
|
||||
deviceId + " and operation id - " + operationId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return deviceOperation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileDeviceOperation> getAllMobileDeviceOperationsOfDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileDeviceOperation deviceOperation = null;
|
||||
List<MobileDeviceOperation> deviceOperations = new ArrayList<MobileDeviceOperation>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
deviceOperation = new MobileDeviceOperation();
|
||||
deviceOperation.setDeviceId(resultSet.getString(1));
|
||||
deviceOperation.setOperationId(resultSet.getInt(2));
|
||||
deviceOperation.setSentDate(resultSet.getInt(3));
|
||||
deviceOperation.setReceivedDate(resultSet.getInt(4));
|
||||
deviceOperations.add(deviceOperation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of device id - '" +
|
||||
deviceId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return deviceOperations;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||
"management metadata repository datasource.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,331 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationMappingDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of MobileDeviceOperationMappingDAO.
|
||||
*/
|
||||
public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperationMappingDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(MobileDeviceOperationMappingDAOImpl.class);
|
||||
|
||||
public MobileDeviceOperationMappingDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO MBL_DEVICE_OPERATION_MAPPING (DEVICE_ID, OPERATION_ID, SENT_DATE, " +
|
||||
"RECEIVED_DATE, STATUS) VALUES (?, ?, ?, ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, deviceOperation.getDeviceId());
|
||||
stmt.setLong(2, deviceOperation.getOperationId());
|
||||
stmt.setLong(3, deviceOperation.getSentDate());
|
||||
stmt.setLong(4, deviceOperation.getReceivedDate());
|
||||
stmt.setString(5, deviceOperation.getStatus().name());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding device id - '" +
|
||||
deviceOperation.getDeviceId() + " and operation id - " +
|
||||
deviceOperation.getOperationId() +
|
||||
" to mapping table MBL_DEVICE_OPERATION";
|
||||
;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, STATUS = ? " +
|
||||
"WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setLong(1, deviceOperation.getSentDate());
|
||||
stmt.setLong(2, deviceOperation.getReceivedDate());
|
||||
stmt.setString(3, deviceOperation.getStatus().name());
|
||||
stmt.setString(4, deviceOperation.getDeviceId());
|
||||
stmt.setInt(5, deviceOperation.getOperationId());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating device id - '" +
|
||||
deviceOperation.getDeviceId() + " and operation id - " +
|
||||
deviceOperation.getOperationId() + " in table MBL_DEVICE_OPERATION";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileDeviceOperationToInProgress(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, STATUS = ? " +
|
||||
"WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setLong(1, new Date().getTime());
|
||||
stmt.setString(2, MobileDeviceOperationMapping.Status.INPROGRESS.name());
|
||||
stmt.setString(3, deviceId);
|
||||
stmt.setInt(4, operationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while updating the Status of operation to in-progress of device id - '" +
|
||||
deviceId + " and operation id - " +
|
||||
operationId + " in table MBL_DEVICE_OPERATION";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileDeviceOperationToCompleted(String deviceId,
|
||||
int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE MBL_DEVICE_OPERATION_MAPPING SET RECEIVED_DATE = ?, STATUS = ? " +
|
||||
"WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setLong(1, new Date().getTime());
|
||||
stmt.setString(2, MobileDeviceOperationMapping.Status.COMPLETED.name());
|
||||
stmt.setString(3, deviceId);
|
||||
stmt.setInt(4, operationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while updating the Status of operation to completed of device id - '" +
|
||||
deviceId + " and operation id - " +
|
||||
operationId + " in table MBL_DEVICE_OPERATION";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteMobileDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
stmt.setInt(2, operationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while deleting the table entry MBL_DEVICE_OPERATION with " +
|
||||
" device id - '" + deviceId + " and operation id - " + operationId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileDeviceOperationMapping getMobileDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileDeviceOperationMapping mblDeviceOperation = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " +
|
||||
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
stmt.setInt(2, operationId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
mblDeviceOperation = new MobileDeviceOperationMapping();
|
||||
mblDeviceOperation.setDeviceId(resultSet.getString(1));
|
||||
mblDeviceOperation.setOperationId(resultSet.getInt(2));
|
||||
mblDeviceOperation.setSentDate(resultSet.getInt(3));
|
||||
mblDeviceOperation.setReceivedDate(resultSet.getInt(4));
|
||||
mblDeviceOperation.setStatus(resultSet.getString(5));
|
||||
break;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching table MBL_DEVICE_OPERATION entry with device id - '" +
|
||||
deviceId + " and operation id - " + operationId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return mblDeviceOperation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileDeviceOperationMapping> getAllMobileDeviceOperationsOfDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileDeviceOperationMapping mblDeviceOperation = null;
|
||||
List<MobileDeviceOperationMapping> mblDeviceOperations = new ArrayList<MobileDeviceOperationMapping>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " +
|
||||
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
mblDeviceOperation = new MobileDeviceOperationMapping();
|
||||
mblDeviceOperation.setDeviceId(resultSet.getString(1));
|
||||
mblDeviceOperation.setOperationId(resultSet.getInt(2));
|
||||
mblDeviceOperation.setSentDate(resultSet.getInt(3));
|
||||
mblDeviceOperation.setReceivedDate(resultSet.getInt(4));
|
||||
mblDeviceOperation.setStatus(resultSet.getString(5));
|
||||
mblDeviceOperations.add(mblDeviceOperation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of " +
|
||||
"device id - '" + deviceId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return mblDeviceOperations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileDeviceOperationMapping> getAllPendingOperationsOfMobileDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileDeviceOperationMapping mblDeviceOperation = null;
|
||||
List<MobileDeviceOperationMapping> mblDeviceOperations = new ArrayList<MobileDeviceOperationMapping>();
|
||||
try {
|
||||
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM" +
|
||||
" MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = 'NEW'";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
mblDeviceOperation = new MobileDeviceOperationMapping();
|
||||
mblDeviceOperation.setDeviceId(resultSet.getString(1));
|
||||
mblDeviceOperation.setOperationId(resultSet.getInt(2));
|
||||
mblDeviceOperation.setSentDate(resultSet.getInt(3));
|
||||
mblDeviceOperation.setReceivedDate(resultSet.getInt(4));
|
||||
mblDeviceOperation.setStatus(resultSet.getString(5));
|
||||
mblDeviceOperations.add(mblDeviceOperation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of" +
|
||||
" device id - '" + deviceId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return mblDeviceOperations;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||
"management metadata repository datasource.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
54
components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeaturePropertyDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java
54
components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeaturePropertyDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.impl;
|
||||
|
||||
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.mobile.config.MobileDeviceManagementConfig;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
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 MobileDeviceManagementConfigTests {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementConfigTests.class);
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY =
|
||||
"./src/test/resources/config/malformed-mobile-config-no-mgt-repo.xml";
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG =
|
||||
"./src/test/resources/config/malformed-mobile-config-no-ds-config.xml";
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG =
|
||||
"./src/test/resources/config/malformed-mobile-config-no-jndi-config.xml";
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG =
|
||||
"./src/test/resources/config/malformed-mobile-config-no-apis-config.xml";
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG =
|
||||
"./src/test/resources/config/malformed-mobile-config-no-api-config.xml";
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG =
|
||||
"./src/test/resources/config/malformed-mobile-config-no-api-publisher-config.xml";
|
||||
private static final String TEST_CONFIG_SCHEMA_LOCATION =
|
||||
"./src/test/resources/config/schema/MobileDeviceManagementConfigSchema.xsd";
|
||||
|
||||
private Schema schema;
|
||||
|
||||
@BeforeClass
|
||||
private void initSchema() {
|
||||
File deviceManagementSchemaConfig = new File(MobileDeviceManagementConfigTests.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 testMandateManagementRepositoryElement() {
|
||||
File malformedConfig =
|
||||
new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMandateDataSourceConfigurationElement() {
|
||||
File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMandateJndiLookupDefinitionElement() {
|
||||
File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMandateAPIPublisherElement() {
|
||||
File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMandateAPIsElement() {
|
||||
File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMandateAPIElement() {
|
||||
File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
private void validateMalformedConfig(File malformedConfig) {
|
||||
try {
|
||||
JAXBContext ctx = JAXBContext.newInstance(MobileDeviceManagementConfig.class);
|
||||
Unmarshaller um = ctx.createUnmarshaller();
|
||||
um.setSchema(this.getSchema());
|
||||
um.unmarshal(malformedConfig);
|
||||
Assert.assertTrue(false);
|
||||
} catch (JAXBException e) {
|
||||
log.error("Error occurred while unmarsharlling mobile device management config", e);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
private Schema getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TestUtils.class);
|
||||
|
||||
public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing result set", e);
|
||||
}
|
||||
}
|
||||
if (stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing prepared statement", e);
|
||||
}
|
||||
}
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing database connection", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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.mobile.impl.dao;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations;
|
||||
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.Statement;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class FeatureDAOTestSuite {
|
||||
|
||||
private TestDBConfiguration testDBConfiguration;
|
||||
private Connection conn = null;
|
||||
private Statement stmt = null;
|
||||
private MobileFeatureDAOImpl featureDAO;
|
||||
|
||||
@BeforeClass
|
||||
@Parameters("dbType")
|
||||
public void setUpDB(String dbTypeStr) throws Exception {
|
||||
|
||||
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||
testDBConfiguration = getTestDBConfiguration(dbType);
|
||||
|
||||
switch (dbType) {
|
||||
case H2:
|
||||
createH2DB(testDBConfiguration);
|
||||
BasicDataSource testDataSource = new BasicDataSource();
|
||||
testDataSource.setDriverClassName(testDBConfiguration.getDriverClass());
|
||||
testDataSource.setUrl(testDBConfiguration.getConnectionUrl());
|
||||
testDataSource.setUsername(testDBConfiguration.getUserName());
|
||||
testDataSource.setPassword(testDBConfiguration.getPwd());
|
||||
featureDAO = new MobileFeatureDAOImpl(testDataSource);
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws
|
||||
MobileDeviceManagementDAOException,
|
||||
DeviceManagementException {
|
||||
|
||||
File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml");
|
||||
Document doc = null;
|
||||
testDBConfiguration = null;
|
||||
TestDBConfigurations testDBConfigurations = null;
|
||||
|
||||
doc = MobileDeviceManagementUtil.convertToDocument(deviceMgtConfig);
|
||||
JAXBContext testDBContext = null;
|
||||
|
||||
try {
|
||||
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
|
||||
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
|
||||
testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc);
|
||||
} catch (JAXBException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e);
|
||||
}
|
||||
|
||||
Iterator<TestDBConfiguration> itrDBConfigs =
|
||||
testDBConfigurations.getDbTypesList().iterator();
|
||||
while (itrDBConfigs.hasNext()) {
|
||||
testDBConfiguration = itrDBConfigs.next();
|
||||
if (testDBConfiguration.getDbType().equals(dbType.toString())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return testDBConfiguration;
|
||||
}
|
||||
|
||||
private void createH2DB(TestDBConfiguration testDBConf) throws Exception {
|
||||
Class.forName(testDBConf.getDriverClass());
|
||||
conn = DriverManager.getConnection(testDBConf.getConnectionUrl());
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFeature() throws MobileDeviceManagementDAOException, DeviceManagementException {
|
||||
|
||||
MobileFeature mobileFeature = new MobileFeature();
|
||||
mobileFeature.setCode("Camera");
|
||||
mobileFeature.setDescription("Camera enable or disable");
|
||||
mobileFeature.setName("Camera");
|
||||
boolean added = featureDAO.addFeature(mobileFeature);
|
||||
// Long deviceId = null;
|
||||
// try {
|
||||
// conn = DeviceManagementDAOFactory.getDataSource().getConnection();
|
||||
// stmt = conn.createStatement();
|
||||
// ResultSet resultSet = stmt
|
||||
// .executeQuery("SELECT ID from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION='111'");
|
||||
//
|
||||
// while (resultSet.next()) {
|
||||
// deviceId = resultSet.getLong(1);
|
||||
// }
|
||||
// conn.close();
|
||||
// } catch (SQLException sqlEx) {
|
||||
// throw new DeviceManagementDAOException("error in fetch device by device identification id", sqlEx);
|
||||
// }
|
||||
|
||||
Assert.assertTrue(added, "Device Id is null");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||
|
||||
public class FeaturePropertyDAOTestSuite {
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||
|
||||
public class MobileDeviceDAOTestSuite {
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||
|
||||
public class MobileDeviceOperationDAOTestSuite {
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||
|
||||
public class MobileOperationDAOTestSuite {
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||
|
||||
public class MobileOperationPropertyDAOTestSuite {
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
/*
|
||||
* 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.mobile.impl.dao;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.impl.FeatureDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.*;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class FeatureDAOTestSuite {
|
||||
|
||||
private TestDBConfiguration testDBConfiguration;
|
||||
private Connection conn = null;
|
||||
private Statement stmt = null;
|
||||
private FeatureDAOImpl featureDAO;
|
||||
|
||||
@BeforeClass
|
||||
@Parameters("dbType")
|
||||
public void setUpDB(String dbTypeStr) throws Exception {
|
||||
|
||||
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||
testDBConfiguration = getTestDBConfiguration(dbType);
|
||||
|
||||
switch (dbType) {
|
||||
case H2:
|
||||
createH2DB(testDBConfiguration);
|
||||
BasicDataSource testDataSource = new BasicDataSource();
|
||||
testDataSource.setDriverClassName(testDBConfiguration.getDriverClass());
|
||||
testDataSource.setUrl(testDBConfiguration.getConnectionUrl());
|
||||
testDataSource.setUsername(testDBConfiguration.getUserName());
|
||||
testDataSource.setPassword(testDBConfiguration.getPwd());
|
||||
featureDAO = new FeatureDAOImpl(testDataSource);
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws
|
||||
MobileDeviceManagementDAOException,
|
||||
DeviceManagementException {
|
||||
|
||||
File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml");
|
||||
Document doc = null;
|
||||
testDBConfiguration = null;
|
||||
TestDBConfigurations testDBConfigurations = null;
|
||||
|
||||
doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
|
||||
JAXBContext testDBContext = null;
|
||||
|
||||
try {
|
||||
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
|
||||
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
|
||||
testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc);
|
||||
} catch (JAXBException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e);
|
||||
}
|
||||
|
||||
Iterator<TestDBConfiguration> itrDBConfigs = testDBConfigurations.getDbTypesList().iterator();
|
||||
while (itrDBConfigs.hasNext()) {
|
||||
testDBConfiguration = itrDBConfigs.next();
|
||||
if (testDBConfiguration.getDbType().equals(dbType.toString())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return testDBConfiguration;
|
||||
}
|
||||
|
||||
private void createH2DB(TestDBConfiguration testDBConf) throws Exception {
|
||||
|
||||
Class.forName(testDBConf.getDriverClass());
|
||||
conn = DriverManager.getConnection(testDBConf.getConnectionUrl());
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void addFeature() throws MobileDeviceManagementDAOException, DeviceManagementException {
|
||||
|
||||
|
||||
|
||||
Feature feature = new Feature();
|
||||
feature.setCode("Camera");
|
||||
feature.setDescription("Camera enable or disable");
|
||||
feature.setName("Camera");
|
||||
boolean added = featureDAO.addFeature(feature);
|
||||
// Long deviceId = null;
|
||||
// try {
|
||||
// conn = DeviceManagementDAOFactory.getDataSource().getConnection();
|
||||
// stmt = conn.createStatement();
|
||||
// ResultSet resultSet = stmt
|
||||
// .executeQuery("SELECT ID from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION='111'");
|
||||
//
|
||||
// while (resultSet.next()) {
|
||||
// deviceId = resultSet.getLong(1);
|
||||
// }
|
||||
// conn.close();
|
||||
// } catch (SQLException sqlEx) {
|
||||
// throw new DeviceManagementDAOException("error in fetch device by device identification id", sqlEx);
|
||||
// }
|
||||
|
||||
Assert.assertTrue(added, "Device Id is null");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<MobileDeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/MobileDM_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</ManagementRepository>
|
||||
|
||||
<APIPublisher>
|
||||
<APIs>
|
||||
<MalformedAPI>
|
||||
<Name>enrollment</Name>
|
||||
<Owner>admin</Owner>
|
||||
<Context>enrollment</Context>
|
||||
<Version>1.0.0</Version>
|
||||
<Endpoint>http://localhost:9763/</Endpoint>
|
||||
<Transports>http,https</Transports>
|
||||
</MalformedAPI>
|
||||
</APIs>
|
||||
</APIPublisher>
|
||||
</MobileDeviceMgtConfiguration>
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<MobileDeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/MobileDM_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</ManagementRepository>
|
||||
|
||||
<MalformedAPIPublisher>
|
||||
<APIs>
|
||||
<API>
|
||||
<Name>enrollment</Name>
|
||||
<Owner>admin</Owner>
|
||||
<Context>enrollment</Context>
|
||||
<Version>1.0.0</Version>
|
||||
<Endpoint>http://localhost:9763/</Endpoint>
|
||||
<Transports>http,https</Transports>
|
||||
</API>
|
||||
</APIs>
|
||||
</MalformedAPIPublisher>
|
||||
</MobileDeviceMgtConfiguration>
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<MobileDeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/MobileDM_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</ManagementRepository>
|
||||
|
||||
<APIPublisher>
|
||||
<MalformedAPIs>
|
||||
<API>
|
||||
<Name>enrollment</Name>
|
||||
<Owner>admin</Owner>
|
||||
<Context>enrollment</Context>
|
||||
<Version>1.0.0</Version>
|
||||
<Endpoint>http://localhost:9763/</Endpoint>
|
||||
<Transports>http,https</Transports>
|
||||
</API>
|
||||
</MalformedAPIs>
|
||||
</APIPublisher>
|
||||
</MobileDeviceMgtConfiguration>
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<MobileDeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<MalformedDataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/MobileDM_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</MalformedDataSourceConfiguration>
|
||||
</ManagementRepository>
|
||||
|
||||
<APIPublisher>
|
||||
<APIs>
|
||||
<API>
|
||||
<Name>enrollment</Name>
|
||||
<Owner>admin</Owner>
|
||||
<Context>enrollment</Context>
|
||||
<Version>1.0.0</Version>
|
||||
<Endpoint>http://localhost:9763/</Endpoint>
|
||||
<Transports>http,https</Transports>
|
||||
</API>
|
||||
</APIs>
|
||||
</APIPublisher>
|
||||
</MobileDeviceMgtConfiguration>
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<MobileDeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<MalformedJndiLookupDefinition>
|
||||
<Name>jdbc/MobileDM_DS</Name>
|
||||
</MalformedJndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</ManagementRepository>
|
||||
|
||||
<APIPublisher>
|
||||
<APIs>
|
||||
<API>
|
||||
<Name>enrollment</Name>
|
||||
<Owner>admin</Owner>
|
||||
<Context>enrollment</Context>
|
||||
<Version>1.0.0</Version>
|
||||
<Endpoint>http://localhost:9763/</Endpoint>
|
||||
<Transports>http,https</Transports>
|
||||
</API>
|
||||
</APIs>
|
||||
</APIPublisher>
|
||||
</MobileDeviceMgtConfiguration>
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<MobileDeviceMgtConfiguration>
|
||||
<MalformedManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/MobileDM_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</MalformedManagementRepository>
|
||||
|
||||
<APIPublisher>
|
||||
<APIs>
|
||||
<API>
|
||||
<Name>enrollment</Name>
|
||||
<Owner>admin</Owner>
|
||||
<Context>enrollment</Context>
|
||||
<Version>1.0.0</Version>
|
||||
<Endpoint>http://localhost:9763/</Endpoint>
|
||||
<Transports>http,https</Transports>
|
||||
</API>
|
||||
</APIs>
|
||||
</APIPublisher>
|
||||
</MobileDeviceMgtConfiguration>
|
||||
|
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014 - 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
<xs:element name="MobileDeviceMgtConfiguration">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="ManagementRepository" minOccurs="1" maxOccurs="1"
|
||||
type="DataSourceConfigurationType"/>
|
||||
<xs:element name="APIPublisher" minOccurs="1" maxOccurs="1"
|
||||
type="APIsConfigurationType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:complexType name="JndiLookupDefinitionType">
|
||||
<xs:sequence>
|
||||
<xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="DataSourceConfigurationType">
|
||||
<xs:sequence>
|
||||
<xs:element name="JndiLookupDefinition" minOccurs="1" maxOccurs="1"
|
||||
type="JndiLookupDefinitionType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="ManagementRepositoryType">
|
||||
<xs:sequence>
|
||||
<xs:element name="DataSourceConfiguration" minOccurs="1" maxOccurs="1"
|
||||
type="DataSourceConfigurationType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="APIConfigurationType">
|
||||
<xs:all>
|
||||
<xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="Owner" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="Context" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="Version" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="Endpoint" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="Transports" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="APIsConfigurationType">
|
||||
<xs:sequence>
|
||||
<xs:element name="API" maxOccurs="unbounded"
|
||||
type="APIConfigurationType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
@ -1,24 +1,82 @@
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE
|
||||
(
|
||||
ID INT auto_increment NOT NULL,
|
||||
NAME VARCHAR(300) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE
|
||||
(
|
||||
ID INT auto_increment NOT NULL,
|
||||
DESCRIPTION TEXT NULL DEFAULT NULL,
|
||||
NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
DATE_OF_ENROLLMENT BIGINT NULL DEFAULT NULL,
|
||||
DATE_OF_LAST_UPDATE BIGINT NULL DEFAULT NULL,
|
||||
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL,
|
||||
STATUS VARCHAR(15) NULL DEFAULT NULL,
|
||||
DEVICE_TYPE_ID INT(11) NULL DEFAULT NULL,
|
||||
DEVICE_IDENTIFICATION VARCHAR(300) NULL DEFAULT NULL,
|
||||
OWNER VARCHAR(45) NULL DEFAULT NULL,
|
||||
TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
|
||||
REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
-- -----------------------------------------------------
|
||||
-- Table `MBL_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `MBL_DEVICE` (
|
||||
`MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL ,
|
||||
`REG_ID` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`IMEI` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`IMSI` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`OS_VERSION` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`VENDOR` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`LATITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LONGITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`MOBILE_DEVICE_ID`) );
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `MBL_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `MBL_FEATURE` (
|
||||
`FEATURE_ID` INT NOT NULL AUTO_INCREMENT ,
|
||||
`CODE` VARCHAR(45) NOT NULL ,
|
||||
`NAME` VARCHAR(100) NULL ,
|
||||
`DESCRIPTION` VARCHAR(200) NULL ,
|
||||
PRIMARY KEY (`FEATURE_ID`) );
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `MBL_OPERATION`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `MBL_OPERATION` (
|
||||
`OPERATION_ID` INT NOT NULL AUTO_INCREMENT ,
|
||||
`FEATURE_CODE` VARCHAR(45) NOT NULL ,
|
||||
`CREATED_DATE` BIGINT NULL ,
|
||||
PRIMARY KEY (`OPERATION_ID`));
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `MBL_DEVICE_OPERATION_MAPPING`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` (
|
||||
`DEVICE_ID` VARCHAR(45) NOT NULL ,
|
||||
`OPERATION_ID` INT NOT NULL ,
|
||||
`SENT_DATE` BIGINT NULL ,
|
||||
`RECEIVED_DATE` BIGINT NULL ,
|
||||
PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) ,
|
||||
CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE`
|
||||
FOREIGN KEY (`DEVICE_ID` )
|
||||
REFERENCES `MBL_DEVICE` (`MOBILE_DEVICE_ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1`
|
||||
FOREIGN KEY (`OPERATION_ID` )
|
||||
REFERENCES `MBL_OPERATION` (`OPERATION_ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `MBL_OPERATION_PROPERTY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` (
|
||||
`OPERATION_ID` INT NOT NULL ,
|
||||
`PROPERTY` VARCHAR(45) NOT NULL ,
|
||||
`VALUE` TEXT NULL ,
|
||||
PRIMARY KEY (`OPERATION_ID`, `PROPERTY`) ,
|
||||
CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1`
|
||||
FOREIGN KEY (`OPERATION_ID` )
|
||||
REFERENCES `MBL_OPERATION` (`OPERATION_ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `MBL_FEATURE_PROPERTY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` (
|
||||
`PROPERTY` VARCHAR(45) NOT NULL ,
|
||||
`FEATURE_ID` VARCHAR(45) NOT NULL ,
|
||||
PRIMARY KEY (`PROPERTY`) ,
|
||||
CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1`
|
||||
FOREIGN KEY (`FEATURE_ID` )
|
||||
REFERENCES `MBL_FEATURE` (`FEATURE_ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
@ -1,7 +1,7 @@
|
||||
product.name=WSO2 Connected Device Manager
|
||||
product.version=2.0.0-SNAPSHOT
|
||||
product.key=CDM
|
||||
product.name=WSO2 Mobile Device Manager
|
||||
product.version=1.0.0-SNAPSHOT
|
||||
product.key=MDM
|
||||
hotdeployment=true
|
||||
hotupdate=true
|
||||
carbon.version=4.3.0
|
||||
default.server.role=CDMPlatform
|
||||
default.server.role=MDMPlatform
|
||||
|
Binary file not shown.
@ -0,0 +1,39 @@
|
||||
<%
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var verb = request.getMethod();
|
||||
var uri = request.getRequestURI();
|
||||
var callPath=uri.replace("/cdm/api/","");
|
||||
var log = new Log();
|
||||
var deviceModule = require("/modules/device.js");
|
||||
if (uri != null) {
|
||||
var uriMatcher = new URIMatcher(callPath);
|
||||
log.info(callPath);
|
||||
if (uriMatcher.match("devices/mobile/{type}/{deviceid}/")) {
|
||||
var deviceId = uriMatcher.elements().deviceid;
|
||||
var type = uriMatcher.elements().type;
|
||||
var result = deviceModule.viewDevice(type, deviceId);
|
||||
print(result);
|
||||
}
|
||||
if (uriMatcher.match("devices/mobile/")) {
|
||||
var result = deviceModule.listDevices();
|
||||
print(result);
|
||||
}
|
||||
}
|
||||
%>
|
@ -1,6 +1,24 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
function identifierFormatter(value, row, index) {
|
||||
return [
|
||||
'<a class="like" href="/cdm/devices/'+value+'" title="Like">',
|
||||
value,
|
||||
'</a>'
|
||||
].join('');}
|
||||
'<a class="like" href="/cdm/devices/' + row["deviceType"] + '/' + value + '" title="Like">',
|
||||
value,
|
||||
'</a>'
|
||||
].join('');
|
||||
}
|
@ -1 +1,32 @@
|
||||
//Init js to execute
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
//Init js to execute
|
||||
var logger = new Log();
|
||||
logger.debug("running debug");
|
||||
var app_TENANT_CONFIGS = 'tenant.configs';
|
||||
var app_carbon = require('carbon');
|
||||
var app_configs = {
|
||||
"HTTPS_URL": "https://localhost:9443"
|
||||
};
|
||||
|
||||
var app_server = new app_carbon.server.Server({
|
||||
tenanted: app_configs.tenanted,
|
||||
url: app_configs.HTTPS_URL + '/admin'
|
||||
});
|
||||
application.put("SERVER", app_server);
|
||||
application.put(app_TENANT_CONFIGS, {});
|
||||
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var utility = require("/modules/utility.js");
|
||||
var DeviceIdentifier = Packages.org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
var log = new Log();
|
||||
|
||||
var deviceManagementService = utility.getDeviceManagementService();
|
||||
|
||||
var listDevices = function () {
|
||||
var devices = deviceManagementService.getAllDevices("android");
|
||||
var deviceList = [];
|
||||
|
||||
for (i = 0; i < devices.size(); i++) {
|
||||
var device = devices.get(i);
|
||||
deviceList.push({
|
||||
"identifier": device.getDeviceIdentifier(),
|
||||
"name": device.getName(),
|
||||
"ownership": device.getOwnership(),
|
||||
"owner": device.getOwner(),
|
||||
"deviceType": device.getType(),
|
||||
"vendor": device.getProperties().get("vendor"),
|
||||
"model": device.getProperties().get("model"),
|
||||
"osVersion": device.getProperties().get("osVersion")
|
||||
});
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
var getDevice = function(type, deviceId){
|
||||
var deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setType(type);
|
||||
deviceIdentifier.setId(deviceId);
|
||||
var device = deviceManagementService.getDevice(deviceIdentifier);
|
||||
return device;
|
||||
}
|
||||
|
||||
var viewDevice = function(type, deviceId){
|
||||
var device = this.getDevice(type, deviceId);
|
||||
|
||||
var entries = device.getProperties().entrySet();
|
||||
var iterator = entries.iterator();
|
||||
var properties = {};
|
||||
while(iterator.hasNext()){
|
||||
var entry = iterator.next();
|
||||
var key = entry.getKey();
|
||||
var value = entry.getValue();
|
||||
properties[key]= value;
|
||||
}
|
||||
return {
|
||||
"identifier": device.getDeviceIdentifier(),
|
||||
"name": device.getName(),
|
||||
"ownership": device.getOwnership(),
|
||||
"owner": device.getOwner(),
|
||||
"deviceType": device.getType(),
|
||||
"vendor": device.getProperties().get("vendor"),
|
||||
"model": device.getProperties().get("model"),
|
||||
"osVersion": device.getProperties().get("osVersion"),
|
||||
"properties": properties
|
||||
};
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//temporary
|
||||
|
||||
var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext,
|
||||
Class = java.lang.Class;
|
||||
|
||||
osgiService = function (clazz) {
|
||||
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(Class.forName(clazz));
|
||||
};
|
||||
var getDeviceManagementService= function(){
|
||||
//server.authenticate("admin", "admin");
|
||||
var realmService = osgiService('org.wso2.carbon.device.mgt.core.service.DeviceManagementService');
|
||||
//var realmService = null;
|
||||
return realmService;
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
<!--
|
||||
~ Copyright 2005-2007 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.
|
||||
-->
|
||||
<project default="build-all">
|
||||
|
||||
<property name="wso2appserver.home" value="../../../"/>
|
||||
<property name="repo.location" value="${wso2appserver.home}/repository/deployment/server"/>
|
||||
<property name="warName" value="jaxrs_basic.war"/>
|
||||
<property name="build.dir" value="build"/>
|
||||
<property name="classes" value="${build.dir}/classes"/>
|
||||
<property name="lib" value="${build.dir}/lib"/>
|
||||
<property name="webapps" value="${build.dir}/webapps"/>
|
||||
<property name="src" value="."/>
|
||||
|
||||
<path id="compile.classpath">
|
||||
<fileset dir="${lib}">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<target name="init" depends="clean">
|
||||
<mkdir dir="${build.dir}"/>
|
||||
<mkdir dir="${classes}"/>
|
||||
<mkdir dir="${webapps}"/>
|
||||
<mkdir dir="${lib}"/>
|
||||
|
||||
<copy toDir="${lib}">
|
||||
<fileset dir="${wso2appserver.home}/repository/components/plugins/">
|
||||
<include name="commons-httpclient_3.1.0.wso2v2.jar"/>
|
||||
<include name="commons-codec_1.4.0.wso2v1.jar"/>
|
||||
</fileset>
|
||||
<fileset dir="${wso2appserver.home}/lib/runtimes/cxf/">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init" >
|
||||
<javac destdir="${classes}" debug="true" srcdir="src">
|
||||
<classpath refid="compile.classpath"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="war" depends="compile">
|
||||
<echo message="Creating webapp ${warName}."/>
|
||||
<copy file="src/main/java/demo/jaxrs/client/add_customer.xml" todir="${classes}/demo/jaxrs/client"/>
|
||||
<copy file="src/main/java/demo/jaxrs/client/update_customer.xml" todir="${classes}/demo/jaxrs/client"/>
|
||||
<war destfile="${webapps}/${warName}" webxml="./src/main/webapp/WEB-INF/web.xml">
|
||||
<classes dir="${classes}"/>
|
||||
<fileset dir="src/main/webapp/"/>
|
||||
</war>
|
||||
</target>
|
||||
|
||||
<target name="build-all" depends ="war">
|
||||
<echo message="Copying the created war file in to the deployment directory"/>
|
||||
<copy file="${webapps}/${warName}" todir="${repo.location}/webapps"/>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${build.dir}" />
|
||||
</target>
|
||||
|
||||
</project>
|
@ -1,81 +0,0 @@
|
||||
@echo off
|
||||
REM ---------------------------------------------------------------------------
|
||||
REM Copyright 2005,2006 WSO2, Inc. http://www.wso2.org
|
||||
REM
|
||||
REM Licensed under the Apache License, Version 2.0 (the "License");
|
||||
REM you may not use this file except in compliance with the License.
|
||||
REM You may obtain a copy of the License at
|
||||
REM
|
||||
REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
REM
|
||||
REM Unless required by applicable law or agreed to in writing, software
|
||||
REM distributed under the License is distributed on an "AS IS" BASIS,
|
||||
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
REM See the License for the specific language governing permissions and
|
||||
REM limitations under the License.
|
||||
|
||||
rem ---------------------------------------------------------------------------
|
||||
rem Client script for the Jaxws-Jaxrs/jaxrs_basic Sample
|
||||
rem
|
||||
rem Environment Variable Prequisites
|
||||
rem
|
||||
rem WSO2AppServer_HOME Must point at your WSO2 AppServer directory
|
||||
rem
|
||||
rem JAVA_HOME Must point at your Java Development Kit installation.
|
||||
rem
|
||||
rem JAVA_OPTS (Optional) Java runtime options
|
||||
rem ---------------------------------------------------------------------------
|
||||
set CURRENT_DIR=%cd%
|
||||
|
||||
rem Make sure prerequisite environment variables are set
|
||||
if not "%JAVA_HOME%" == "" goto gotJavaHome
|
||||
echo The JAVA_HOME environment variable is not defined
|
||||
echo This environment variable is needed to run this program
|
||||
goto end
|
||||
:gotJavaHome
|
||||
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
|
||||
goto okJavaHome
|
||||
:noJavaHome
|
||||
echo The JAVA_HOME environment variable is not defined correctly
|
||||
echo This environment variable is needed to run this program
|
||||
echo NB: JAVA_HOME should point to a JDK/JRE
|
||||
goto end
|
||||
:okJavaHome
|
||||
|
||||
rem check the WSO2AppServer_HOME environment variable
|
||||
if not "%WSO2AppServer_HOME%" == "" goto gotHome
|
||||
set WSO2AppServer_HOME=%CURRENT_DIR%
|
||||
if exist "%WSO2AppServer_HOME\bin\version.txt" goto okHome
|
||||
|
||||
rem guess the home. Jump two directories up to check if that is the home
|
||||
cd ..\..\..
|
||||
set WSO2AppServer_HOME=%cd%
|
||||
cd %CURRENT_DIR%
|
||||
|
||||
:gotHome
|
||||
if exist "%WSO2AppServer_HOME%\bin\version.txt" goto okHome
|
||||
|
||||
set WSO2AppServer_HOME=%~dp0..\..
|
||||
if exist "%WSO2AppServer_HOME%\bin\version.txt" goto okHome
|
||||
|
||||
echo The WSO2AppServer_HOME environment variable is not defined correctly
|
||||
echo This environment variable is needed to run this program
|
||||
goto end
|
||||
|
||||
:okHome
|
||||
rem set the classes
|
||||
setlocal EnableDelayedExpansion
|
||||
rem loop through the libs and add them to the class path
|
||||
cd %WSO2AppServer_HOME%\samples\Jaxws-Jaxrs\jaxrs_basic
|
||||
set CLIENT_CLASSPATH=.\conf;.\build\classes
|
||||
FOR %%C in (.\build\lib\*.jar) DO set CLIENT_CLASSPATH=!CLIENT_CLASSPATH!;.\build\lib\%%~nC%%~xC
|
||||
|
||||
rem ----- Execute The Requested Command ---------------------------------------
|
||||
echo Using WSO2AppServer_HOME: %WSO2AppServer_HOME%
|
||||
echo Using JAVA_HOME: %JAVA_HOME%
|
||||
set _RUNJAVA="%JAVA_HOME%\bin\java"
|
||||
|
||||
%_RUNJAVA% %JAVA_OPTS% -Dwso2appserver.home="%WSO2AppServer_HOME%" -cp "%CLIENT_CLASSPATH%" -Djava.endorsed.dirs="%WSO2AppServer_HOME%\lib\endorsed";"%JAVA_HOME%\jre\lib\endorsed";"%JAVA_HOME%\lib\endorsed" demo.jaxrs.client.Client http://localhost:9763/jaxrs_basic/services/customers/customerservice %*
|
||||
cd %CURRENT_DIR%
|
||||
endlocal
|
||||
:end
|
@ -1,90 +0,0 @@
|
||||
#!/bin/sh
|
||||
# -----------------------------------------------------------------------------
|
||||
#
|
||||
# Environment Variable Prequisites
|
||||
#
|
||||
# CARBON_HOME Home of WSO2 AppServer installation. If not set I will try
|
||||
# to figure it out.
|
||||
#
|
||||
# JAVA_HOME Must point at your Java Development Kit installation.
|
||||
#
|
||||
# NOTE: Borrowed generously from Apache Tomcat startup scripts.
|
||||
|
||||
# if JAVA_HOME is not set we're not happy
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
echo "You must set the JAVA_HOME variable before running WSO2 AppServer."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# OS specific support. $var _must_ be set to either true or false.
|
||||
cygwin=false
|
||||
os400=false
|
||||
case "`uname`" in
|
||||
CYGWIN*) cygwin=true;;
|
||||
OS400*) os400=true;;
|
||||
esac
|
||||
|
||||
# resolve links - $0 may be a softlink
|
||||
PRG="$0"
|
||||
|
||||
while [ -h "$PRG" ]; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '.*/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
# Get standard environment variables
|
||||
PRGDIR=`dirname "$PRG"`
|
||||
|
||||
# Only set WSO2AppServer_HOME if not already set
|
||||
[ -z "$CARBON_HOME" ] && CARBON_HOME=`cd "$PRGDIR/../../.." ; pwd`
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||
if $cygwin; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
[ -n "$CARBON_HOME" ] && WSO2AppServer_HOME=`cygpath --unix "$CARBON_HOME"`
|
||||
[ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
|
||||
fi
|
||||
|
||||
# For OS400
|
||||
if $os400; then
|
||||
# Set job priority to standard for interactive (interactive - 6) by using
|
||||
# the interactive priority - 6, the helper threads that respond to requests
|
||||
# will be running at the same priority as interactive jobs.
|
||||
COMMAND='chgjob job('$JOBNAME') runpty(6)'
|
||||
system $COMMAND
|
||||
|
||||
# Enable multi threading
|
||||
QIBM_MULTI_THREADED=Y
|
||||
export QIBM_MULTI_THREADED
|
||||
fi
|
||||
|
||||
# update classpath
|
||||
CLIENT_CLASSPATH=""
|
||||
for f in "$CARBON_HOME"/samples/Jaxws-Jaxrs/jaxrs_basic/build/lib/*.jar
|
||||
do
|
||||
CLIENT_CLASSPATH=$CLIENT_CLASSPATH:$f
|
||||
done
|
||||
CLIENT_CLASSPATH=$CLIENT_CLASSPATH:$CLASSPATH
|
||||
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin; then
|
||||
JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"`
|
||||
CARBON_HOME=`cygpath --absolute --windows "$CARBON_HOME"`
|
||||
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||
JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`
|
||||
fi
|
||||
|
||||
echo Using CARBON_HOME: $CARBON_HOME
|
||||
echo Using JAVA_HOME : $JAVA_HOME
|
||||
|
||||
CLIENT_CLASSPATH="$CARBON_HOME/samples/Jaxws-Jaxrs/jaxrs_basic/build/classes":$CLIENT_CLASSPATH
|
||||
|
||||
$JAVA_HOME/bin/java -Dwso2appserver.home="$CARBON_HOME" -classpath "$CLIENT_CLASSPATH" \
|
||||
-Djava.endorsed.dirs="$CARBON_HOME/lib/endorsed":"$JAVA_HOME/jre/lib/endorsed":"$JAVA_HOME/lib/endorsed" \
|
||||
demo.jaxrs.client.Client http://localhost:9763/jaxrs_basic/services/customers/customerservice$*
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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 cdm.api.windows;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Path("/EnrollmentServer")
|
||||
public interface DiscoveryService {
|
||||
|
||||
@Path("/Discovery.svc")
|
||||
@POST
|
||||
@Consumes({ "application/soap+xml;charset=utf-8", "application/xml" })
|
||||
@Produces("application/soap+xml;charset=utf-8")
|
||||
Response getDiscoveryResponse(
|
||||
InputStream discoveryRequest);
|
||||
|
||||
@Path("/Discovery.svc")
|
||||
@GET
|
||||
@Consumes("text/html")
|
||||
@Produces("text/html")
|
||||
Response getDiscoveryOKRequest();
|
||||
|
||||
@Path("/Discovery.svc")
|
||||
@GET
|
||||
@Consumes({ "application/soap+xml;charset=utf-8", "application/xml" })
|
||||
@Produces("text/html")
|
||||
Response getDiscoveryOKRequestWithBody(InputStream discoveryRequest);
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.DiscoveryService;
|
||||
|
||||
|
||||
import cdm.api.windows.DiscoveryService.beans.in.DiscoveryRequest;
|
||||
import cdm.api.windows.DiscoveryService.beans.out.Message;
|
||||
|
||||
import javax.jws.WebMethod;
|
||||
import javax.jws.WebParam;
|
||||
import javax.jws.WebResult;
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.xml.ws.BindingType;
|
||||
import javax.xml.ws.RequestWrapper;
|
||||
import javax.xml.ws.ResponseWrapper;
|
||||
import javax.xml.ws.soap.SOAPBinding;
|
||||
|
||||
@WebService(targetNamespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment", name = "IDiscoveryService")
|
||||
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
|
||||
public interface DiscoveryServiceGet {
|
||||
|
||||
@POST
|
||||
@WebMethod(operationName = "Discover")
|
||||
@RequestWrapper(targetNamespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment")
|
||||
@ResponseWrapper(targetNamespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment")
|
||||
@WebResult(name = "DiscoverResult") Message Discover(
|
||||
@WebParam(name = "request")
|
||||
DiscoveryRequest request);
|
||||
|
||||
@GET
|
||||
@WebMethod
|
||||
@WebResult() Response DiscoverGet();
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.DiscoveryService.beans.in;
|
||||
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class DiscoveryRequest implements Serializable {
|
||||
|
||||
@XmlElement(name = "EmailAddress")
|
||||
private String emailId;
|
||||
|
||||
@XmlElement(name = "RequestVersion")
|
||||
private String version;
|
||||
|
||||
@XmlElement(name = "DeviceType")
|
||||
private String deviceType;
|
||||
|
||||
public String getEmailId() {
|
||||
return emailId;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setEmailId(String emailId) {
|
||||
this.emailId = emailId;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.microsoft.com/windows/pki/2009/01/enrollment", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
|
||||
package cdm.api.windows.DiscoveryService.beans.in;
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.DiscoveryService.beans.out;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
@XmlRootElement
|
||||
public class Message implements Serializable {
|
||||
|
||||
private String authPolicy;
|
||||
private String enrollmentPolicyServiceUrl;
|
||||
private String enrollmentServiceUrl;
|
||||
|
||||
@XmlElement(name = "AuthPolicy", namespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment")
|
||||
public String getAuthPolicy() {
|
||||
return authPolicy;
|
||||
}
|
||||
|
||||
@XmlElement(name = "EnrollmentPolicyServiceUrl", namespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment")
|
||||
public String getEnrollmentPolicyServiceUrl() {
|
||||
return enrollmentPolicyServiceUrl;
|
||||
}
|
||||
|
||||
@XmlElement(name = "EnrollmentServiceUrl", namespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment")
|
||||
public String getEnrollmentServiceUrl() {
|
||||
return enrollmentServiceUrl;
|
||||
}
|
||||
|
||||
public void setAuthPolicy(String authPolicy) {
|
||||
this.authPolicy = authPolicy;
|
||||
}
|
||||
|
||||
public void setEnrollmentPolicyServiceUrl(String enrollmentPolicyServiceUrl) {
|
||||
this.enrollmentPolicyServiceUrl = enrollmentPolicyServiceUrl;
|
||||
}
|
||||
|
||||
public void setEnrollmentServiceUrl(String enrollmentServiceUrl) {
|
||||
this.enrollmentServiceUrl = enrollmentServiceUrl;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.DiscoveryService.impl;
|
||||
|
||||
import cdm.api.windows.DiscoveryService.beans.in.DiscoveryRequest;
|
||||
import cdm.api.windows.DiscoveryService.DiscoveryServiceGet;
|
||||
import cdm.api.windows.DiscoveryService.beans.out.Message;
|
||||
import org.apache.log4j.Logger;
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.xml.ws.BindingType;
|
||||
import javax.xml.ws.soap.Addressing;
|
||||
import javax.xml.ws.soap.SOAPBinding;
|
||||
|
||||
@WebService(endpointInterface = "cdm.api.windows.DiscoveryService.DiscoveryServiceGet", targetNamespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment")
|
||||
@Addressing(enabled = true, required = true)
|
||||
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
|
||||
public class DiscoveryServiceGetImpl implements DiscoveryServiceGet {
|
||||
|
||||
private Logger LOGGER = Logger.getLogger(DiscoveryServiceGetImpl.class);
|
||||
|
||||
@Override
|
||||
public Message Discover(DiscoveryRequest disRequest) {
|
||||
|
||||
System.out.println("CHECK_SECOND_POST");
|
||||
|
||||
Message message = new Message();
|
||||
message.setAuthPolicy("OnPremise");
|
||||
|
||||
message.setEnrollmentPolicyServiceUrl(
|
||||
"https://EnterpriseEnrollment.wso2.com/ENROLLMENTSERVER/PolicyEnrollmentWebservice.svc");
|
||||
message.setEnrollmentServiceUrl(
|
||||
"https://EnterpriseEnrollment.wso2.com/ENROLLMENTSERVER/DeviceEnrollmentWebservice.svc");
|
||||
|
||||
LOGGER.info("Received Discovery Service Request");
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response DiscoverGet() {
|
||||
|
||||
System.out.println("CHECK_FIRST_GET");
|
||||
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* 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 cdm.api.windows;
|
||||
|
||||
import javax.swing.text.Document;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Path("/ENROLLMENTSERVER")
|
||||
public interface EnrolmentService {
|
||||
|
||||
@Path("/PolicyEnrollmentWebservice.svc")
|
||||
@POST
|
||||
@Consumes("application/soap+xml;charset=utf-8")
|
||||
@Produces("application/soap+xml;charset=utf-8")
|
||||
Response getPolicies(Document request);
|
||||
|
||||
@Path("/DeviceEnrollmentWebservice.svc")
|
||||
@POST
|
||||
@Consumes("application/soap+xml;charset=utf-8")
|
||||
@Produces("application/soap+xml;charset=utf-8")
|
||||
Response enrollUser(Document request);
|
||||
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.impl;
|
||||
|
||||
import cdm.api.windows.DiscoveryService;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class DiscoveryServiceImpl implements DiscoveryService {
|
||||
|
||||
private Logger LOGGER = Logger.getLogger(DiscoveryServiceImpl.class);
|
||||
|
||||
public Response getDiscoveryResponse(InputStream discoveryRequest) {
|
||||
LOGGER.info("Received Discovery Service POST Request [{}]");
|
||||
|
||||
String response = null;
|
||||
File file = null;
|
||||
FileInputStream fis = null;
|
||||
byte[] data = null;
|
||||
|
||||
try {
|
||||
|
||||
file = new File("./conf/discover-service.xml");
|
||||
fis = new FileInputStream(file);
|
||||
data = new byte[(int) file.length()];
|
||||
fis.read(data);
|
||||
fis.close();
|
||||
response = new String(data, "UTF-8");
|
||||
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("An Unexpected Error has occurred while processing the request ", e);
|
||||
}
|
||||
LOGGER.info("Sending Discovery Response");
|
||||
|
||||
return Response.ok().entity(response).build();
|
||||
}
|
||||
|
||||
public Response getDiscoveryOKRequest() {
|
||||
LOGGER.info("Received a GET Request without body");
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
public Response getDiscoveryOKRequestWithBody(InputStream discoveryRequest) {
|
||||
LOGGER.info("Received a GET Request with body [{}]");
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,305 +0,0 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.impl;
|
||||
|
||||
import cdm.api.windows.EnrolmentService;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
||||
import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
import javax.swing.text.Document;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Security;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.util.Iterator;
|
||||
|
||||
import cdm.api.windows.util.CertificateSigningService;
|
||||
|
||||
public class EnrolmentServiceImpl implements EnrolmentService {
|
||||
|
||||
private Logger LOGGER = Logger.getLogger(EnrolmentServiceImpl.class);
|
||||
|
||||
static {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
||||
private String enrollmentResponseFile;
|
||||
|
||||
private String wapProvisioningXmlFile;
|
||||
|
||||
private String privatePemKeyFilePath;
|
||||
|
||||
private String caCertificateFilePath;
|
||||
|
||||
PrivateKey privateKey;
|
||||
|
||||
X509Certificate rooCACertificate;
|
||||
|
||||
public void init() {
|
||||
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(privatePemKeyFilePath);
|
||||
byte[] keyBytes = new byte[in.available()];
|
||||
in.read(keyBytes);
|
||||
in.close();
|
||||
|
||||
String key = new String(keyBytes, "UTF-8");
|
||||
key = key.replaceAll(
|
||||
"(-+BEGIN RSA PRIVATE KEY-+\\r?\\n|-+END RSA PRIVATE KEY-+\\r?\\n?)", "");
|
||||
|
||||
// don't use this for real projects!
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
keyBytes = decoder.decodeBuffer(key);
|
||||
|
||||
// generate private key
|
||||
|
||||
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
|
||||
privateKey = keyFactory.generatePrivate(spec);
|
||||
|
||||
LOGGER.info("Private Key Algorithm : " + privateKey.getAlgorithm());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("An unexpected Error has occurred while reading CA Private Key, ", e);
|
||||
}
|
||||
|
||||
try {
|
||||
FileInputStream fr = new FileInputStream(caCertificateFilePath);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
rooCACertificate = (X509Certificate) cf.generateCertificate(fr);
|
||||
|
||||
rooCACertificate.verify(rooCACertificate.getPublicKey());
|
||||
|
||||
LOGGER.info("CA Certificate Expiration Date : " + rooCACertificate.getNotAfter());
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("An unexpected Error has occurred while reading CA Root Certificate, ", e);
|
||||
}
|
||||
|
||||
/*try {
|
||||
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
|
||||
gen.initialize(2048);
|
||||
key = gen.generateKeyPair();
|
||||
PrivateKey privateKey = key.getPrivate();
|
||||
PublicKey publicKey = key.getPublic();
|
||||
|
||||
|
||||
*//**
|
||||
* Following details need to be provided
|
||||
*
|
||||
* Serial number
|
||||
* Signature algorithm
|
||||
* Issuer Name.
|
||||
* Subject Name -- or a Subject Alternative Name (SAN).
|
||||
* Date range (not before, not after).
|
||||
* Subject Public Key.
|
||||
*//*
|
||||
|
||||
X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator();
|
||||
v3CertGen.setSerialNumber(BigInteger.valueOf(new SecureRandom().nextInt(Integer.MAX_VALUE)));
|
||||
v3CertGen.setIssuerDN(new X509Principal("CN=wso2.com"));
|
||||
//v3CertGen.setIssuerDN(new X509Principal("CN=wso2.com, OU=Mobile, O=wso2 L=Colombo, C=LK"));
|
||||
v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30));
|
||||
v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365*10)));
|
||||
v3CertGen.setSubjectDN(new X509Principal("CN=wso2.com"));
|
||||
v3CertGen.setPublicKey(publicKey);
|
||||
v3CertGen.setSignatureAlgorithm("SHA1withRSA");
|
||||
|
||||
rooCACertificate = v3CertGen.generateX509Certificate(privateKey);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
|
||||
public Response getPolicies(Document request) {
|
||||
LOGGER.info("Received Get Policies Request");
|
||||
|
||||
String response = null;
|
||||
File file = null;
|
||||
FileInputStream fis = null;
|
||||
byte[] data = null;
|
||||
|
||||
try {
|
||||
|
||||
file = new File("./conf/policy-service.xml");
|
||||
fis = new FileInputStream(file);
|
||||
data = new byte[(int) file.length()];
|
||||
fis.read(data);
|
||||
fis.close();
|
||||
response = new String(data, "UTF-8");
|
||||
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("An Unexpected Error has occurred while processing the request ", e);
|
||||
}
|
||||
|
||||
LOGGER.info("Sending Get Policy Response");
|
||||
return Response.ok().entity(response).build();
|
||||
}
|
||||
|
||||
public Response enrollUser(Document request) {
|
||||
LOGGER.info("Received User Enrollment Request");
|
||||
|
||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||
xPath.setNamespaceContext(new MyNamespaceContext());
|
||||
String response = null;
|
||||
|
||||
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
try {
|
||||
NodeList nl = (NodeList) xPath.evaluate(
|
||||
"/s:Envelope/s:Body/wst:RequestSecurityToken/wsse:BinarySecurityToken", request,
|
||||
XPathConstants.NODESET);
|
||||
Node node = nl.item(0);
|
||||
String certificateDataString = node.getTextContent();
|
||||
byte[] derByteArray =
|
||||
javax.xml.bind.DatatypeConverter.parseBase64Binary(certificateDataString);
|
||||
|
||||
PKCS10CertificationRequest certificationRequest =
|
||||
new PKCS10CertificationRequest(derByteArray);
|
||||
JcaPKCS10CertificationRequest csrReq =
|
||||
new JcaPKCS10CertificationRequest(certificationRequest);
|
||||
|
||||
LOGGER.info("Public Key of CSR : " + csrReq.getPublicKey());
|
||||
|
||||
X509Certificate signedCert =
|
||||
CertificateSigningService.signCSR(csrReq, privateKey, rooCACertificate);
|
||||
|
||||
LOGGER.info("Verifying Signed Certificate with CSR's public key : " +
|
||||
signedCert.getPublicKey());
|
||||
|
||||
BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||
String rootCertEncodedString = base64Encoder.encode(rooCACertificate.getEncoded());
|
||||
String signedCertEncoded = base64Encoder.encode(signedCert.getEncoded());
|
||||
|
||||
DocumentBuilder builder = domFactory.newDocumentBuilder();
|
||||
org.w3c.dom.Document dDoc = builder.parse(wapProvisioningXmlFile);
|
||||
|
||||
NodeList wapParm = dDoc.getElementsByTagName("parm");
|
||||
|
||||
NamedNodeMap rootCertAttributes = wapParm.item(0).getAttributes();
|
||||
Node b64Encoded = rootCertAttributes.getNamedItem("value");
|
||||
b64Encoded.setTextContent(rootCertEncodedString);
|
||||
|
||||
NamedNodeMap clientCertAttributes = wapParm.item(1).getAttributes();
|
||||
Node b64CliendEncoded = clientCertAttributes.getNamedItem("value");
|
||||
b64CliendEncoded.setTextContent(signedCertEncoded);
|
||||
|
||||
String wapProvisioning = convertDocumentToString(dDoc);
|
||||
String encodedWap = base64Encoder.encode(wapProvisioning.getBytes());
|
||||
|
||||
org.w3c.dom.Document responseXml = builder.parse(enrollmentResponseFile);
|
||||
NodeList token = responseXml.getElementsByTagName("BinarySecurityToken");
|
||||
|
||||
Node firstToken = token.item(0);
|
||||
firstToken.setTextContent(encodedWap);
|
||||
|
||||
response = convertDocumentToString(responseXml);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("An Unexpected Error has occurred while processing the request ", e);
|
||||
}
|
||||
|
||||
LOGGER.info("Sending User Enrollment Response");
|
||||
return Response.ok().entity(response).build();
|
||||
}
|
||||
|
||||
private String convertDocumentToString(org.w3c.dom.Document document) throws Exception {
|
||||
DOMSource domSource = new DOMSource(document);
|
||||
StringWriter writer = new StringWriter();
|
||||
StreamResult result = new StreamResult(writer);
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
Transformer transformer = tf.newTransformer();
|
||||
transformer.transform(domSource, result);
|
||||
String wapProvisioning = writer.toString();
|
||||
|
||||
return wapProvisioning;
|
||||
|
||||
}
|
||||
|
||||
public void setEnrollmentResponseFile(String enrollmentResponseFile) {
|
||||
this.enrollmentResponseFile = enrollmentResponseFile;
|
||||
}
|
||||
|
||||
public void setWapProvisioningXmlFile(String wapProvisioningXmlFile) {
|
||||
this.wapProvisioningXmlFile = wapProvisioningXmlFile;
|
||||
}
|
||||
|
||||
public void setPrivatePemKeyFilePath(String privatePemKeyFilePath) {
|
||||
this.privatePemKeyFilePath = privatePemKeyFilePath;
|
||||
}
|
||||
|
||||
public void setCaCertificateFilePath(String caCertificateFilePath) {
|
||||
this.caCertificateFilePath = caCertificateFilePath;
|
||||
}
|
||||
|
||||
public void setPrivateKey(PrivateKey privateKey) {
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
public void setRooCACertificate(X509Certificate rooCACertificate) {
|
||||
this.rooCACertificate = rooCACertificate;
|
||||
}
|
||||
|
||||
private static class MyNamespaceContext implements NamespaceContext {
|
||||
|
||||
public String getNamespaceURI(String prefix) {
|
||||
|
||||
if ("s".equals(prefix)) {
|
||||
return "http://www.w3.org/2003/05/soap-envelope";
|
||||
} else if ("wst".equals(prefix)) {
|
||||
return "http://docs.oasis-open.org/ws-sx/ws-trust/200512";
|
||||
} else if ("wsse".equals(prefix)) {
|
||||
return "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public String getPrefix(String namespaceURI) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator getPrefixes(String namespaceURI) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.util;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bouncycastle.asn1.x500.X500Name;
|
||||
import org.bouncycastle.cert.X509v3CertificateBuilder;
|
||||
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
|
||||
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
|
||||
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
|
||||
import org.bouncycastle.operator.ContentSigner;
|
||||
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||
import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Date;
|
||||
|
||||
public class CertificateSigningService {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(CertificateSigningService.class);
|
||||
|
||||
public static X509Certificate signCSR(JcaPKCS10CertificationRequest jcaRequest,
|
||||
PrivateKey privateKey, X509Certificate caCert)
|
||||
throws Exception {
|
||||
try {
|
||||
|
||||
X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(caCert,
|
||||
BigInteger
|
||||
.valueOf(
|
||||
new SecureRandom()
|
||||
.nextInt(
|
||||
Integer.MAX_VALUE)),
|
||||
new Date(
|
||||
System.currentTimeMillis() -
|
||||
1000L *
|
||||
60 *
|
||||
60 *
|
||||
24 *
|
||||
30),
|
||||
new Date(
|
||||
System.currentTimeMillis() +
|
||||
(1000L *
|
||||
60 *
|
||||
60 *
|
||||
24 *
|
||||
365 *
|
||||
10)),
|
||||
new X500Name(
|
||||
"CN=abimaran"),
|
||||
jcaRequest
|
||||
.getPublicKey());
|
||||
|
||||
JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils();
|
||||
|
||||
ContentSigner signer =
|
||||
new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(privateKey);
|
||||
|
||||
X509Certificate theCert =
|
||||
new JcaX509CertificateConverter().setProvider("BC").getCertificate(
|
||||
certificateBuilder.build(signer));
|
||||
|
||||
LOGGER.info("Signed Certificate CN : " + theCert.getSubjectDN().getName());
|
||||
|
||||
LOGGER.info("Signed CSR's public key : " + theCert.getPublicKey());
|
||||
|
||||
return theCert;
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Error in signing the certificate", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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 cdm.api.windows.util;
|
||||
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
|
||||
|
||||
/**
|
||||
* WindowsAPIUtil class provides utility function used by Android REST-API classes.
|
||||
*/
|
||||
public class WindowsAPIUtil {
|
||||
|
||||
public static Device convertToDeviceObject(JsonObject json){
|
||||
Device device = new Device();
|
||||
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
device.setName("Test Device");
|
||||
device.setOwner("harshan");
|
||||
return device;
|
||||
}
|
||||
|
||||
public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId){
|
||||
DeviceIdentifier identifier = new DeviceIdentifier();
|
||||
identifier.setId(deviceId);
|
||||
identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
return identifier;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep;
|
||||
|
||||
import cdm.api.windows.wstep.beans.RequestSecurityTokenResponse;
|
||||
|
||||
import javax.jws.WebMethod;
|
||||
import javax.jws.WebParam;
|
||||
import javax.jws.WebResult;
|
||||
import javax.jws.WebService;
|
||||
import javax.ws.rs.*;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
import javax.xml.ws.Action;
|
||||
import javax.xml.ws.RequestWrapper;
|
||||
import javax.xml.ws.ResponseWrapper;
|
||||
import javax.xml.ws.soap.SOAPBinding;
|
||||
import javax.xml.ws.BindingType;
|
||||
|
||||
@WebService(targetNamespace = "http://schemas.microsoft.com/windows/pki/2009/01/enrollment/RSTRC", name = "wstep")
|
||||
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
|
||||
public interface CertificateEnrollmentService {
|
||||
|
||||
@RequestWrapper(localName = "RequestSecurityToken", targetNamespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512")
|
||||
@WebMethod(operationName = "RequestSecurityToken")
|
||||
@ResponseWrapper(localName = "RequestSecurityTokenResponseCollection", targetNamespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512")
|
||||
public void RequestSecurityToken(
|
||||
@WebParam(name = "TokenType", targetNamespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512")
|
||||
String TokenType,
|
||||
@WebParam(name = "RequestType", targetNamespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512")
|
||||
String RequestType,
|
||||
@WebParam(name = "BinarySecurityToken", targetNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
|
||||
String BinarySecurityToken,
|
||||
@WebParam(name = "AdditionalContext", targetNamespace = "http://schemas.xmlsoap.org/ws/2006/12/authorization")
|
||||
cdm.api.windows.wstep.beans.AdditionalContext AdditionalContext,
|
||||
@WebParam(mode = WebParam.Mode.OUT, name = "RequestSecurityTokenResponse", targetNamespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512")
|
||||
javax.xml.ws.Holder<RequestSecurityTokenResponse> response
|
||||
);
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep.beans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "OIDCollection", namespace = "http://schemas.xmlsoap.org/ws/2006/12/authorization", propOrder = {
|
||||
"contextitem"
|
||||
})
|
||||
public class AdditionalContext {
|
||||
|
||||
@XmlElement(name = "ContextItem", required = true)
|
||||
protected List<ContextItem> contextitem;
|
||||
|
||||
public List<ContextItem> getcontextitem() {
|
||||
if (contextitem == null) {
|
||||
contextitem = new ArrayList<ContextItem>();
|
||||
}
|
||||
return this.contextitem;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep.beans;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "BinarySecurityToken", namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
|
||||
public class BinarySecurityToken {
|
||||
|
||||
@XmlAttribute(name = "ValueType")
|
||||
protected String ValueType;
|
||||
@XmlAttribute(name = "EncodingType")
|
||||
protected String EncodingType;
|
||||
|
||||
@XmlValue
|
||||
protected String Token;
|
||||
|
||||
public void setValueType(String valuetype) {
|
||||
this.ValueType = valuetype;
|
||||
}
|
||||
|
||||
public String getValueType() {
|
||||
return this.ValueType;
|
||||
}
|
||||
|
||||
public void setEncodingType(String encodingtype) {
|
||||
this.EncodingType = encodingtype;
|
||||
}
|
||||
|
||||
public String getEncodingType() {
|
||||
return this.EncodingType;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.Token = token;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return this.Token;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep.beans;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "ContextItem", namespace = "http://schemas.xmlsoap.org/ws/2006/12/authorization", propOrder = {
|
||||
"Value"
|
||||
})
|
||||
public class ContextItem {
|
||||
|
||||
@XmlElement(required = true)
|
||||
protected String Value;
|
||||
|
||||
public String getValue() {
|
||||
return Value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
Value = value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep.beans;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "RequestedSecurityToken", namespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512", propOrder = {
|
||||
"binarySecurityToken"
|
||||
})
|
||||
public class RequestSecurityToken {
|
||||
|
||||
@XmlElement(name = "BinarySecurityToken", required = true, namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
|
||||
|
||||
protected BinarySecurityToken binarySecurityToken;
|
||||
|
||||
public void setBinarySecurityToken(BinarySecurityToken binarysecuritytoken) {
|
||||
this.binarySecurityToken = binarysecuritytoken;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep.beans;
|
||||
|
||||
import cdm.api.windows.wstep.beans.AdditionalContext;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "RequestSecurityTokenResponse", namespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512", propOrder = {
|
||||
"TokenType",
|
||||
"RequestedSecurityToken",
|
||||
"RequestID"
|
||||
})
|
||||
public class RequestSecurityTokenResponse implements Serializable {
|
||||
|
||||
@XmlElement(name = "TokenType", namespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512")
|
||||
private String TokenType;
|
||||
|
||||
@XmlElement(name = "RequestedSecurityToken", required = true, namespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512")
|
||||
private RequestedSecurityToken RequestedSecurityToken;
|
||||
|
||||
@XmlElement(name = "RequestID", namespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512")
|
||||
private int RequestID;
|
||||
|
||||
public String getTokenType() {
|
||||
return TokenType;
|
||||
}
|
||||
|
||||
public void setTokenType(String tokenType) {
|
||||
TokenType = tokenType;
|
||||
}
|
||||
|
||||
public RequestedSecurityToken getRequestedSecurityToken() {
|
||||
return RequestedSecurityToken;
|
||||
}
|
||||
|
||||
public void setRequestedSecurityToken(RequestedSecurityToken requestedSecurityToken) {
|
||||
RequestedSecurityToken = requestedSecurityToken;
|
||||
}
|
||||
|
||||
public int getRequestID() {
|
||||
return RequestID;
|
||||
}
|
||||
|
||||
public void setRequestID(int requestID) {
|
||||
RequestID = requestID;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep.beans;
|
||||
|
||||
import cdm.api.windows.wstep.beans.ContextItem;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "RequestedSecurityToken", namespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512", propOrder = {
|
||||
"binarySecurityToken"
|
||||
})
|
||||
public class RequestedSecurityToken {
|
||||
|
||||
@XmlElement(name = "BinarySecurityToken", required = true, namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
|
||||
|
||||
protected BinarySecurityToken binarySecurityToken;
|
||||
|
||||
public void setBinarySecurityToken(BinarySecurityToken binarysecuritytoken) {
|
||||
this.binarySecurityToken = binarysecuritytoken;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@XmlSchema(namespace = "http://www.w3.org/2003/05/soap-envelope",
|
||||
xmlns = {
|
||||
@XmlNs(prefix = "", namespaceURI = "http://www.w3.org/2003/05/soap-envelope")
|
||||
}, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
|
||||
|
||||
package cdm.api.windows.wstep.beans;
|
||||
|
||||
import javax.xml.bind.annotation.XmlNs;
|
||||
import javax.xml.bind.annotation.XmlSchema;
|
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep.impl;
|
||||
|
||||
import cdm.api.windows.wstep.beans.AdditionalContext;
|
||||
import cdm.api.windows.wstep.CertificateEnrollmentService;
|
||||
import cdm.api.windows.wstep.beans.BinarySecurityToken;
|
||||
import javax.jws.WebService;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.ws.BindingType;
|
||||
import javax.xml.ws.Holder;
|
||||
import javax.xml.ws.soap.Addressing;
|
||||
import javax.xml.ws.soap.SOAPBinding;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import cdm.api.windows.wstep.beans.RequestSecurityTokenResponse;
|
||||
import cdm.api.windows.wstep.beans.RequestedSecurityToken;
|
||||
import cdm.api.windows.wstep.util.CertificateSigningService;
|
||||
import cdm.api.windows.wstep.util.KeyStoreGenerator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
||||
import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import sun.misc.BASE64Encoder;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.StringWriter;
|
||||
import java.security.KeyStore;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
@WebService(endpointInterface = "cdm.api.windows.wstep.CertificateEnrollmentService", targetNamespace = "http://schemas.microsoft.com/windows/pki/2009/01/enrollment/RSTRC")
|
||||
@Addressing(enabled = true, required = true)
|
||||
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
|
||||
public class CertificateEnrollmentServiceImpl implements CertificateEnrollmentService {
|
||||
|
||||
private Logger LOGGER = Logger.getLogger(CertificateEnrollmentServiceImpl.class);
|
||||
|
||||
PrivateKey privateKey;
|
||||
X509Certificate rooCACertificate;
|
||||
JcaPKCS10CertificationRequest csrReq;
|
||||
PKCS10CertificationRequest certificationRequest;
|
||||
|
||||
String wapProvisioningXmlFile;
|
||||
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
@Override public void RequestSecurityToken(String TokenType, String RequestType,
|
||||
String BinarySecurityToken,
|
||||
AdditionalContext AdditionalContext,
|
||||
Holder<RequestSecurityTokenResponse> response) {
|
||||
|
||||
certificateSign();
|
||||
//////////
|
||||
System.out.println("\n\n\n"+"REQUEST_CSR:"+BinarySecurityToken+"\n\n\n");
|
||||
//////////
|
||||
|
||||
File file = new File(getClass().getClassLoader().getResource("wap-provisioning.xml").getFile());
|
||||
wapProvisioningXmlFile = file.getPath();
|
||||
|
||||
String encodedWap="Initial_test";
|
||||
|
||||
RequestSecurityTokenResponse rs = new RequestSecurityTokenResponse();
|
||||
rs.setTokenType(
|
||||
"http://schemas.microsoft.com/5.0.0.0/ConfigurationManager/Enrollment/DeviceEnrollmentToken");
|
||||
|
||||
try {
|
||||
byte[] derByteArray = javax.xml.bind.DatatypeConverter.parseBase64Binary(BinarySecurityToken);
|
||||
certificationRequest = new PKCS10CertificationRequest(derByteArray);
|
||||
csrReq = new JcaPKCS10CertificationRequest(certificationRequest);
|
||||
|
||||
X509Certificate signedCert = CertificateSigningService.signCSR(csrReq, privateKey, rooCACertificate);
|
||||
|
||||
System.out.println("PUBLIC KEY OF SIGNED CERT :"+signedCert.getPublicKey()+"\n\n\n");
|
||||
System.out.println("PUBLIC KEY OF CSR :"+csrReq.getPublicKey()+"\n\n\n");
|
||||
|
||||
|
||||
|
||||
BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||
String rootCertEncodedString = base64Encoder.encode(rooCACertificate.getEncoded());
|
||||
String signedCertEncoded = base64Encoder.encode(signedCert.getEncoded());
|
||||
|
||||
DocumentBuilder builder = domFactory.newDocumentBuilder();
|
||||
Document dDoc = builder.parse(wapProvisioningXmlFile);
|
||||
|
||||
NodeList wapParm = dDoc.getElementsByTagName("parm");
|
||||
/////////
|
||||
wapParm.item(0).getParentNode().getAttributes().getNamedItem("type").setTextContent(String.valueOf(
|
||||
DigestUtils.sha1Hex(rooCACertificate.getEncoded())));
|
||||
/////////
|
||||
NamedNodeMap rootCertAttributes = wapParm.item(0).getAttributes();
|
||||
Node b64Encoded = rootCertAttributes.getNamedItem("value");
|
||||
rootCertEncodedString=rootCertEncodedString.replaceAll("\n","");
|
||||
b64Encoded.setTextContent(rootCertEncodedString);
|
||||
System.out.println("COPY_ROOT_CERT:"+rootCertEncodedString);
|
||||
|
||||
/////////
|
||||
wapParm.item(1).getParentNode().getAttributes().getNamedItem("type").setTextContent(String.valueOf(DigestUtils.sha1Hex(signedCert.getEncoded())));
|
||||
/////////
|
||||
|
||||
|
||||
|
||||
NamedNodeMap clientCertAttributes = wapParm.item(1).getAttributes();
|
||||
Node b64CliendEncoded = clientCertAttributes.getNamedItem("value");
|
||||
signedCertEncoded=signedCertEncoded.replaceAll("\n","");
|
||||
b64CliendEncoded.setTextContent(signedCertEncoded);
|
||||
System.out.println("COPY_SIGNED_CERT:"+signedCertEncoded);
|
||||
|
||||
|
||||
String wapProvisioning = convertDocumentToString(dDoc);
|
||||
|
||||
///////
|
||||
System.out.println("WAP_XML:"+wapProvisioning+"\n\n\n");
|
||||
///////
|
||||
|
||||
encodedWap = base64Encoder.encode(wapProvisioning.getBytes());
|
||||
|
||||
} catch (Exception e) {
|
||||
//throw
|
||||
}
|
||||
|
||||
RequestedSecurityToken rst = new RequestedSecurityToken();
|
||||
BinarySecurityToken BinarySecToken=new BinarySecurityToken();
|
||||
BinarySecToken.setValueType("http://schemas.microsoft.com/5.0.0.0/ConfigurationManager/Enrollment/DeviceEnrollmentProvisionDoc");
|
||||
BinarySecToken.setEncodingType(
|
||||
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd#base64binary");
|
||||
BinarySecToken.setToken(encodedWap);
|
||||
rst.setBinarySecurityToken(BinarySecToken);
|
||||
|
||||
rs.setRequestedSecurityToken(rst);
|
||||
rs.setRequestID(0);
|
||||
response.value = rs;
|
||||
|
||||
}
|
||||
|
||||
private String convertDocumentToString(Document document) throws Exception {
|
||||
DOMSource domSource = new DOMSource(document);
|
||||
StringWriter writer = new StringWriter();
|
||||
StreamResult result = new StreamResult(writer);
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
Transformer transformer = tf.newTransformer();
|
||||
transformer.transform(domSource, result);
|
||||
String wapProvisioning = writer.toString();
|
||||
|
||||
return wapProvisioning;
|
||||
|
||||
}
|
||||
|
||||
public void certificateSign() {
|
||||
|
||||
try {
|
||||
KeyStore securityJks = KeyStoreGenerator.getKeyStore();
|
||||
String pass = "wso2carbon";
|
||||
KeyStoreGenerator.loadToStore(securityJks, pass.toCharArray(), "/Users/asok/Downloads/wso2as-5.2.1/repository/resources/security/wso2carbon.jks");
|
||||
PrivateKey privateKeyCA = (PrivateKey) securityJks.getKey("wso2carbon", pass.toCharArray());
|
||||
|
||||
privateKey=privateKeyCA;
|
||||
|
||||
Certificate cartificateCA = securityJks.getCertificate(pass);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(cartificateCA.getEncoded());
|
||||
X509Certificate cartificateCAX509 = (X509Certificate) cf.generateCertificate(bais);
|
||||
|
||||
rooCACertificate=cartificateCAX509;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep.util;
|
||||
|
||||
|
||||
/**
|
||||
* Custom exception handling class, to handle the issue that come up during
|
||||
* execution of Apk and certificate generation.
|
||||
*/
|
||||
public class ApkGenerationException extends Exception {
|
||||
|
||||
public ApkGenerationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ApkGenerationException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package cdm.api.windows.wstep.util;
|
||||
|
||||
//REMOVE THIS LATER
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bouncycastle.asn1.x500.X500Name;
|
||||
import org.bouncycastle.asn1.x509.*;
|
||||
import org.bouncycastle.cert.X509CertificateHolder;
|
||||
import org.bouncycastle.cert.X509v3CertificateBuilder;
|
||||
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
|
||||
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
|
||||
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
|
||||
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
|
||||
import org.bouncycastle.crypto.util.PrivateKeyFactory;
|
||||
import org.bouncycastle.jce.PKCS10CertificationRequest;
|
||||
import org.bouncycastle.operator.ContentSigner;
|
||||
import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;
|
||||
import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder;
|
||||
import org.bouncycastle.operator.OperatorCreationException;
|
||||
import org.bouncycastle.operator.bc.BcRSAContentSignerBuilder;
|
||||
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||
//import org.bouncycastle.pkcs.PKCS10CertificationRequestHolder;
|
||||
import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest;
|
||||
|
||||
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.*;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Date;
|
||||
|
||||
public class CertificateSigningService {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(CertificateSigningService.class);
|
||||
|
||||
/*public static X509Certificate sign(PKCS10CertificationRequest inputCSR, PrivateKey caPrivate, X509Certificate caCertificate)
|
||||
throws InvalidKeyException, NoSuchAlgorithmException,NoSuchProviderException, SignatureException, IOException,
|
||||
OperatorCreationException, CertificateException {
|
||||
|
||||
AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1withRSA");
|
||||
AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
|
||||
|
||||
AsymmetricKeyParameter foo = PrivateKeyFactory.createKey(caPrivate.getEncoded());
|
||||
|
||||
//SubjectPublicKeyInfo keyInfo = SubjectPublicKeyInfo.getInstance(pair.getPublic().getEncoded());
|
||||
|
||||
PKCS10CertificationRequestHolder pk10Holder = new PKCS10CertificationRequestHolder(inputCSR);
|
||||
SubjectPublicKeyInfo csrKeyInfo = pk10Holder.getSubjectPublicKeyInfo();
|
||||
|
||||
LOGGER.info("CN of the Device's CSR : " + pk10Holder.getSubject().toString());
|
||||
|
||||
|
||||
X509v3CertificateBuilder myCertificateGenerator = new X509v3CertificateBuilder(
|
||||
new X500Name(caCertificate.getIssuerX500Principal().getName()), BigInteger.valueOf(new SecureRandom().nextInt(Integer.MAX_VALUE)), new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30),
|
||||
new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365*10)), new X500Name("CN=abimaran"), csrKeyInfo);
|
||||
|
||||
ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(foo);
|
||||
|
||||
X509CertificateHolder holder = myCertificateGenerator.build(sigGen);
|
||||
X509CertificateStructure eeX509CertificateStructure = holder.toASN1Structure();
|
||||
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
|
||||
|
||||
// Read Certificate
|
||||
InputStream is1 = new ByteArrayInputStream(eeX509CertificateStructure.getEncoded());
|
||||
X509Certificate theCert = (X509Certificate) cf.generateCertificate(is1);
|
||||
|
||||
LOGGER.info("Signed Certificate CN : " + theCert.getSubjectDN().getName());
|
||||
|
||||
LOGGER.info("Signed CSR's public key : " + theCert.getPublicKey());
|
||||
|
||||
is1.close();
|
||||
return theCert;
|
||||
}*/
|
||||
|
||||
public static X509Certificate signCSR(JcaPKCS10CertificationRequest jcaRequest, PrivateKey privateKey, X509Certificate caCert) throws Exception{
|
||||
try {
|
||||
|
||||
X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(caCert,
|
||||
BigInteger.valueOf(new SecureRandom().nextInt(Integer.MAX_VALUE)), new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30),
|
||||
new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365*10)), new X500Name("CN=abimaran"), jcaRequest.getPublicKey());
|
||||
|
||||
JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils();
|
||||
|
||||
ContentSigner signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(privateKey);
|
||||
|
||||
X509Certificate theCert = new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateBuilder.build(signer));
|
||||
|
||||
LOGGER.info("Signed Certificate CN : " + theCert.getSubjectDN().getName());
|
||||
|
||||
LOGGER.info("Signed CSR's public key : " + theCert.getPublicKey());
|
||||
|
||||
return theCert;
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Error in signing the certificate", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Date;
|
||||
import org.spongycastle.asn1.x500.X500Name;
|
||||
import org.spongycastle.cert.X509v3CertificateBuilder;
|
||||
import org.spongycastle.cert.jcajce.JcaX509CertificateConverter;
|
||||
import org.spongycastle.cert.jcajce.JcaX509v3CertificateBuilder;
|
||||
import org.spongycastle.operator.ContentSigner;
|
||||
import org.spongycastle.operator.OperatorCreationException;
|
||||
import org.spongycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||
|
||||
/**
|
||||
* Generate X509 V3 certificates. CA, RA and SSL can be generated, where
|
||||
* intermediate certificates are signed from the root certificate to generate
|
||||
* the chain.
|
||||
*/
|
||||
public class CertificateUtil {
|
||||
private static final Log LOG = LogFactory.getLog(CertificateUtil.class);
|
||||
|
||||
|
||||
|
||||
|
||||
public static X509Certificate signCSR(PublicKey publicKeyToBeSigned, PrivateKey caPrivateKey, X509Certificate caCert) throws Exception{
|
||||
try {
|
||||
X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(caCert,
|
||||
BigInteger
|
||||
.valueOf(new SecureRandom().nextInt(Integer.MAX_VALUE)),
|
||||
new Date(System.currentTimeMillis()),
|
||||
new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365*10)),
|
||||
new X500Name("CN=abimaran"),
|
||||
publicKeyToBeSigned);
|
||||
ContentSigner signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider("SC").build(caPrivateKey);
|
||||
X509Certificate theCert = new JcaX509CertificateConverter().setProvider("SC").getCertificate(certificateBuilder.build(signer));
|
||||
return theCert;
|
||||
|
||||
} catch (OperatorCreationException e) {
|
||||
String message = "Error creating ContentSigner with JcaContentSignerBuilder"
|
||||
+ " with the private key provided.";
|
||||
LOG.error(message, e);
|
||||
throw new ApkGenerationException(message, e);
|
||||
} catch (CertificateException e) {
|
||||
String message = "Error building certificate.";
|
||||
LOG.error(message, e);
|
||||
throw new ApkGenerationException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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 cdm.api.windows.wstep.util;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Constants used throughout the project
|
||||
*/
|
||||
public class Constants {
|
||||
public static class FilePath {
|
||||
private FilePath() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String BKS_FILE = "emm_truststore.bks";
|
||||
public static final String ANDROID_AGENT = "emm-agent-android";
|
||||
public static final String WSO2CARBON_JKS = "wso2carbon.jks";
|
||||
public static final String CLIENT_TRUST_JKS = "client-truststore.jks";
|
||||
|
||||
public static final String COMMON_UTIL = ANDROID_AGENT + File.separator + "src" +
|
||||
File.separator + "org" + File.separator + "wso2" +
|
||||
File.separator + "emm" + File.separator + "agent" +
|
||||
File.separator + "utils" + File.separator +
|
||||
"CommonUtilities.java";
|
||||
public static final String WSO2EMM_JKS = "wso2emm.jks";
|
||||
public static final String ANDROID_AGENT_RAW = ANDROID_AGENT + File.separator + "res" +
|
||||
File.separator + "raw" + File.separator;
|
||||
public static final String ANDROID_AGENT_APK = ANDROID_AGENT + File.separator + "target" +
|
||||
File.separator + "emm_agent.apk";
|
||||
public static final String APK_FOLDER = "Apk";
|
||||
public static final String JKS_FOLDER = "jks";
|
||||
public static final String BIN_PATH = File.separator + "bin" + File.separator + "mvn";
|
||||
public static final String WORKING_DIR = "workingDir";
|
||||
public static final String ZIP_PATH = "zipPath";
|
||||
}
|
||||
|
||||
public static final String ALGORITHM = "RSA";
|
||||
public static final String PROVIDER = "SC";
|
||||
public static final String ENCRYPTION = "SHA1withRSA";
|
||||
public static final String REGISTRATION_AUTHORITY = "RA";
|
||||
public static final String BKS = "BKS";
|
||||
public static final String BKS_ALIAS = "cert-alias";
|
||||
public static final String JKS = "JKS";
|
||||
public static final String SSL = "SSL";
|
||||
public static final String ENVIRONMENT_VARIABLE = "MAVEN_HOME";
|
||||
public static final String ARCHIVE_TYPE = ".zip";
|
||||
public static final String ACTION = "clean";
|
||||
public static final String GOAL = "package";
|
||||
public static final String SERVER_IP_ANDROID = "String SERVER_IP = \"";
|
||||
public static final String TRUST_STORE_BKS = "String TRUSTSTORE_PASSWORD = \"";
|
||||
|
||||
public static class CSRDataKeys {
|
||||
private CSRDataKeys() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String COUNTRY_CA = "countryCA";
|
||||
public static final String STATE_CA = "stateCA";
|
||||
public static final String LOCALITY_CA = "localityCA";
|
||||
public static final String ORGANIZATION_CA = "organizationCA";
|
||||
public static final String ORGANIZATION_UNIT_CA = "organizationUCA";
|
||||
public static final String DAYS_CA = "daysCA";
|
||||
public static final String COMMON_NAME_CA = "commonNameCA";
|
||||
public static final String COUNTRY_RA = "countryRA";
|
||||
public static final String STATE_RA = "stateRA";
|
||||
public static final String LOCALITY_RA = "localityRA";
|
||||
public static final String ORGANIZATION_RA = "organizationRA";
|
||||
public static final String ORGANIZATION_UNIT_RA = "organizationURA";
|
||||
public static final String DAYS_RA = "daysRA";
|
||||
public static final String COMMON_NAME_RA = "commonNameRA";
|
||||
public static final String COUNTRY_SSL = "countrySSL";
|
||||
public static final String STATE_SSL = "stateSSL";
|
||||
public static final String LOCALITY_SSL = "localitySSL";
|
||||
public static final String ORGANIZATION_SSL = "organizationSSL";
|
||||
public static final String ORGANIZATION_UNIT_SSL = "organizationUSSL";
|
||||
public static final String DAYS_SSL = "daysSSL";
|
||||
public static final String SERVER_IP = "serverIp";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String USERSNAME = "usersname";
|
||||
public static final String COMPANY = "company";
|
||||
|
||||
}
|
||||
|
||||
public static class TruststoreKeys {
|
||||
private TruststoreKeys() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final String PASSWORD_PK12_CA = "passwordPK12CA";
|
||||
public static final String PASSWORD_PK12_RA = "passwordPK12RA";
|
||||
public static final String ALIAS_PK12_CA = "aliasPK12CA";
|
||||
public static final String ALIAS_PK12_RA = "aliasPK12RA";
|
||||
public static final String PASSWORD_WSO2_EMM_JKS = "passwordWSO2EMMJKS";
|
||||
public static final String ALIAS__CLIENT_TRUSTSTORE = "aliasClientTruststore";
|
||||
public static final String PASSWORD_CLIENT_TRUSTSTORE = "passwordClientTruststore";
|
||||
public static final String ALIAS_WSO2_CARBON = "aliasWSO2Carbon";
|
||||
public static final String PASSWORD_WSO2_CARBON = "passwordWSO2Carbon";
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue