Update MDM admin content from product-emm

revert-dabc3590
charithag 9 years ago
parent 6e981fb2c7
commit 8c6690a597

@ -18,6 +18,7 @@
package org.wso2.carbon.mdm.api; package org.wso2.carbon.mdm.api;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException; import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
@ -29,19 +30,13 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.mdm.api.common.MDMAPIException; import org.wso2.carbon.mdm.api.common.MDMAPIException;
import org.wso2.carbon.mdm.api.util.MDMAPIUtils; import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
import org.wso2.carbon.mdm.api.util.ResponsePayload;
import org.wso2.carbon.mdm.beans.EnrollmentCertificate; import org.wso2.carbon.mdm.beans.EnrollmentCertificate;
import org.wso2.carbon.mdm.exception.*;
import org.wso2.carbon.mdm.exception.BadRequestException; import org.wso2.carbon.mdm.exception.BadRequestException;
import org.wso2.carbon.mdm.exception.Message; import org.wso2.carbon.mdm.util.MDMUtil;
import javax.ws.rs.Consumes; import javax.ws.rs.*;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
@ -50,8 +45,7 @@ import java.util.List;
/** /**
* All the certificate related tasks such as saving certificates, can be done through this endpoint. * All the certificate related tasks such as saving certificates, can be done through this endpoint.
*/ */
@SuppressWarnings("NonJaxWsWebServices") @Produces({ "application/json", "application/xml" })
@Produces({"application/json", "application/xml" })
@Consumes({ "application/json", "application/xml" }) @Consumes({ "application/json", "application/xml" })
public class Certificate { public class Certificate {
@ -71,7 +65,8 @@ public class Certificate {
EnrollmentCertificate[] enrollmentCertificates) throws MDMAPIException { EnrollmentCertificate[] enrollmentCertificates) throws MDMAPIException {
MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader); MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader);
CertificateManagementService certificateService; CertificateManagementService certificateService;
List<org.wso2.carbon.certificate.mgt.core.bean.Certificate> certificates = new ArrayList<>(); List<org.wso2.carbon.certificate.mgt.core.bean.Certificate> certificates = new ArrayList<org.wso2.carbon
.certificate.mgt.core.bean.Certificate>();
org.wso2.carbon.certificate.mgt.core.bean.Certificate certificate; org.wso2.carbon.certificate.mgt.core.bean.Certificate certificate;
certificateService = MDMAPIUtils.getCertificateManagementService(); certificateService = MDMAPIUtils.getCertificateManagementService();
try { try {
@ -184,9 +179,9 @@ public class Certificate {
try { try {
deleted = certificateService.removeCertificate(serialNumber); deleted = certificateService.removeCertificate(serialNumber);
if(deleted){ if(deleted){
return Response.status(Response.Status.OK).entity(true).type(responseMediaType).build(); return Response.status(Response.Status.OK).entity(deleted).type(responseMediaType).build();
} else { } else {
return Response.status(Response.Status.GONE).entity(false).type(responseMediaType).build(); return Response.status(Response.Status.GONE).entity(deleted).type(responseMediaType).build();
} }
} catch (CertificateManagementDAOException e) { } catch (CertificateManagementDAOException e) {
String msg = "Error occurred while converting PEM file to X509Certificate"; String msg = "Error occurred while converting PEM file to X509Certificate";

@ -79,7 +79,7 @@ public class Configuration {
configurationEntry.setValue(PolicyManagerUtil.getMonitoringFequency()); configurationEntry.setValue(PolicyManagerUtil.getMonitoringFequency());
List<ConfigurationEntry> configList = tenantConfiguration.getConfiguration(); List<ConfigurationEntry> configList = tenantConfiguration.getConfiguration();
if (configList == null) { if (configList == null) {
configList = new ArrayList<>(); configList = new ArrayList<ConfigurationEntry>();
} }
configList.add(configurationEntry); configList.add(configurationEntry);
tenantConfiguration.setConfiguration(configList); tenantConfiguration.setConfiguration(configList);

@ -0,0 +1,83 @@
/*
* Copyright (c) 2016, 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.mdm.api;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.mdm.api.common.MDMAPIException;
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
public class DeviceInformation {
private static Log log = LogFactory.getLog(DeviceInformation.class);
@GET
@Path("{type}/{id}")
public Response getDeviceInfo(@PathParam("type") String type, @PathParam("id") String id) throws MDMAPIException {
DeviceInformationManager informationManager;
DeviceInfo deviceInfo;
try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(id);
deviceIdentifier.setType(type);
informationManager = MDMAPIUtils.getDeviceInformationManagerService();
deviceInfo = informationManager.getDeviceInfo(deviceIdentifier);
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device information.";
log.error(msg, e);
throw new MDMAPIException(msg, e);
}
return Response.status(HttpStatus.SC_OK).entity(deviceInfo).build();
}
@GET
@Path("location/{type}/{id}")
public Response getDeviceLocation(@PathParam("type") String type, @PathParam("id") String id) throws MDMAPIException {
DeviceInformationManager informationManager;
DeviceLocation deviceLocation;
try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(id);
deviceIdentifier.setType(type);
informationManager = MDMAPIUtils.getDeviceInformationManagerService();
deviceLocation = informationManager.getDeviceLocation(deviceIdentifier);
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device location.";
log.error(msg, e);
throw new MDMAPIException(msg, e);
}
return Response.status(HttpStatus.SC_OK).entity(deviceLocation).build();
}
}

@ -0,0 +1,56 @@
/*
* Copyright (c) 2016, 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.mdm.api;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
import org.wso2.carbon.mdm.api.common.MDMAPIException;
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
import javax.ws.rs.GET;
import javax.ws.rs.core.Response;
import java.util.List;
public class DeviceSearch {
private static Log log = LogFactory.getLog(DeviceSearch.class);
@GET
public Response getDeviceInfo(SearchContext searchContext) throws MDMAPIException {
SearchManagerService searchManagerService;
List<DeviceWrapper> devices;
try {
searchManagerService = MDMAPIUtils.getSearchManagerService();
devices = searchManagerService.search(searchContext);
} catch (SearchMgtException e) {
String msg = "Error occurred while searching the device information.";
log.error(msg, e);
throw new MDMAPIException(msg, e);
}
return Response.status(HttpStatus.SC_OK).entity(devices).build();
}
}

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
@ -15,6 +15,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.wso2.carbon.mdm.api; package org.wso2.carbon.mdm.api;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -39,7 +40,7 @@ public class Feature {
* Get all features for Mobile Device Type * Get all features for Mobile Device Type
* *
* @return Feature * @return Feature
* @throws org.wso2.carbon.mdm.api.common.MDMAPIException * @throws MDMAPIException
* *
*/ */
@GET @GET

@ -133,7 +133,7 @@ public class MobileDevice {
* @param user User Name * @param user User Name
* @param tenantDomain tenant domain * @param tenantDomain tenant domain
* @return Device * @return Device
* @throws org.wso2.carbon.mdm.api.common.MDMAPIException * @throws MDMAPIException
*/ */
@GET @GET
@Path("user/{user}/{tenantDomain}") @Path("user/{user}/{tenantDomain}")
@ -184,7 +184,7 @@ public class MobileDevice {
public List<Device> getDevicesByName(@PathParam("name") String deviceName, public List<Device> getDevicesByName(@PathParam("name") String deviceName,
@PathParam("tenantDomain") String tenantDomain) throws MDMAPIException { @PathParam("tenantDomain") String tenantDomain) throws MDMAPIException {
List<org.wso2.carbon.device.mgt.common.Device> devices; List<Device> devices;
try { try {
devices = MDMAPIUtils.getDeviceManagementService().getDevicesByName(deviceName); devices = MDMAPIUtils.getDeviceManagementService().getDevicesByName(deviceName);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {

@ -49,7 +49,7 @@ public class Role {
* Get user roles (except all internal roles) from system. * Get user roles (except all internal roles) from system.
* *
* @return A list of users * @return A list of users
* @throws org.wso2.carbon.mdm.api.common.MDMAPIException * @throws MDMAPIException
*/ */
@GET @GET
@Produces ({MediaType.APPLICATION_JSON}) @Produces ({MediaType.APPLICATION_JSON})
@ -85,7 +85,7 @@ public class Role {
* Get user roles by user store(except all internal roles) from system. * Get user roles by user store(except all internal roles) from system.
* *
* @return A list of users * @return A list of users
* @throws org.wso2.carbon.mdm.api.common.MDMAPIException * @throws MDMAPIException
*/ */
@GET @GET
@Path ("{userStore}") @Path ("{userStore}")
@ -122,7 +122,7 @@ public class Role {
* Get user roles by providing a filtering criteria(except all internal roles & system roles) from system. * Get user roles by providing a filtering criteria(except all internal roles & system roles) from system.
* *
* @return A list of users * @return A list of users
* @throws org.wso2.carbon.mdm.api.common.MDMAPIException * @throws MDMAPIException
*/ */
@GET @GET
@Path ("search") @Path ("search")
@ -205,7 +205,7 @@ public class Role {
* Get user role of the system * Get user role of the system
* *
* @return user role * @return user role
* @throws org.wso2.carbon.mdm.api.common.MDMAPIException * @throws MDMAPIException
*/ */
@GET @GET
@Path("role") @Path("role")

@ -30,6 +30,8 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfigurationManagementService; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfigurationManagementService;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.mdm.api.common.MDMAPIException; import org.wso2.carbon.mdm.api.common.MDMAPIException;
import org.wso2.carbon.ntask.core.TaskManager; import org.wso2.carbon.ntask.core.TaskManager;
@ -282,4 +284,30 @@ public class MDMAPIUtils {
return responseMediaType; return responseMediaType;
} }
public static DeviceInformationManager getDeviceInformationManagerService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
DeviceInformationManager deviceInformationManager =
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
if (deviceInformationManager == null) {
String msg = "Device information Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return deviceInformationManager;
}
public static SearchManagerService getSearchManagerService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
SearchManagerService searchManagerService =
(SearchManagerService) ctx.getOSGiService(SearchManagerService.class, null);
if (searchManagerService == null) {
String msg = "Device search manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return searchManagerService;
}
} }

@ -15,6 +15,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.wso2.carbon.mdm.api.util; package org.wso2.carbon.mdm.api.util;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
@ -54,21 +55,21 @@ public class ResponsePayload {
this.responseContent = responseContent; this.responseContent = responseContent;
} }
private ResponsePayload.ResponsePayloadBuilder getBuilder() { private ResponsePayloadBuilder getBuilder() {
return new ResponsePayload.ResponsePayloadBuilder(); return new ResponsePayloadBuilder();
} }
public static ResponsePayload.ResponsePayloadBuilder statusCode(int statusCode) { public static ResponsePayloadBuilder statusCode(int statusCode) {
ResponsePayload message = new ResponsePayload(); ResponsePayload message = new ResponsePayload();
return message.getBuilder().statusCode(statusCode); return message.getBuilder().statusCode(statusCode);
} }
public static ResponsePayload.ResponsePayloadBuilder messageFromServer(String messageFromServer) { public static ResponsePayloadBuilder messageFromServer(String messageFromServer) {
ResponsePayload message = new ResponsePayload(); ResponsePayload message = new ResponsePayload();
return message.getBuilder().messageFromServer(messageFromServer); return message.getBuilder().messageFromServer(messageFromServer);
} }
public static ResponsePayload.ResponsePayloadBuilder responseContent(String responseContent) { public static ResponsePayloadBuilder responseContent(String responseContent) {
ResponsePayload message = new ResponsePayload(); ResponsePayload message = new ResponsePayload();
return message.getBuilder().responseContent(responseContent); return message.getBuilder().responseContent(responseContent);
} }

@ -772,6 +772,25 @@
</Permission> </Permission>
<!-- End of Profile related APIs --> <!-- End of Profile related APIs -->
<!--Start of the device search and information -->
<Permission>
<name>Device Information</name>
<path>/device-mgt/emm-admin/information/get</path>
<url>/information/*/*</url>
<method>GET</method>
</Permission>
<Permission>
<name>Device Search</name>
<path>/device-mgt/emm-admin/search</path>
<url>/information/*</url>
<method>GET</method>
</Permission>
<!--End of the device search and information -->
<!-- License related APIs --> <!-- License related APIs -->
<!--<Permission>--> <!--<Permission>-->
<!--<name>Get license</name>--> <!--<name>Get license</name>-->

@ -123,6 +123,26 @@
<ref bean="errorHandler"/> <ref bean="errorHandler"/>
</jaxrs:providers> </jaxrs:providers>
</jaxrs:server> </jaxrs:server>
<jaxrs:server id="informationService" address="/information">
<jaxrs:serviceBeans>
<ref bean="informationServiceBean"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="errorHandler"/>
</jaxrs:providers>
</jaxrs:server>
<jaxrs:server id="searchService" address="/search">
<jaxrs:serviceBeans>
<ref bean="searchingServiceBean"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="errorHandler"/>
</jaxrs:providers>
</jaxrs:server>
<!-- <!--
<jaxrs:server id="authenticationService" address="/authentication"> <jaxrs:server id="authenticationService" address="/authentication">
<jaxrs:serviceBeans> <jaxrs:serviceBeans>
@ -143,6 +163,10 @@
<bean id="notificationServiceBean" class="org.wso2.carbon.mdm.api.DeviceNotification"/> <bean id="notificationServiceBean" class="org.wso2.carbon.mdm.api.DeviceNotification"/>
<bean id="licenseServiceBean" class="org.wso2.carbon.mdm.api.License"/> <bean id="licenseServiceBean" class="org.wso2.carbon.mdm.api.License"/>
<bean id="certificateServiceBean" class="org.wso2.carbon.mdm.api.Certificate"/> <bean id="certificateServiceBean" class="org.wso2.carbon.mdm.api.Certificate"/>
<bean id="informationServiceBean" class="org.wso2.carbon.mdm.api.DeviceInformation"/>
<bean id="searchingServiceBean" class="org.wso2.carbon.mdm.api.DeviceSearch"/>
<!-- <!--
<bean id="authenticationServiceBean" class="org.wso2.carbon.mdm.api.Authentication"/> <bean id="authenticationServiceBean" class="org.wso2.carbon.mdm.api.Authentication"/>
--> -->

Loading…
Cancel
Save