revert-70aa11f8
geethkokila 9 years ago
commit 3fa65ae98c

@ -35,6 +35,11 @@ public class License {
private Date validTo; private Date validTo;
private String text; private String text;
public License() {
this.validTo = new Date();
this.validFrom = new Date();
}
@XmlElement(name = "Provider", required = true) @XmlElement(name = "Provider", required = true)
public String getProvider() { public String getProvider() {
return provider; return provider;

@ -46,4 +46,5 @@ public interface OperationDAO {
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException; throws OperationManagementDAOException;
} }

@ -72,9 +72,10 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
super.deleteOperation(id);
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
super.deleteOperation(id);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID = ?"); stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID = ?");
stmt.setInt(1, id); stmt.setInt(1, id);
@ -113,21 +114,19 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, public List<? extends Operation> getOperationsByDeviceAndStatus(
Operation.Status status) throws OperationManagementDAOException { int enrolmentId, Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation;
List<Operation> operations = new ArrayList<>();
List<CommandOperation> commandOperations = new ArrayList<>();
CommandOperation commandOperation; CommandOperation commandOperation;
List<CommandOperation> commandOperations = new ArrayList<>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT co.OPERATION_ID,ENABLED FROM DM_COMMAND_OPERATION co " + 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 * FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " + "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"; "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 = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
@ -137,15 +136,13 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
commandOperation = new CommandOperation(); commandOperation = new CommandOperation();
commandOperation.setEnabled(rs.getInt("ENABLED") != 0); commandOperation.setEnabled(rs.getInt("ENABLED") != 0);
commandOperation.setId(rs.getInt("OPERATION_ID")); 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); 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) { } catch (SQLException e) {
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation available " + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation available " +
"for the device'" + enrolmentId + "' with status '" + status.toString(), e); "for the device'" + enrolmentId + "' with status '" + status.toString(), e);
@ -153,7 +150,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
return operations; return commandOperations;
} }
} }

@ -152,8 +152,8 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus( public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
int enrolmentId, Operation.Status status) throws OperationManagementDAOException { Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
ConfigOperation configOperation; ConfigOperation configOperation;
@ -170,7 +170,6 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {

@ -240,7 +240,7 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
@ -281,7 +281,7 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
@ -360,7 +360,7 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +

@ -38,6 +38,10 @@
<groupId>org.apache.ws.commons.axiom</groupId> <groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId> <artifactId>axiom-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -65,7 +69,9 @@
org.wso2.carbon.registry.api, org.wso2.carbon.registry.api,
org.wso2.carbon.registry.core, org.wso2.carbon.registry.core,
org.wso2.carbon.registry.core.exceptions, 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> </Import-Package>
</instructions> </instructions>
</configuration> </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. * 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.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; 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.CarbonContext;
import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.context.RegistryType;
@ -38,6 +38,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Locale; import java.util.Locale;
@SuppressWarnings("unused")
public class RegistryBasedLicenseManager implements LicenseManager { public class RegistryBasedLicenseManager implements LicenseManager {
private Registry registry; private Registry registry;

@ -43,30 +43,26 @@ import java.util.Arrays;
public class DynamicClientRegistrationUtil { public class DynamicClientRegistrationUtil {
private static final String TOKEN_SCOPE = "tokenScope";
private static final Log log = LogFactory.getLog(DynamicClientRegistrationUtil.class); private static final Log log = LogFactory.getLog(DynamicClientRegistrationUtil.class);
public static OAuthApplicationInfo registerApplication(RegistrationProfile profile) throws APIManagementException { public static OAuthApplicationInfo registerApplication(RegistrationProfile profile) throws APIManagementException {
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo(); 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 applicationName = profile.getClientName();
String grantType = profile.getGrantType();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Trying to create OAuth application: '" + applicationName + "'"); log.debug("Trying to create OAuth application: '" + applicationName + "'");
} }
String callBackURL = profile.getCallbackUrl();
String tokenScope = profile.getTokenScope(); String tokenScope = profile.getTokenScope();
String tokenScopes[] = new String[1]; String tokenScopes[] = new String[1];
tokenScopes[0] = tokenScope; tokenScopes[0] = tokenScope;
oAuthApplicationInfo.addParameter("tokenScope", Arrays.toString(tokenScopes)); oAuthApplicationInfo.addParameter(TOKEN_SCOPE, Arrays.toString(tokenScopes));
OAuthApplicationInfo info; OAuthApplicationInfo info;
try { try {
info = createOAuthApplication(userId, applicationName, callBackURL, grantType); info = createOAuthApplication(profile);
} catch (Exception e) { } catch (Exception e) {
throw new APIManagementException("Can not create OAuth application : " + applicationName, e); throw new APIManagementException("Can not create OAuth application : " + applicationName, e);
} }
@ -98,8 +94,15 @@ public class DynamicClientRegistrationUtil {
} }
public static OAuthApplicationInfo createOAuthApplication( public static OAuthApplicationInfo createOAuthApplication(
String userId, String applicationName, String callbackUrl, String grantType) RegistrationProfile profile)
throws APIManagementException, IdentityException { 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()) { if (userId == null || userId.isEmpty()) {
return null; return null;
} }

Loading…
Cancel
Save