mharindu 10 years ago
commit 6eb1af110c

@ -0,0 +1,44 @@
/*
*
* 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.common;
/**
* DTO of the consumer key and secret
*/
public class Credential {
String consumerKey;
String consumerSecret;
public String getConsumerKey() {
return consumerKey;
}
public void setConsumerKey(String consumerKey) {
this.consumerKey = consumerKey;
}
public String getConsumerSecret() {
return consumerSecret;
}
public void setConsumerSecret(String consumerSecret) {
this.consumerSecret = consumerSecret;
}
}

@ -17,7 +17,9 @@
*/
package org.wso2.carbon.device.mgt.common;
public class DeviceIdentifier {
import java.io.Serializable;
public class DeviceIdentifier implements Serializable{
private String id;
private String type;
@ -29,7 +31,6 @@ public class DeviceIdentifier {
public void setType(String type) {
this.type = type;
}
public String getId() {
return id;
}

@ -0,0 +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.
*/
package org.wso2.carbon.device.mgt.common;
public enum Platform {
ANDROID, IOS, WINDOWS;
}

@ -15,11 +15,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.app.mgt;
package org.wso2.carbon.device.mgt.common.app.mgt;
import org.wso2.carbon.device.mgt.common.Credential;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.app.mgt.oauth.dto.Credential;
import org.wso2.carbon.device.mgt.core.dto.Application;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.List;
/**
* This will handle the Application management side of MDM by acting a bridge between
@ -68,4 +69,7 @@ public interface AppManagerConnector {
*/
Credential getClientCredentials() throws AppManagerConnectorException;
void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers) throws
AppManagerConnectorException;
}

@ -0,0 +1,87 @@
/*
*
* 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.common.app.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Platform;
import java.util.List;
public class Application {
private String applicationName;
private String appId;
private String locationUrl;
private String imageUrl;
private String version;
private String appType;
public String getAppType() {
return appType;
}
public void setAppType(String appType) {
this.appType = appType;
}
public String getApplicationName() {
return applicationName;
}
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getLocationUrl() {
return locationUrl;
}
public void setLocationUrl(String locationUrl) {
this.locationUrl = locationUrl;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}

@ -0,0 +1,64 @@
/*
*
* 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.common.app.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.util.List;
public class ApplicationWrapper {
private List<String> userNameList;
private List<String> roleNameList;
private List<DeviceIdentifier> deviceIdentifiers;
private Application application;
public List<String> getUserNameList() {
return userNameList;
}
public void setUserNameList(List<String> userNameList) {
this.userNameList = userNameList;
}
public List<String> getRoleNameList() {
return roleNameList;
}
public void setRoleNameList(List<String> roleNameList) {
this.roleNameList = roleNameList;
}
public List<DeviceIdentifier> getDeviceIdentifiers() {
return deviceIdentifiers;
}
public void setDeviceIdentifiers(List<DeviceIdentifier> deviceIdentifiers) {
this.deviceIdentifiers = deviceIdentifiers;
}
public Application getApplication() {
return application;
}
public void setApplication(Application application) {
this.application = application;
}
}

@ -0,0 +1,33 @@
/*
*
* 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.common.spi;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.List;
public interface AppManager {
void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException;
}

@ -18,7 +18,10 @@
package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import java.util.List;
@ -31,14 +34,14 @@ public interface DeviceManager {
/**
* Method to retrieve the provider type that implements DeviceManager interface.
*
* @return Returns provider type
* @return Returns provider type
*/
String getProviderType();
/**
* Method to return feature manager implementation associated with a particular platform-specific plugin.
*
* @return Returns an instance of feature manager
* @return Returns an instance of feature manager
*/
FeatureManager getFeatureManager();
@ -110,7 +113,7 @@ public interface DeviceManager {
* Method to retrieve metadata of a device corresponding to a particular type that carries a specific identifier.
*
* @param deviceId Fully qualified device identifier
* @return Metadata corresponding to a particular device
* @return Metadata corresponding to a particular device
* @throws DeviceManagementException If some unusual behaviour is observed obtaining the device object
*/
Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
@ -133,5 +136,4 @@ public interface DeviceManager {
*/
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;
}

@ -0,0 +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.
*/
package org.wso2.carbon.device.mgt.common.spi;
public interface DeviceMgtService extends DeviceManager,AppManager {
}

@ -18,7 +18,7 @@
package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.HashMap;
@ -26,13 +26,13 @@ import java.util.Map;
public class DeviceManagementRepository {
private Map<String, DeviceManager> providers;
private Map<String, DeviceMgtService> providers;
public DeviceManagementRepository() {
providers = new HashMap<String, DeviceManager>();
providers = new HashMap<String, DeviceMgtService>();
}
public void addDeviceManagementProvider(DeviceManager provider) throws DeviceManagementException {
public void addDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType();
try {
DeviceManagerUtil.registerDeviceType(deviceType);
@ -43,7 +43,7 @@ public class DeviceManagementRepository {
providers.put(deviceType, provider);
}
public void removeDeviceManagementProvider(DeviceManager provider) throws DeviceManagementException {
public void removeDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType();
try {
DeviceManagerUtil.unregisterDeviceType(deviceType);
@ -54,7 +54,7 @@ public class DeviceManagementRepository {
providers.remove(deviceType);
}
public DeviceManager getDeviceManagementProvider(String type) {
public DeviceMgtService getDeviceManagementProvider(String type) {
return providers.get(type);
}

@ -22,10 +22,8 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.*;
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.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.email.NotificationMessages;
@ -37,9 +35,8 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.dto.Status;
import org.wso2.carbon.device.mgt.core.email.EmailConstants;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
@ -54,8 +51,6 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO;
private DeviceManagementRepository pluginRepository;
private OperationManager operationManager;
private LicenseManager licenseManager;
private static Log log = LogFactory.getLog(DeviceManagementServiceProviderImpl.class);
@ -63,15 +58,11 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
this.pluginRepository = pluginRepository;
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.operationManager = new OperationManagerImpl();
this.licenseManager = new LicenseManagerImpl();
}
public DeviceManagementServiceProviderImpl(){
public DeviceManagementServiceProviderImpl() {
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.operationManager = new OperationManagerImpl();
this.licenseManager = new LicenseManagerImpl();
}
@Override
@ -104,7 +95,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
}
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device for id " +
"'" + deviceId.getId() + "' and type:"+deviceId.getType(), e);
"'" + deviceId.getId() + "' and type:" + deviceId.getType(), e);
}
return convertedDevice;
}
@ -256,7 +247,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
}
@Override
public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties)
throws DeviceManagementException {
List<NotificationMessages> notificationMessages = DeviceConfigurationManager.getInstance()
.getNotificationMessagesConfig().getNotificationMessagesList();
@ -267,9 +259,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
String url = "";
String subject = "";
for(NotificationMessages notificationMessage : notificationMessages){
for (NotificationMessages notificationMessage : notificationMessages) {
if (DeviceManagementConstants.EmailNotifications.ENROL_NOTIFICATION_TYPE.
equals(notificationMessage.getType())) {
equals(notificationMessage.getType())) {
messageHeader = notificationMessage.getHeader();
messageBody = notificationMessage.getBody();
messageFooter = notificationMessage.getFooter();
@ -283,18 +275,18 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
try {
messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.FIRST_NAME + "\\}",
URLEncoder.encode(emailMessageProperties.getFirstName(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
URLEncoder.encode(emailMessageProperties.getFirstName(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{"
+ EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}",
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBuilder.append(messageHeader).append(System.getProperty("line.separator"));
messageBuilder.append(messageHeader).append(System.getProperty("line.separator"));
messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter);
} catch (IOException e) {
log.error("IO error in processing enrol email message "+emailMessageProperties);
log.error("IO error in processing enrol email message " + emailMessageProperties);
throw new DeviceManagementException("Error replacing tags in email template '" +
emailMessageProperties.getSubject() + "'", e);
}
@ -314,9 +306,9 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
String url = "";
String subject = "";
for(NotificationMessages notificationMessage : notificationMessages){
for (NotificationMessages notificationMessage : notificationMessages) {
if (DeviceManagementConstants.EmailNotifications.USER_REGISTRATION_NOTIFICATION_TYPE.
equals(notificationMessage.getType())) {
equals(notificationMessage.getType())) {
messageHeader = notificationMessage.getHeader();
messageBody = notificationMessage.getBody();
messageFooter = notificationMessage.getFooter();
@ -350,7 +342,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(messageFooter);
} catch (IOException e) {
log.error("IO error in processing enrol email message "+emailMessageProperties);
log.error("IO error in processing enrol email message " + emailMessageProperties);
throw new DeviceManagementException("Error replacing tags in email template '" +
emailMessageProperties.getSubject() + "'", e);
}
@ -402,12 +394,12 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
@Override
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
return licenseManager.getLicense(deviceType, languageCode);
return DeviceManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
}
@Override
public boolean addLicense(String type, License license) throws LicenseManagementException {
return licenseManager.addLicense(type, license);
return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(type, license);
}
public DeviceDAO getDeviceDAO() {
@ -425,55 +417,58 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
@Override
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws
OperationManagementException {
return operationManager.addOperation(operation, devices);
return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices);
}
@Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
return operationManager.getOperations(deviceId);
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperations(deviceId);
}
@Override
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException {
return operationManager.getPendingOperations(deviceId);
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId)
throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().getPendingOperations(deviceId);
}
@Override
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
return operationManager.getNextPendingOperation(deviceId);
return DeviceManagementDataHolder.getInstance().getOperationManager().getNextPendingOperation(deviceId);
}
@Override
public void updateOperation(int operationId, Operation.Status operationStatus)
throws OperationManagementException {
operationManager.updateOperation(operationId, operationStatus);
DeviceManagementDataHolder.getInstance().getOperationManager().updateOperation(operationId, operationStatus);
}
@Override
public void deleteOperation(int operationId) throws OperationManagementException {
operationManager.deleteOperation(operationId);
DeviceManagementDataHolder.getInstance().getOperationManager().deleteOperation(operationId);
}
@Override
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
throws OperationManagementException {
return operationManager.getOperationByDeviceAndOperationId(deviceId, operationId);
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationByDeviceAndOperationId(
deviceId, operationId);
}
@Override
public List<? extends Operation> getOperationsByDeviceAndStatus(DeviceIdentifier identifier,
Operation.Status status) throws OperationManagementException, DeviceManagementException {
return operationManager.getOperationsByDeviceAndStatus(identifier, status);
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationsByDeviceAndStatus(identifier,
status);
}
@Override
public Operation getOperation(int operationId) throws OperationManagementException {
return operationManager.getOperation(operationId);
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId);
}
@Override
public List<? extends Operation> getOperationsForStatus(Operation.Status status)
throws OperationManagementException {
return operationManager.getOperationsForStatus(status);
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationsForStatus(status);
}
}

@ -17,16 +17,20 @@
*/
package org.wso2.carbon.device.mgt.core.app.mgt;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.Credential;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.app.mgt.oauth.dto.Credential;
import org.wso2.carbon.device.mgt.core.dto.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import java.util.List;
public class AppManagementServiceImpl implements AppManagerConnector {
@Override
public Application[] getApplicationList(String domain, int pageNumber,
int size) throws AppManagerConnectorException {
public Application[] getApplicationList(String domain, int pageNumber, int size) throws AppManagerConnectorException {
return DeviceManagementDataHolder.getInstance().getAppManager().getApplicationList(domain, pageNumber, size);
}
@ -48,4 +52,10 @@ public class AppManagementServiceImpl implements AppManagerConnector {
return DeviceManagementDataHolder.getInstance().getAppManager().getClientCredentials();
}
@Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException {
DeviceManagementDataHolder.getInstance().getAppManager().installApplication(operation, deviceIdentifiers);
}
}

@ -18,12 +18,26 @@
*/
package org.wso2.carbon.device.mgt.core.app.mgt;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
public class AppManagerConnectorFactory {
private static DeviceManagementRepository pluginRepository;
public DeviceManagementRepository getPluginRepository() {
return pluginRepository;
}
public void setPluginRepository(DeviceManagementRepository pluginRepository) {
this.pluginRepository = pluginRepository;
}
public static AppManagerConnector getConnector(AppManagementConfig config) {
return new RemoteAppManagerConnector(config);
return new RemoteAppManagerConnector(config, pluginRepository);
}
}

@ -23,19 +23,25 @@ import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.Credential;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator;
import org.wso2.carbon.device.mgt.core.app.mgt.oauth.dto.Credential;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations;
import org.wso2.carbon.device.mgt.core.dto.Application;
import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException;
import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub;
import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
import java.rmi.RemoteException;
import java.util.List;
/**
* Implements AppManagerConnector interface
@ -45,12 +51,14 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
private ConfigurationContext configCtx;
private ServiceAuthenticator authenticator;
private String oAuthAdminServiceUrl;
private DeviceManagementRepository pluginRepository;
private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1";
private static final Log log = LogFactory.getLog(RemoteAppManagerConnector.class);
public RemoteAppManagerConnector(AppManagementConfig appManagementConfig) {
public RemoteAppManagerConnector(AppManagementConfig appManagementConfig, DeviceManagementRepository pluginRepository) {
IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
getDeviceManagementConfigRepository().getIdentityConfigurations();
this.authenticator =
@ -63,6 +71,7 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
throw new IllegalArgumentException("Error occurred while initializing Axis2 Configuration Context. " +
"Please check if an appropriate axis2.xml is provided", e);
}
this.pluginRepository = pluginRepository;
}
@Override
@ -93,6 +102,16 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
return credential;
}
@Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException {
for(DeviceIdentifier deviceIdentifier:deviceIdentifiers){
DeviceMgtService dms = this.getPluginRepository().getDeviceManagementProvider(deviceIdentifier.getType());
dms.installApplication(operation,deviceIdentifiers);
}
}
private OAuthConsumerAppDTO getAppInfo() throws AppManagerConnectorException {
OAuthConsumerAppDTO appInfo = null;
try {
@ -133,4 +152,7 @@ public class RemoteAppManagerConnector implements AppManagerConnector {
throw new AppManagerConnectorException(msg, e);
}
public DeviceManagementRepository getPluginRepository() {
return pluginRepository;
}
}

@ -19,8 +19,7 @@
package org.wso2.carbon.device.mgt.core.app.mgt.config;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.utils.CarbonUtils;

@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.core.app.mgt.oauth;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
/**
* Authenticate a given service client.

@ -20,8 +20,9 @@
package org.wso2.carbon.device.mgt.core.internal;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnector;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
@ -40,6 +41,7 @@ public class DeviceManagementDataHolder {
private APIPublisherService apiPublisherService;
private AppManagerConnector appManager;
private AppManagementConfig appManagerConfig;
private OperationManager operationManager;
private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder();
@ -126,4 +128,11 @@ public class DeviceManagementDataHolder {
this.appManagerConfig = appManagerConfig;
}
public OperationManager getOperationManager() {
return operationManager;
}
public void setOperationManager(OperationManager operationManager) {
this.operationManager = operationManager;
}
}

@ -27,7 +27,10 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
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.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl;
@ -35,8 +38,8 @@ import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService;
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherServiceImpl;
import org.wso2.carbon.device.mgt.core.api.mgt.APIRegistrationStartupObserver;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnector;
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.core.app.mgt.RemoteAppManagerConnector;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfigurationManager;
@ -47,6 +50,7 @@ import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl;
@ -67,7 +71,7 @@ import java.util.List;
* bind="setRealmService"
* unbind="unsetRealmService"
* @scr.reference name="device.manager.service"
* interface="org.wso2.carbon.device.mgt.common.spi.DeviceManager"
* interface="org.wso2.carbon.device.mgt.common.spi.DeviceMgtService"
* cardinality="0..n"
* policy="dynamic"
* bind="setDeviceManager"
@ -98,14 +102,13 @@ public class DeviceManagementServiceComponent {
private static final Object LOCK = new Object();
private boolean isInitialized;
private List<DeviceManager> deviceManagers = new ArrayList<DeviceManager>();
private List<DeviceMgtService> deviceManagers = new ArrayList<DeviceMgtService>();
protected void activate(ComponentContext componentContext) {
try {
if (log.isDebugEnabled()) {
log.debug("Initializing device management core bundle");
}
/* Initializing Device Management Configuration */
DeviceConfigurationManager.getInstance().initConfig();
DeviceManagementConfig config =
@ -114,15 +117,16 @@ public class DeviceManagementServiceComponent {
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
DeviceManagementDAOFactory.init(dsConfig);
DeviceManagementService deviceManagementProvider =
new DeviceManagementServiceProviderImpl(this.getPluginRepository());
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
/* Initializing license manager */
this.initLicenseManager();
/*Initialize Operation Manager*/
this.initOperationsManager();
/* Initializing app manager connector */
this.initAppManagerConnector();
DeviceManagementService deviceManagementProvider =
new DeviceManagementServiceProviderImpl(this.getPluginRepository());
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
OperationManagementDAOFactory.init(dsConfig);
/* If -Dsetup option enabled then create device management database schema */
@ -138,7 +142,7 @@ public class DeviceManagementServiceComponent {
}
synchronized (LOCK) {
for (DeviceManager deviceManager : deviceManagers) {
for (DeviceMgtService deviceManager : deviceManagers) {
this.registerDeviceManagementProvider(deviceManager);
}
this.isInitialized = true;
@ -169,21 +173,20 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig);
}
private void initOperationsManager() throws OperationManagementException {
OperationManager operationManager = new OperationManagerImpl();
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
}
private void initAppManagerConnector() throws AppManagerConnectorException {
AppManagementConfigurationManager.getInstance().initConfig();
AppManagementConfig appConfig =
AppManagementConfigurationManager.getInstance().getAppManagementConfig();
DeviceManagementDataHolder.getInstance().setAppManagerConfig(appConfig);
RemoteAppManagerConnector appManager = new RemoteAppManagerConnector(appConfig);
RemoteAppManagerConnector appManager = new RemoteAppManagerConnector(appConfig,this.getPluginRepository());
DeviceManagementDataHolder.getInstance().setAppManager(appManager);
}
// private void initAPIProviders() throws DeviceManagementException {
// for (APIConfig config : APIPublisherConfig.getInstance().getApiConfigs()) {
// config.init();
// }
// }
private void registerServices(ComponentContext componentContext) {
if (log.isDebugEnabled()) {
log.debug("Registering OSGi service DeviceManagementServiceImpl");
@ -231,7 +234,7 @@ public class DeviceManagementServiceComponent {
}
}
private void registerDeviceManagementProvider(DeviceManager deviceManager) {
private void registerDeviceManagementProvider(DeviceMgtService deviceManager) {
try {
this.getPluginRepository().addDeviceManagementProvider(deviceManager);
} catch (DeviceManagementException e) {
@ -245,7 +248,7 @@ public class DeviceManagementServiceComponent {
*
* @param deviceManager An instance of DeviceManager
*/
protected void setDeviceManager(DeviceManager deviceManager) {
protected void setDeviceManager(DeviceMgtService deviceManager) {
if (log.isDebugEnabled()) {
log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'");
}
@ -262,7 +265,7 @@ public class DeviceManagementServiceComponent {
*
* @param deviceManager An Instance of DeviceManager
*/
protected void unsetDeviceManager(DeviceManager deviceManager) {
protected void unsetDeviceManager(DeviceMgtService deviceManager) {
if (log.isDebugEnabled()) {
log.debug("Unsetting Device Management Service Provider : '" + deviceManager.getProviderType() + "'");
}

@ -18,6 +18,7 @@
package org.wso2.carbon.device.mgt.core.service;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnector;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;

@ -23,7 +23,7 @@ import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import java.util.List;
public class DeviceManagementServiceImpl implements DeviceManagementService {

@ -22,6 +22,7 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
public class DeviceManagementRepositoryTests {
@ -34,7 +35,7 @@ public class DeviceManagementRepositoryTests {
@Test
public void testAddDeviceManagementService() {
DeviceManager sourceProvider = new TestDeviceManager();
DeviceMgtService sourceProvider = new TestDeviceManager();
try {
this.getRepository().addDeviceManagementProvider(sourceProvider);
} catch (DeviceManagementException e) {
@ -47,7 +48,7 @@ public class DeviceManagementRepositoryTests {
@Test(dependsOnMethods = "testAddDeviceManagementService")
public void testRemoveDeviceManagementService() {
DeviceManager sourceProvider = new TestDeviceManager();
DeviceMgtService sourceProvider = new TestDeviceManager();
try {
this.getRepository().removeDeviceManagementProvider(sourceProvider);
} catch (DeviceManagementException e) {

@ -17,15 +17,15 @@
*/
package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.AppManagerConnectorException;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.spi.DeviceMgtService;
import java.util.List;
public class TestDeviceManager implements DeviceManager {
public class TestDeviceManager implements DeviceMgtService {
public static final String DEVICE_TYPE_TEST = "Test";
@ -89,4 +89,9 @@ public class TestDeviceManager implements DeviceManager {
return false;
}
@Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws AppManagerConnectorException {
}
}

@ -27,17 +27,18 @@ import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
//TODO :
public class PIPDevice {
Device device;
DeviceType deviceType;
DeviceIdentifier deviceIdentifier;
String ownershipType;
List<String> userIds;
String roles [];
String altitude;
String longitude;
Timestamp timestamp;
private Device device;
private DeviceType deviceType;
private DeviceIdentifier deviceIdentifier;
private String ownershipType;
private List<String> userIds;
private String roles[];
private String altitude;
private String longitude;
private Timestamp timestamp;
/*This will be used to record attributes to which would come from other PDPs*/
Map<String, Object> attributes;

@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.common;
import org.wso2.carbon.device.mgt.core.dto.Device;
import java.io.Serializable;
import java.sql.Date;
import java.util.List;
import java.util.Map;
@ -28,12 +29,11 @@ import java.util.Map;
/**
* This class will be the used to create policy object with relevant information for evaluating.
*/
public class Policy implements Comparable<Policy> {
public class Policy implements Comparable<Policy>, Serializable {
private int id; // Identifier of the policy.
private int priorityId; // Priority of the policies. This will be used only for simple evaluation.
private Profile profile; // Profile
private int profileId;
private String policyName; // Name of the policy.
private boolean generic; // If true, this should be applied to all related device.
private List<String> roleList; // Roles which this policy should be applied.
@ -57,6 +57,7 @@ public class Policy implements Comparable<Policy> {
private String longitude; // Longitude
private int tenantId;
private int profileId;
/*This will be used to record attributes which will be used by customer extended PDPs and PIPs*/

@ -31,8 +31,6 @@ public interface PolicyAdministratorPoint {
/**
* This method adds a policy to the platform
*
* @param policy
* @return primary key (generated key)
*/
Policy addPolicy(Policy policy) throws PolicyManagementException;
@ -40,13 +38,10 @@ public interface PolicyAdministratorPoint {
Policy updatePolicy(Policy policy) throws PolicyManagementException;
boolean deletePolicy(Policy policy) throws PolicyManagementException;
/**
* This method adds a policy per device which should be implemented by the related plugins.
*
* @param deviceIdentifierList
* @param policy
* @return
* @throws PolicyManagementException
*/
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException;
@ -132,7 +127,7 @@ public interface PolicyAdministratorPoint {
*/
Profile addProfile(Profile profile) throws PolicyManagementException;
boolean deleteProfile(int profileId) throws PolicyManagementException;
boolean deleteProfile(Profile profile) throws PolicyManagementException;
Profile updateProfile(Profile profile) throws PolicyManagementException;

@ -34,7 +34,7 @@ public interface PolicyEvaluationPoint {
* @param deviceIdentifier device information.
* @return returns the effective policy.
*/
Policy getEffectivePolicies(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException;
Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException;
/**
@ -42,5 +42,5 @@ public interface PolicyEvaluationPoint {
* @param deviceIdentifier device information.
* @return returns the effective feature set.
*/
List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException ;
List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException;
}

@ -124,7 +124,7 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` (
`NAME` VARCHAR(256) NOT NULL ,
`CODE` VARCHAR(45) NULL DEFAULT NULL ,
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
`EVALUVATION_RULE` VARCHAR(60) NOT NULL ,
`EVALUATION_RULE` VARCHAR(60) NOT NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;

@ -119,6 +119,10 @@
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.base</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>

@ -19,7 +19,6 @@
package org.wso2.carbon.policy.mgt.core;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.*;
@ -39,15 +38,19 @@ public interface PolicyManagerService {
Policy updatePolicy(Policy policy) throws PolicyManagementException;
Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
boolean deletePolicy(Policy policy) throws PolicyManagementException;
Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException;
Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException;
List<Policy> getPolicies(String deviceType) throws PolicyManagementException;
List<Feature> getFeatures() throws FeatureManagementException;
PolicyAdministratorPoint getPAP() throws PolicyManagementException;
PolicyAdministratorPoint getPAP() throws PolicyManagementException;
PolicyInformationPoint getPIP() throws PolicyManagementException;
PolicyInformationPoint getPIP() throws PolicyManagementException;
PolicyEvaluationPoint getPEP() throws PolicyManagementException;
}

@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;
import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import java.util.List;
@ -67,19 +68,41 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
return policyAdministratorPoint.updatePolicy(policy);
}
@Override
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
return policyAdministratorPoint.deletePolicy(policy);
}
@Override
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
return null;
try {
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
getEffectivePolicy(deviceIdentifier);
} catch (PolicyEvaluationException e) {
String msg = "Error occurred while getting the effective policies from the PEP service for device " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
}
@Override
public Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException {
return null;
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws
FeatureManagementException {
try {
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
getEffectiveFeatures(deviceIdentifier);
} catch (PolicyEvaluationException e) {
String msg = "Error occurred while getting the effective features from the PEP service " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
log.error(msg, e);
throw new FeatureManagementException(msg, e);
}
}
@Override
public List<Policy> getPolicies(String deviceType) throws PolicyManagementException {
return null;
return policyAdministratorPoint.getPoliciesOfDeviceType(deviceType);
}
@Override
@ -96,4 +119,9 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
public PolicyInformationPoint getPIP() throws PolicyManagementException {
return new PolicyInformationPointImpl();
}
@Override
public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
}
}

@ -38,9 +38,11 @@ public interface FeatureDAO {
ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException;
List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws FeatureManagerDAOException;
List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException;
List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws FeatureManagerDAOException;
List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException;
List<Feature> getAllFeatures() throws FeatureManagerDAOException;

@ -73,4 +73,13 @@ public interface PolicyDAO {
PolicyLocations getLocationsOfPolicy(Policy policy) throws PolicyManagerDAOException;
void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
throws PolicyManagerDAOException;
void setPolicyApplied(int deviceId) throws PolicyManagerDAOException;
void updateEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
throws PolicyManagerDAOException;
boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException;
}

@ -50,7 +50,7 @@ public class FeatureDAOImpl implements FeatureDAO {
try {
conn = this.getConnection();
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUVATION_RULE, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?)";
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUATION_RULE, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setString(1, feature.getName());
stmt.setString(2, feature.getCode());
@ -88,7 +88,7 @@ public class FeatureDAOImpl implements FeatureDAO {
try {
conn = this.getConnection();
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUVATION_RULE, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?)";
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUATION_RULE, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
for (Feature feature : features) {
@ -133,7 +133,7 @@ public class FeatureDAOImpl implements FeatureDAO {
try {
conn = this.getConnection();
String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ?, EVALUVATION_RULE = ? WHERE ID = ?";
String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ?, EVALUATION_RULE = ? WHERE ID = ?";
stmt = conn.prepareStatement(query);
stmt.setString(1, feature.getName());
stmt.setString(2, feature.getCode());
@ -266,7 +266,7 @@ public class FeatureDAOImpl implements FeatureDAO {
try {
conn = this.getConnection();
String query = "SELECT ID, NAME, CODE, DEVICE_TYPE_ID, EVALUVATION_RULE FROM DM_FEATURES";
String query = "SELECT ID, NAME, CODE, DEVICE_TYPE_ID, EVALUATION_RULE FROM DM_FEATURES";
stmt = conn.prepareStatement(query);
resultSet = stmt.executeQuery();
@ -277,7 +277,7 @@ public class FeatureDAOImpl implements FeatureDAO {
feature.setCode(resultSet.getString("CODE"));
feature.setName(resultSet.getString("NAME"));
feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID"));
feature.setRuleValue(resultSet.getString("EVALUVATION_RULE"));
feature.setRuleValue(resultSet.getString("EVALUATION_RULE"));
featureList.add(feature);
}
@ -303,7 +303,7 @@ public class FeatureDAOImpl implements FeatureDAO {
try {
conn = this.getConnection();
String query = "SELECT PF.ID AS ID, PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " +
"F.EVALUVATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " +
"F.EVALUATION_RULE RULE, PF.CONTENT AS CONTENT, PF.PROFILE_ID PROFILE_ID FROM DM_PROFILE_FEATURES AS PF " +
"JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID";
stmt = conn.prepareStatement(query);
resultSet = stmt.executeQuery();
@ -320,6 +320,7 @@ public class FeatureDAOImpl implements FeatureDAO {
profileFeature.setFeature(feature);
profileFeature.setId(resultSet.getInt("ID"));
profileFeature.setContent(resultSet.getObject("CONTENT"));
profileFeature.setProfileId(resultSet.getInt("PROFILE_ID"));
featureList.add(profileFeature);
}
@ -345,7 +346,7 @@ public class FeatureDAOImpl implements FeatureDAO {
try {
conn = this.getConnection();
String query = "SELECT f.ID ID, f.NAME NAME, f.CODE CODE, f.DEVICE_TYPE_ID DEVICE_TYPE_ID," +
" f.EVALUVATION_RULE EVALUVATION_RULE FROM DM_FEATURES f INNER JOIN DM_DEVICE_TYPE d " +
" f.EVALUATION_RULE EVALUATION_RULE FROM DM_FEATURES f INNER JOIN DM_DEVICE_TYPE d " +
"ON d.ID=f.DEVICE_TYPE_ID WHERE d.NAME = ?";
stmt = conn.prepareStatement(query);
stmt.setString(1, deviceType);
@ -358,7 +359,7 @@ public class FeatureDAOImpl implements FeatureDAO {
feature.setCode(resultSet.getString("CODE"));
feature.setName(resultSet.getString("NAME"));
feature.setDeviceTypeId(resultSet.getInt("DEVICE_TYPE_ID"));
feature.setRuleValue(resultSet.getString("EVALUVATION_RULE"));
feature.setRuleValue(resultSet.getString("EVALUATION_RULE"));
featureList.add(feature);
}
@ -384,7 +385,7 @@ public class FeatureDAOImpl implements FeatureDAO {
try {
conn = this.getConnection();
String query = "SELECT PF.ID AS ID, PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " +
"F.EVALUVATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " +
"F.EVALUATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " +
"JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID WHERE PROFILE_ID=?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId);

@ -21,22 +21,16 @@ package org.wso2.carbon.policy.mgt.core.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.core.dto.Device;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyDates;
import org.wso2.carbon.policy.mgt.common.PolicyLocations;
import org.wso2.carbon.policy.mgt.common.PolicyTimes;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
public class PolicyDAOImpl implements PolicyDAO {
@ -200,7 +194,8 @@ public class PolicyDAOImpl implements PolicyDAO {
}
@Override
public Policy addLocationToPolicy(String latitude, String longitude, Policy policy) throws PolicyManagerDAOException {
public Policy addLocationToPolicy(String latitude, String longitude, Policy policy) throws
PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
@ -270,6 +265,7 @@ public class PolicyDAOImpl implements PolicyDAO {
policy.setId(policyId);
policy.setPolicyName(resultSet.getString("NAME"));
policy.setTenantId(resultSet.getInt("TENANT_ID"));
policy.setPriorityId(resultSet.getInt("PRIORITY"));
}
return policy;
@ -302,6 +298,7 @@ public class PolicyDAOImpl implements PolicyDAO {
policy.setId(resultSet.getInt("ID"));
policy.setPolicyName(resultSet.getString("NAME"));
policy.setTenantId(resultSet.getInt("TENANT_ID"));
policy.setPriorityId(resultSet.getInt("PRIORITY"));
}
return policy;
@ -335,6 +332,7 @@ public class PolicyDAOImpl implements PolicyDAO {
policy.setProfileId(resultSet.getInt("PROFILE_ID"));
policy.setPolicyName(resultSet.getString("NAME"));
policy.setTenantId(resultSet.getInt("TENANT_ID"));
policy.setPriorityId(resultSet.getInt("PRIORITY"));
policies.add(policy);
}
return policies;
@ -432,7 +430,6 @@ public class PolicyDAOImpl implements PolicyDAO {
resultSet = stmt.executeQuery();
while (resultSet.next()) {
//TODO:
policy.setStartTime(resultSet.getInt("STARTING_TIME"));
policy.setEndTime(resultSet.getInt("ENDING_TIME"));
@ -467,7 +464,7 @@ public class PolicyDAOImpl implements PolicyDAO {
resultSet = stmt.executeQuery();
while (resultSet.next()) {
//TODO:
policy.setStartDate(resultSet.getDate("START_DATE"));
policy.setEndDate(resultSet.getDate("END_DATE"));
@ -502,7 +499,7 @@ public class PolicyDAOImpl implements PolicyDAO {
resultSet = stmt.executeQuery();
while (resultSet.next()) {
//TODO:
policy.setLatitude(resultSet.getString("LATITUDE"));
policy.setLongitude(resultSet.getString("LONGITUDE"));
@ -521,6 +518,117 @@ public class PolicyDAOImpl implements PolicyDAO {
return locations;
}
@Override
public void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
try {
conn = this.getConnection();
String query = "INSERT INTO DM_DEVICE_POLICY_APPLIED " +
"(DEVICE_ID, POLICY_ID, POLICY_CONTENT, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
stmt.setInt(2, policyId);
stmt.setObject(3, profileFeatures);
stmt.setTimestamp(4, currentTimestamp);
stmt.setTimestamp(5, currentTimestamp);
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while adding the evaluated feature list to device.";
log.error(msg, e);
throw new PolicyManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null);
}
}
@Override
public void setPolicyApplied(int deviceId) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
try {
conn = this.getConnection();
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET APPLIED_TIME = ?, APPLIED = ? WHERE DEVICE_ID = ? ";
stmt = conn.prepareStatement(query);
stmt.setTimestamp(1, currentTimestamp);
stmt.setBoolean(2, true);
stmt.setInt(3, deviceId);
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while updating applied policy to device (" + deviceId + ")";
log.error(msg, e);
throw new PolicyManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null);
}
}
@Override
public void updateEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
try {
conn = this.getConnection();
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ?, UPDATED_TIME = ?, " +
"APPLIED = ? WHERE DEVICE_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, policyId);
stmt.setObject(2, profileFeatures);
stmt.setTimestamp(3, currentTimestamp);
stmt.setBoolean(4, false);
stmt.setInt(5, deviceId);
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while updating the evaluated feature list to device.";
log.error(msg, e);
throw new PolicyManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null);
}
}
@Override
public boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
boolean exist = false;
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
resultSet = stmt.executeQuery();
exist = resultSet.next();
} catch (SQLException e) {
String msg = "Error occurred while checking whether device (" + deviceId + ") has a policy to apply.";
log.error(msg, e);
throw new PolicyManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection();
}
return exist;
}
@Override
public List<Integer> getPolicyIdsOfDevice(Device device) throws PolicyManagerDAOException {
@ -711,8 +819,8 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
int tenantId = PolicyManagerUtil.getTenantId();
int tenantId = MultitenantConstants.SUPER_TENANT_ID;
try {
conn = this.getConnection();
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY) VALUES (?, ?, ?, ?)";

@ -20,6 +20,7 @@ package org.wso2.carbon.policy.mgt.core.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
@ -27,7 +28,7 @@ import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.ProfileDAO;
import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -45,7 +46,7 @@ public class ProfileDAOImpl implements ProfileDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
int tenantId = MultitenantConstants.SUPER_TENANT_ID;
int tenantId = PolicyManagerUtil.getTenantId();
try {
conn = this.getConnection();
@ -91,7 +92,7 @@ public class ProfileDAOImpl implements ProfileDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
int tenantId = MultitenantConstants.SUPER_TENANT_ID;
int tenantId = PolicyManagerUtil.getTenantId();
try {
conn = this.getConnection();

@ -57,6 +57,11 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
return policyManager.updatePolicy(policy);
}
@Override
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
return policyManager.deletePolicy(policy);
}
@Override
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException {
return policyManager.addPolicyToDevice(deviceIdentifierList, policy);
@ -94,17 +99,17 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
@Override
public boolean isPolicyAvailableForDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
return false;
return policyManager.checkPolicyAvailable(deviceIdentifier);
}
@Override
public boolean isPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
return false;
return policyManager.setPolicyApplied(deviceIdentifier);
}
@Override
public void setPolicyUsed(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException {
policyManager.addAppliedPolicyToDevice(deviceIdentifier, policy.getId(), policy.getProfile().getProfileFeaturesList());
}
@Override
@ -119,8 +124,14 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
}
@Override
public boolean deleteProfile(int profileId) throws PolicyManagementException {
return false;
public boolean deleteProfile(Profile profile) throws PolicyManagementException {
try {
return profileManager.deleteProfile(profile);
} catch (ProfileManagementException e) {
String msg = "Error occurred while deleting the profile.";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
}
@Override

@ -59,9 +59,9 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
PIPDevice pipDevice = new PIPDevice();
org.wso2.carbon.device.mgt.common.Device device;
// TODO : Find
DeviceType deviceType = new DeviceType();
deviceType.setName(deviceIdentifier.getType());
deviceManagementService = getDeviceManagementService();
try {
device = deviceManagementService.getDevice(deviceIdentifier);
@ -147,4 +147,8 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
return finalPolicies;
}
private DeviceManagementService getDeviceManagementService() {
return PolicyManagementDataHolder.getInstance().getDeviceManagementService();
}
}

@ -23,13 +23,12 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
import org.wso2.carbon.policy.mgt.core.config.PolicyConfigurationManager;
import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig;
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.service.PolicyManagementService;
import org.wso2.carbon.user.core.service.RealmService;
/**
@ -40,12 +39,6 @@ import org.wso2.carbon.user.core.service.RealmService;
* policy="dynamic"
* bind="setRealmService"
* unbind="unsetRealmService"
* @scr.reference name="org.wso2.carbon.devicemgt.policy.information.point.default"
* interface="org.wso2.carbon.policy.mgt.common.PolicyInformationPoint"
* cardinality="1..1"
* policy="dynamic"
* bind="setPIPService"
* unbind="unsetPIPService"
* @scr.reference name="org.wso2.carbon.devicemgt.simple.policy.evaluation.manager"
* interface="org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint"
* cardinality="1..1"
@ -59,7 +52,7 @@ import org.wso2.carbon.user.core.service.RealmService;
* bind="setDeviceManagementService"
* unbind="unsetDeviceManagementService"
*/
@SuppressWarnings("unused")
public class PolicyManagementServiceComponent {
private static Log log = LogFactory.getLog(PolicyManagementServiceComponent.class);
@ -73,11 +66,10 @@ public class PolicyManagementServiceComponent {
PolicyManagementDAOFactory.init(dsConfig);
componentContext.getBundleContext().registerService(
PolicyManagerService.class.getName(), new PolicyManagementService(), null);
PolicyManagerService.class.getName(), new PolicyManagerServiceImpl(), null);
} catch (Throwable t) {
String msg = "Error occurred while initializing the Policy management core.";
log.error(msg, t);
log.error("Error occurred while initializing the Policy management core.", t);
}
}
@ -108,7 +100,7 @@ public class PolicyManagementServiceComponent {
}
protected void setPIPService(PolicyInformationPoint pipService) {
/* protected void setPIPService(PolicyInformationPoint pipService) {
if (log.isDebugEnabled()) {
log.debug("Setting Policy Information Service");
}
@ -120,7 +112,7 @@ public class PolicyManagementServiceComponent {
log.debug("Unsetting Policy Information Service");
}
PolicyManagementDataHolder.getInstance().setPolicyInformationPoint(null);
}
}*/
protected void setPEPService(PolicyEvaluationPoint pepService) {

@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.dto.Device;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import java.util.List;
@ -33,7 +34,8 @@ public interface PolicyManager {
boolean deletePolicy(Policy policy) throws PolicyManagementException;
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException;
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws
PolicyManagementException;
Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagementException;
@ -54,4 +56,11 @@ public interface PolicyManager {
List<Policy> getPoliciesOfUser(String username) throws PolicyManagementException;
List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException;
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws
PolicyManagementException;
boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
}

@ -27,11 +27,10 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dto.Device;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.dao.*;
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
import java.util.ArrayList;
import java.util.List;
@ -43,6 +42,7 @@ public class PolicyManagerImpl implements PolicyManager {
private FeatureDAO featureDAO;
private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO;
private ProfileManager profileManager;
private static Log log = LogFactory.getLog(PolicyManagerImpl.class);
public PolicyManagerImpl() {
@ -51,6 +51,7 @@ public class PolicyManagerImpl implements PolicyManager {
this.featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.profileManager = new ProfileManagerImpl();
}
@Override
@ -462,13 +463,16 @@ public class PolicyManagerImpl implements PolicyManager {
List<Policy> policies = new ArrayList<Policy>();
try {
DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName);
List<Profile> profileList = profileDAO.getProfilesOfDeviceType(deviceType);
// DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName);
List<Profile> profileList = profileManager.getProfilesOfDeviceType(deviceTypeName);
List<Policy> allPolicies = policyDAO.getAllPolicies();
for (Profile profile : profileList) {
for (Policy policy : allPolicies) {
if (policy.getProfileId() == profile.getProfileId()) {
policy.setProfile(profile);
policies.add(policy);
}
}
@ -478,12 +482,16 @@ public class PolicyManagerImpl implements PolicyManager {
String msg = "Error occurred while getting all the policies.";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (ProfileManagerDAOException e) {
String msg = "Error occurred while getting the profiles related to device type (" + deviceTypeName + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while getting device type object related to (" + deviceTypeName + ")";
// } catch (ProfileManagerDAOException e) {
// String msg = "Error occurred while getting the profiles related to device type (" + deviceTypeName + ")";
// log.error(msg, e);
// throw new PolicyManagementException(msg, e);
// } catch (DeviceManagementDAOException e) {
// String msg = "Error occurred while getting device type object related to (" + deviceTypeName + ")";
// log.error(msg, e);
// throw new PolicyManagementException(msg, e);
} catch (ProfileManagementException e) {
String msg = "Error occurred while getting all the profile features.";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
@ -565,4 +573,75 @@ public class PolicyManagerImpl implements PolicyManager {
}
return deviceList;
}
@Override
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws
PolicyManagementException {
int deviceId = -1;
try {
Device device = deviceDAO.getDevice(deviceIdentifier);
deviceId = device.getId();
boolean exist = policyDAO.checkPolicyAvailable(deviceId);
PolicyManagementDAOFactory.beginTransaction();
if (exist) {
policyDAO.updateEffectivePolicyToDevice(deviceId, policyId, profileFeatures);
} else {
policyDAO.addEffectivePolicyToDevice(deviceId, policyId, profileFeatures);
}
PolicyManagementDAOFactory.commitTransaction();
} catch (PolicyManagerDAOException e) {
try {
PolicyManagementDAOFactory.rollbackTransaction();
} catch (PolicyManagerDAOException e1) {
log.warn("Error occurred while roll backing the transaction.");
}
String msg = "Error occurred while adding the evaluated policy to device (" +
deviceId + " - " + policyId + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while getting the device details (" + deviceIdentifier.getId() + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
}
@Override
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
boolean exist;
try {
Device device = deviceDAO.getDevice(deviceIdentifier);
exist = policyDAO.checkPolicyAvailable(device.getId());
} catch (PolicyManagerDAOException e) {
String msg = "Error occurred while checking whether device has a policy to apply.";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while getting the device details (" + deviceIdentifier.getId() + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
return exist;
}
@Override
public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
try {
Device device = deviceDAO.getDevice(deviceIdentifier);
policyDAO.setPolicyApplied(device.getId());
return true;
} catch (PolicyManagerDAOException e) {
String msg = "Error occurred while setting the policy has applied to device (" +
deviceIdentifier.getId() + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while getting the device details (" + deviceIdentifier.getId() + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
}
}

@ -64,13 +64,19 @@ public class PolicyManagementService implements PolicyManagerService {
return policyManagerService.updatePolicy(policy);
}
@Override
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
return policyManagerService.deletePolicy(policy);
}
@Override
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
return policyManagerService.getEffectivePolicy(deviceIdentifier);
}
@Override
public Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException {
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws
FeatureManagementException {
return policyManagerService.getEffectiveFeatures(deviceIdentifier);
}
@ -93,4 +99,9 @@ public class PolicyManagementService implements PolicyManagerService {
public PolicyInformationPoint getPIP() throws PolicyManagementException {
return policyManagerService.getPIP();
}
@Override
public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
return policyManagerService.getPEP();
}
}

@ -21,10 +21,12 @@ package org.wso2.carbon.policy.mgt.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import javax.sql.DataSource;
import javax.xml.parsers.DocumentBuilder;
@ -82,4 +84,23 @@ public class PolicyManagerUtil {
}
return dataSource;
}
public static int getTenantId() {
//TODO: Get the tenant id proper way. This is has to be fix for test to run.
int tenantId;
tenantId = MultitenantConstants.SUPER_TENANT_ID;
/* try {
if (PrivilegedCarbonContext.getThreadLocalCarbonContext() != null) {
tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
} else {
tenantId = MultitenantConstants.SUPER_TENANT_ID;
}
} catch (Exception e) {
}*/
return tenantId;
}
}

@ -235,7 +235,7 @@ public class PolicyDAOTestCase {
List<DeviceIdentifier> deviceIdentifierList = new ArrayList<DeviceIdentifier>();
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(device.getDeviceIdentificationId());
deviceIdentifier.setType("ANDROID");
deviceIdentifier.setType("android");
deviceIdentifierList.add(deviceIdentifier);
policyManager.addPolicyToDevice(deviceIdentifierList, policy);
@ -266,7 +266,7 @@ public class PolicyDAOTestCase {
public void getDeviceTypeRelatedPolicy() throws PolicyManagementException {
PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl();
List<Policy> policyList = policyAdministratorPoint.getPoliciesOfDeviceType("ANDROID");
List<Policy> policyList = policyAdministratorPoint.getPoliciesOfDeviceType("android");
log.debug("----------Device type related policy---------");

@ -25,7 +25,7 @@ public class DeviceTypeCreator {
public static DeviceType getDeviceType(){
DeviceType deviceType = new DeviceType();
deviceType.setName("ANDROID");
deviceType.setName("android");
deviceType.setId(1);
return deviceType;

@ -32,7 +32,7 @@ public class ProfileCreator {
DeviceType deviceType = new DeviceType();
deviceType.setId(1);
deviceType.setName("ANDROID");
deviceType.setName("android");
profile.setProfileFeaturesList(ProfileFeatureCreator.getProfileFeature(features));
profile.setProfileName("Test Profile");

@ -142,7 +142,7 @@ CREATE TABLE IF NOT EXISTS DM_FEATURES (
CODE VARCHAR(45) NULL DEFAULT NULL ,
DEVICE_TYPE_ID INT NOT NULL ,
DESCRIPTION TEXT NULL DEFAULT NULL ,
EVALUVATION_RULE VARCHAR(60) NOT NULL ,
EVALUATION_RULE VARCHAR(60) NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT DM_FEATURES_DEVICE_TYPE
FOREIGN KEY (DEVICE_TYPE_ID )

@ -154,7 +154,7 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` (
`CODE` VARCHAR(45) NULL DEFAULT NULL ,
`DEVICE_TYPE_ID` INT NOT NULL ,
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
`EVALUVATION_RULE` VARCHAR(60) NOT NULL ,
`EVALUATION_RULE` VARCHAR(60) NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `DM_FEATURES_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) ,
CONSTRAINT `DM_FEATURES_DEVICE_TYPE`
@ -286,6 +286,36 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_USER_POLICY` (
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` ;
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` (
`ID` INT NOT NULL AUTO_INCREMENT ,
`DEVICE_ID` INT NOT NULL ,
`POLICY_ID` INT NOT NULL ,
`POLICY_CONTENT` BLOB NULL ,
`APPLIED` TINYINT(1) NULL ,
`CREATED_TIME` TIMESTAMP NULL ,
`UPDATED_TIME` TIMESTAMP NULL ,
`APPLIED_TIME` TIMESTAMP NULL ,
PRIMARY KEY (`ID`) ,
INDEX `FK_DM_POLICY_DEVCIE_APPLIED` (`DEVICE_ID` ASC) ,
INDEX `FK_DM_POLICY_DEVICE_APPLIED_POLICY` (`POLICY_ID` ASC) ,
CONSTRAINT `FK_DM_POLICY_DEVCIE_APPLIED`
FOREIGN KEY (`DEVICE_ID` )
REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_DM_POLICY_DEVICE_APPLIED_POLICY`
FOREIGN KEY (`POLICY_ID` )
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

@ -19,10 +19,10 @@
<DeviceMgtTestDBConfigurations>
<DBType typeName="MySql">
<connectionurl>jdbc:mysql://10.100.0.47:3306/WSO2CDM</connectionurl>
<connectionurl>jdbc:mysql://localhost:3306/WSO2CDM</connectionurl>
<driverclass>com.mysql.jdbc.Driver</driverclass>
<userName>root</userName>
<pwd>root</pwd>
<pwd></pwd>
</DBType>
<DBType typeName="H2">
<connectionurl>jdbc:h2:mem:WSO2_TEST_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000</connectionurl>

@ -35,7 +35,7 @@ public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint {
}
@Override
public Policy getEffectivePolicies(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
return evaluation.getEffectivePolicy(deviceIdentifier);
}

@ -25,7 +25,7 @@ import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
public interface SimpleEvaluation {
void sortPolicy() throws PolicyEvaluationException;
void sortPolicies() throws PolicyEvaluationException;
Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException;

@ -21,47 +21,62 @@ package org.wso2.carbon.simple.policy.decision.point;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.PIPDevice;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.simple.policy.decision.point.internal.PolicyDecisionPointDataHolder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SimpleEvaluationImpl implements SimpleEvaluation {
private static final Log log = LogFactory.getLog(SimpleEvaluationImpl.class);
//TODO : to revove the stale reference
private PolicyManagerService policyManagerService;
private List<Policy> policyList;
private List<Policy> policyList = new ArrayList<Policy>();
public SimpleEvaluationImpl() {
policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
}
// public SimpleEvaluationImpl() {
// policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
// }
@Override
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
Policy policy = new Policy();
PolicyAdministratorPoint policyAdministratorPoint;
PolicyInformationPoint policyInformationPoint;
policyManagerService = getPolicyManagerService();
try {
if (policyManagerService == null && policyList == null) {
PIPDevice pipDevice = policyManagerService.getPIP().getDeviceData(deviceIdentifier);
policyList = policyManagerService.getPIP().getRelatedPolicies(pipDevice);
if (policyManagerService != null) {
policyInformationPoint = policyManagerService.getPIP();
PIPDevice pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier);
policyList = policyInformationPoint.getRelatedPolicies(pipDevice);
sortPolicies();
policy = policyList.get(0);
policyAdministratorPoint = policyManagerService.getPAP();
policyAdministratorPoint.setPolicyUsed(deviceIdentifier, policy);
}
sortPolicy();
} catch (PolicyManagementException e) {
String msg = "Error occurred when retrieving the policy related data from policy management service.";
log.error(msg, e);
throw new PolicyEvaluationException(msg, e);
}
return policyList.get(0);
return policy;
}
@Override
public void sortPolicy() throws PolicyEvaluationException {
public void sortPolicies() throws PolicyEvaluationException {
Collections.sort(policyList);
}
private PolicyManagerService getPolicyManagerService(){
return PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
}
}

Loading…
Cancel
Save