mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
3fa65ae98c
@ -35,6 +35,11 @@ public class License {
|
||||
private Date validTo;
|
||||
private String text;
|
||||
|
||||
public License() {
|
||||
this.validTo = new Date();
|
||||
this.validFrom = new Date();
|
||||
}
|
||||
|
||||
@XmlElement(name = "Provider", required = true)
|
||||
public String getProvider() {
|
||||
return provider;
|
||||
|
||||
@ -46,4 +46,5 @@ public interface OperationDAO {
|
||||
|
||||
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
|
||||
throws OperationManagementDAOException;
|
||||
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement(
|
||||
"UPDATE DM_COMMAND_OPERATION O SET O.ENABLED=? WHERE O.OPERATION_ID=?");
|
||||
"UPDATE DM_COMMAND_OPERATION O SET O.ENABLED = ? WHERE O.OPERATION_ID = ?");
|
||||
stmt.setBoolean(1, operation.isEnabled());
|
||||
stmt.setInt(2, operation.getId());
|
||||
stmt.executeUpdate();
|
||||
@ -72,9 +72,10 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
|
||||
@Override
|
||||
public void deleteOperation(int id) throws OperationManagementDAOException {
|
||||
super.deleteOperation(id);
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
super.deleteOperation(id);
|
||||
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID = ?");
|
||||
stmt.setInt(1, id);
|
||||
@ -93,7 +94,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
CommandOperation commandOperation = null;
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT OPERATION_ID, ENABLED FROM DM_COMMAND_OPERATION WHERE OPERATION_ID=?";
|
||||
String sql = "SELECT OPERATION_ID, ENABLED FROM DM_COMMAND_OPERATION WHERE OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, id);
|
||||
rs = stmt.executeQuery();
|
||||
@ -113,21 +114,19 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(
|
||||
int enrolmentId, Operation.Status status) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
|
||||
List<Operation> operations = new ArrayList<>();
|
||||
List<CommandOperation> commandOperations = new ArrayList<>();
|
||||
|
||||
CommandOperation commandOperation;
|
||||
List<CommandOperation> commandOperations = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT co.OPERATION_ID,ENABLED FROM DM_COMMAND_OPERATION co " +
|
||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " +
|
||||
"AND STATUS=? ) dm ON dm.OPERATION_ID = co.OPERATION_ID";
|
||||
String sql = "SELECT o.ID, co1.ENABLED, co1.STATUS, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE FROM (SELECT co.OPERATION_ID, co.ENABLED, dm.STATUS FROM DM_COMMAND_OPERATION co " +
|
||||
"INNER JOIN (SELECT ENROLMENT_ID, OPERATION_ID, STATUS FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? " +
|
||||
"AND STATUS = ?) dm ON dm.OPERATION_ID = co.OPERATION_ID) co1 INNER JOIN DM_OPERATION o ON co1.OPERATION_ID = o.ID";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, status.toString());
|
||||
@ -137,15 +136,13 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
commandOperation = new CommandOperation();
|
||||
commandOperation.setEnabled(rs.getInt("ENABLED") != 0);
|
||||
commandOperation.setId(rs.getInt("OPERATION_ID"));
|
||||
commandOperation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
commandOperation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
commandOperation.setCreatedTimeStamp(rs.getString("CREATED_TIMESTAMP"));
|
||||
commandOperation.setReceivedTimeStamp(rs.getString("RECEIVED_TIMESTAMP"));
|
||||
commandOperation.setCode(rs.getString("OPERATION_CODE"));
|
||||
commandOperations.add(commandOperation);
|
||||
}
|
||||
|
||||
for(CommandOperation cmOperation : commandOperations){
|
||||
operation = super.getOperation(cmOperation.getId());
|
||||
operation.setEnabled(cmOperation.isEnabled());
|
||||
operation.setStatus(status);
|
||||
operations.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation available " +
|
||||
"for the device'" + enrolmentId + "' with status '" + status.toString(), e);
|
||||
@ -153,7 +150,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
OperationManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return operations;
|
||||
return commandOperations;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("DELETE DM_CONFIG_OPERATION WHERE OPERATION_ID = ?");
|
||||
stmt = connection.prepareStatement("DELETE DM_CONFIG_OPERATION WHERE OPERATION_ID = ?") ;
|
||||
stmt.setInt(1, id);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
@ -152,8 +152,8 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(
|
||||
int enrolmentId, Operation.Status status) throws OperationManagementDAOException {
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
ConfigOperation configOperation;
|
||||
@ -164,13 +164,12 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT co.OPERATION_ID, co.OPERATION_CONFIG FROM DM_CONFIG_OPERATION co " +
|
||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? " +
|
||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? " +
|
||||
"AND STATUS = ?) dm ON dm.OPERATION_ID = co.OPERATION_ID";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, status.toString());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
@ -70,8 +70,8 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP = ? " +
|
||||
"WHERE O.ID = ?");
|
||||
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=? " +
|
||||
"WHERE O.ID=?");
|
||||
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
||||
stmt.setInt(2, operation.getId());
|
||||
stmt.executeUpdate();
|
||||
@ -87,8 +87,8 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OPERATION_MAPPING O SET O.STATUS = ? " +
|
||||
"WHERE O.ENROLMENT_ID = ? and O.OPERATION_ID = ?");
|
||||
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OPERATION_MAPPING O SET O.STATUS=? " +
|
||||
"WHERE O.ENROLMENT_ID=? and O.OPERATION_ID=?");
|
||||
stmt.setString(1, status.toString());
|
||||
stmt.setInt(2, enrolmentId);
|
||||
stmt.setInt(3, operationId);
|
||||
@ -110,7 +110,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
ObjectOutputStream oos = null;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, DEVICE_ID, " +
|
||||
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,DEVICE_ID," +
|
||||
"OPERATION_RESPONSE) VALUES(?, ?, ?)");
|
||||
bao = new ByteArrayOutputStream();
|
||||
oos = new ObjectOutputStream(bao);
|
||||
@ -240,7 +240,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
List<Operation> operations = new ArrayList<>();
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
||||
@ -281,7 +281,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
List<Operation> operations = new ArrayList<>();
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
|
||||
@ -360,7 +360,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
List<Operation> operations = new ArrayList<>();
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
|
||||
|
||||
@ -38,6 +38,10 @@
|
||||
<groupId>org.apache.ws.commons.axiom</groupId>
|
||||
<artifactId>axiom-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -65,7 +69,9 @@
|
||||
org.wso2.carbon.registry.api,
|
||||
org.wso2.carbon.registry.core,
|
||||
org.wso2.carbon.registry.core.exceptions,
|
||||
org.wso2.carbon.registry.core.session
|
||||
org.wso2.carbon.registry.core.session,
|
||||
javax.xml.bind,
|
||||
org.wso2.carbon.utils
|
||||
</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.license.mgt.file;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
|
||||
public class FileSystemBasedLicenseManager implements LicenseManager {
|
||||
|
||||
private static final String PATH_MOBILE_PLUGIN_CONF_DIR =
|
||||
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugins";
|
||||
|
||||
@Override
|
||||
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
|
||||
try {
|
||||
String licenseConfigPath =
|
||||
PATH_MOBILE_PLUGIN_CONF_DIR + File.separator + deviceType + File.separator + "license.xml";
|
||||
File licenseConfig = new File(licenseConfigPath);
|
||||
JAXBContext context = JAXBContext.newInstance(License.class);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
return (License) unmarshaller.unmarshal(licenseConfig);
|
||||
} catch (JAXBException e) {
|
||||
throw new LicenseManagementException("Error occurred while un-marshalling license configuration " +
|
||||
"used for '" + deviceType + "' platform from file system", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLicense(String deviceType, License license) throws LicenseManagementException {
|
||||
throw new UnsupportedOperationException("'addLicense' method is not supported in " +
|
||||
"FileSystemBasedLicenseManager");
|
||||
}
|
||||
|
||||
}
|
||||
@ -16,7 +16,7 @@
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.license.mgt;
|
||||
package org.wso2.carbon.device.mgt.extensions.license.mgt.registry;
|
||||
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
@ -17,7 +17,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.extensions.license.mgt;
|
||||
package org.wso2.carbon.device.mgt.extensions.license.mgt.registry;
|
||||
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.RegistryType;
|
||||
@ -38,6 +38,7 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class RegistryBasedLicenseManager implements LicenseManager {
|
||||
|
||||
private Registry registry;
|
||||
@ -43,30 +43,26 @@ import java.util.Arrays;
|
||||
|
||||
public class DynamicClientRegistrationUtil {
|
||||
|
||||
private static final String TOKEN_SCOPE = "tokenScope";
|
||||
private static final Log log = LogFactory.getLog(DynamicClientRegistrationUtil.class);
|
||||
|
||||
public static OAuthApplicationInfo registerApplication(RegistrationProfile profile) throws APIManagementException {
|
||||
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
|
||||
|
||||
//Subscriber's name should be passed as a parameter, since it's under the subscriber the OAuth App is created.
|
||||
String userId = profile.getOwner();
|
||||
String applicationName = profile.getClientName();
|
||||
String grantType = profile.getGrantType();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Trying to create OAuth application: '" + applicationName + "'");
|
||||
}
|
||||
|
||||
String callBackURL = profile.getCallbackUrl();
|
||||
|
||||
String tokenScope = profile.getTokenScope();
|
||||
String tokenScopes[] = new String[1];
|
||||
tokenScopes[0] = tokenScope;
|
||||
|
||||
oAuthApplicationInfo.addParameter("tokenScope", Arrays.toString(tokenScopes));
|
||||
oAuthApplicationInfo.addParameter(TOKEN_SCOPE, Arrays.toString(tokenScopes));
|
||||
OAuthApplicationInfo info;
|
||||
try {
|
||||
info = createOAuthApplication(userId, applicationName, callBackURL, grantType);
|
||||
info = createOAuthApplication(profile);
|
||||
} catch (Exception e) {
|
||||
throw new APIManagementException("Can not create OAuth application : " + applicationName, e);
|
||||
}
|
||||
@ -98,8 +94,15 @@ public class DynamicClientRegistrationUtil {
|
||||
}
|
||||
|
||||
public static OAuthApplicationInfo createOAuthApplication(
|
||||
String userId, String applicationName, String callbackUrl, String grantType)
|
||||
RegistrationProfile profile)
|
||||
throws APIManagementException, IdentityException {
|
||||
|
||||
//Subscriber's name should be passed as a parameter, since it's under the subscriber the OAuth App is created.
|
||||
String userId = profile.getOwner();
|
||||
String applicationName = profile.getClientName();
|
||||
String grantType = profile.getGrantType();
|
||||
String callbackUrl = profile.getCallbackUrl();
|
||||
|
||||
if (userId == null || userId.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user