mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
993a387e7c
212
components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
Normal file
212
components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>device-mgt</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.api</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<name>WSO2 Carbon - Mobile Device Management API</name>
|
||||||
|
<description>WSO2 Carbon - Mobile Device Management API</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.7</source>
|
||||||
|
<target>1.7</target>
|
||||||
|
</configuration>
|
||||||
|
<version>2.3.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
<configuration>
|
||||||
|
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
|
||||||
|
<warName>mdm-admin</warName>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>deploy</id>
|
||||||
|
<build>
|
||||||
|
<defaultGoal>compile</defaultGoal>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<tasks>
|
||||||
|
<copy todir="${basedir}/../../../repository/deployment/server/webapps"
|
||||||
|
overwrite="true">
|
||||||
|
<fileset dir="${basedir}/target">
|
||||||
|
<include name="mdm-admin.war"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
</tasks>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>client</id>
|
||||||
|
<build>
|
||||||
|
<defaultGoal>test</defaultGoal>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>java</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-transports-http</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-httpclient.wso2</groupId>
|
||||||
|
<artifactId>commons-httpclient</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>jsr311-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.commons</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.user.mgt</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
|
<artifactId>axis2-client</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
|
<artifactId>axis2-client</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.identity</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.identity.oauth.stub</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
|
<artifactId>axis2-client</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec.wso2</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.api;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authentication related REST-API implementation.
|
||||||
|
*/
|
||||||
|
@Produces({ "application/json", "application/xml" })
|
||||||
|
@Consumes({ "application/json", "application/xml" })
|
||||||
|
public class Authentication {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(Authentication.class);
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
* 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.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
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.exception.*;
|
||||||
|
import org.wso2.carbon.mdm.exception.BadRequestException;
|
||||||
|
import org.wso2.carbon.mdm.util.MDMUtil;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All the certificate related tasks such as saving certificates, can be done through this endpoint.
|
||||||
|
*/
|
||||||
|
@Produces({ "application/json", "application/xml" })
|
||||||
|
@Consumes({ "application/json", "application/xml" })
|
||||||
|
public class Certificate {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(Operation.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save a list of certificates and relevant information in the database.
|
||||||
|
*
|
||||||
|
* @param enrollmentCertificates List of all the certificates which includes the tenant id, certificate as
|
||||||
|
* a pem and a serial number.
|
||||||
|
* @return Status of the data persist operation.
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("saveCertificate")
|
||||||
|
public Response saveCertificate(@HeaderParam("Accept") String acceptHeader,
|
||||||
|
EnrollmentCertificate[] enrollmentCertificates) throws MDMAPIException {
|
||||||
|
MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader);
|
||||||
|
CertificateManagementService certificateService;
|
||||||
|
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;
|
||||||
|
certificateService = MDMAPIUtils.getCertificateManagementService();
|
||||||
|
try {
|
||||||
|
for (EnrollmentCertificate enrollmentCertificate : enrollmentCertificates) {
|
||||||
|
certificate = new org.wso2.carbon.certificate.mgt.core.bean.Certificate();
|
||||||
|
certificate.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||||
|
certificate.setSerial(enrollmentCertificate.getSerial());
|
||||||
|
certificate.setCertificate(certificateService.pemToX509Certificate(enrollmentCertificate.getPem()));
|
||||||
|
certificates.add(certificate);
|
||||||
|
}
|
||||||
|
certificateService.saveCertificate(certificates);
|
||||||
|
return Response.status(Response.Status.CREATED).entity("Added successfully.").
|
||||||
|
type(responseMediaType).build();
|
||||||
|
} catch (KeystoreException e) {
|
||||||
|
String msg = "Error occurred while converting PEM file to X509Certificate.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a certificate when the serial number is given.
|
||||||
|
*
|
||||||
|
* @param serialNumber serial of the certificate needed.
|
||||||
|
* @return certificate response.
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("{serialNumber}")
|
||||||
|
public Response getCertificate(@HeaderParam("Accept") String acceptHeader,
|
||||||
|
@PathParam("serialNumber") String serialNumber) throws MDMAPIException {
|
||||||
|
MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader);
|
||||||
|
Message message = new Message();
|
||||||
|
|
||||||
|
if (serialNumber == null || serialNumber.isEmpty()) {
|
||||||
|
message.setErrorMessage("Invalid serial number");
|
||||||
|
message.setDiscription("Serial number is missing or invalid.");
|
||||||
|
throw new BadRequestException(message, responseMediaType);
|
||||||
|
}
|
||||||
|
|
||||||
|
CertificateManagementService certificateService = MDMAPIUtils.getCertificateManagementService();
|
||||||
|
CertificateResponse certificateResponse;
|
||||||
|
try {
|
||||||
|
certificateResponse = certificateService.getCertificateBySerial(serialNumber);
|
||||||
|
if(certificateResponse != null) {
|
||||||
|
certificateResponse.setCertificate(null); //avoid sending byte array in response.
|
||||||
|
}
|
||||||
|
return Response.status(Response.Status.OK).entity(certificateResponse).type(responseMediaType).build();
|
||||||
|
} catch (KeystoreException e) {
|
||||||
|
String msg = "Error occurred while converting PEM file to X509Certificate";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.serverError().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all certificates in a paginated manner.
|
||||||
|
*
|
||||||
|
* @param startIndex index of the first record to be fetched
|
||||||
|
* @param length number of records to be fetched starting from the start index.
|
||||||
|
* @return paginated result of certificate.
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("paginate")
|
||||||
|
public Response getAllCertificates(@HeaderParam("Accept") String acceptHeader,
|
||||||
|
@QueryParam("start") int startIndex,
|
||||||
|
@QueryParam("length") int length)
|
||||||
|
throws MDMAPIException {
|
||||||
|
MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader);
|
||||||
|
Message message = new Message();
|
||||||
|
|
||||||
|
if (startIndex < 0) {
|
||||||
|
message.setErrorMessage("Invalid start index.");
|
||||||
|
message.setDiscription("Start index cannot be less that 0.");
|
||||||
|
throw new BadRequestException(message, responseMediaType);
|
||||||
|
} else if (length <= 0) {
|
||||||
|
message.setErrorMessage("Invalid length value.");
|
||||||
|
message.setDiscription("Length should be a positive integer.");
|
||||||
|
throw new BadRequestException(message, responseMediaType);
|
||||||
|
}
|
||||||
|
|
||||||
|
CertificateManagementService certificateService = MDMAPIUtils.getCertificateManagementService();
|
||||||
|
PaginationRequest paginationRequest = new PaginationRequest(startIndex, length);
|
||||||
|
try {
|
||||||
|
PaginationResult certificates = certificateService.getAllCertificates(paginationRequest);
|
||||||
|
return Response.status(Response.Status.OK).entity(certificates).type(responseMediaType).build();
|
||||||
|
} catch (CertificateManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while fetching all certificates.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("{serialNumber}")
|
||||||
|
public Response removeCertificate(@HeaderParam("Accept") String acceptHeader,
|
||||||
|
@PathParam("serialNumber") String serialNumber) throws MDMAPIException {
|
||||||
|
MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader);
|
||||||
|
Message message = new Message();
|
||||||
|
|
||||||
|
if (serialNumber == null || serialNumber.isEmpty()) {
|
||||||
|
message.setErrorMessage("Invalid serial number");
|
||||||
|
message.setDiscription("Serial number is missing or invalid.");
|
||||||
|
throw new BadRequestException(message, responseMediaType);
|
||||||
|
}
|
||||||
|
|
||||||
|
CertificateManagementService certificateService = MDMAPIUtils.getCertificateManagementService();
|
||||||
|
boolean deleted;
|
||||||
|
try {
|
||||||
|
deleted = certificateService.removeCertificate(serialNumber);
|
||||||
|
if(deleted){
|
||||||
|
return Response.status(Response.Status.OK).entity(deleted).type(responseMediaType).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.GONE).entity(deleted).type(responseMediaType).build();
|
||||||
|
}
|
||||||
|
} catch (CertificateManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while converting PEM file to X509Certificate";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.serverError().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* 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.configuration.mgt.ConfigurationEntry;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAppConstants;
|
||||||
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||||
|
|
||||||
|
import javax.jws.WebService;
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General Tenant Configuration REST-API implementation.
|
||||||
|
* All end points support JSON, XMl with content negotiation.
|
||||||
|
*/
|
||||||
|
@WebService
|
||||||
|
@Produces({ "application/json", "application/xml" })
|
||||||
|
@Consumes({ "application/json", "application/xml" })
|
||||||
|
public class Configuration {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(Configuration.class);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
public ResponsePayload saveTenantConfiguration(TenantConfiguration configuration)
|
||||||
|
throws MDMAPIException {
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
MDMAPIUtils.getTenantConfigurationManagementService().saveConfiguration(configuration,
|
||||||
|
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
||||||
|
//Schedule the task service
|
||||||
|
MDMAPIUtils.scheduleTaskService(MDMAPIUtils.getNotifierFrequency(configuration));
|
||||||
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setMessageFromServer("Tenant configuration saved successfully.");
|
||||||
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
|
return responseMsg;
|
||||||
|
} catch (ConfigurationManagementException e) {
|
||||||
|
String msg = "Error occurred while saving the tenant configuration.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
public TenantConfiguration getConfiguration() throws MDMAPIException {
|
||||||
|
String msg;
|
||||||
|
try {
|
||||||
|
TenantConfiguration tenantConfiguration = MDMAPIUtils.getTenantConfigurationManagementService().
|
||||||
|
getConfiguration(MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
||||||
|
ConfigurationEntry configurationEntry = new ConfigurationEntry();
|
||||||
|
configurationEntry.setContentType("text");
|
||||||
|
configurationEntry.setName("notifierFrequency");
|
||||||
|
configurationEntry.setValue(PolicyManagerUtil.getMonitoringFequency());
|
||||||
|
List<ConfigurationEntry> configList = tenantConfiguration.getConfiguration();
|
||||||
|
if (configList == null) {
|
||||||
|
configList = new ArrayList<ConfigurationEntry>();
|
||||||
|
}
|
||||||
|
configList.add(configurationEntry);
|
||||||
|
tenantConfiguration.setConfiguration(configList);
|
||||||
|
return tenantConfiguration;
|
||||||
|
} catch (ConfigurationManagementException e) {
|
||||||
|
msg = "Error occurred while retrieving the tenant configuration.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
public ResponsePayload updateConfiguration(TenantConfiguration configuration) throws MDMAPIException {
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
MDMAPIUtils.getTenantConfigurationManagementService().saveConfiguration(configuration,
|
||||||
|
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
||||||
|
//Schedule the task service
|
||||||
|
MDMAPIUtils.scheduleTaskService(MDMAPIUtils.getNotifierFrequency(configuration));
|
||||||
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setMessageFromServer("Tenant configuration updated successfully.");
|
||||||
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
|
return responseMsg;
|
||||||
|
} catch (ConfigurationManagementException e) {
|
||||||
|
String msg = "Error occurred while updating the tenant configuration.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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,108 @@
|
|||||||
|
/*
|
||||||
|
* 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.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.notification.mgt.NotificationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
|
||||||
|
import javax.jws.WebService;
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DeviceNotification management REST-API implementation.
|
||||||
|
* All end points support JSON, XMl with content negotiation.
|
||||||
|
*/
|
||||||
|
@WebService
|
||||||
|
@Produces({ "application/json", "application/xml" })
|
||||||
|
@Consumes({ "application/json", "application/xml" })
|
||||||
|
public class DeviceNotification {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(Configuration.class);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
public List<Notification> getNotifications() throws MDMAPIException {
|
||||||
|
String msg;
|
||||||
|
try {
|
||||||
|
return MDMAPIUtils.getNotificationManagementService().getAllNotifications();
|
||||||
|
} catch (NotificationManagementException e) {
|
||||||
|
msg = "Error occurred while retrieving the notification list.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("{status}")
|
||||||
|
public List<Notification> getNotificationsByStatus(@PathParam("status") Notification.Status status)
|
||||||
|
throws MDMAPIException {
|
||||||
|
String msg;
|
||||||
|
try {
|
||||||
|
return MDMAPIUtils.getNotificationManagementService().getNotificationsByStatus(status);
|
||||||
|
} catch (NotificationManagementException e) {
|
||||||
|
msg = "Error occurred while retrieving the notification list.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("{id}/{status}")
|
||||||
|
public ResponsePayload updateNotificationStatus(@PathParam("id") int id,
|
||||||
|
@PathParam("status") Notification.Status status)
|
||||||
|
throws MDMAPIException{
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
MDMAPIUtils.getNotificationManagementService().updateNotificationStatus(id, status);
|
||||||
|
Response.status(HttpStatus.SC_ACCEPTED);
|
||||||
|
responseMsg.setMessageFromServer("Notification status updated successfully.");
|
||||||
|
responseMsg.setStatusCode(HttpStatus.SC_ACCEPTED);
|
||||||
|
return responseMsg;
|
||||||
|
} catch (NotificationManagementException e) {
|
||||||
|
String msg = "Error occurred while updating notification status.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
public ResponsePayload addNotification(Notification notification)
|
||||||
|
throws MDMAPIException{
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
MDMAPIUtils.getNotificationManagementService().addNotification(notification);
|
||||||
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setMessageFromServer("Notification has added successfully.");
|
||||||
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
|
return responseMsg;
|
||||||
|
} catch (NotificationManagementException e) {
|
||||||
|
String msg = "Error occurred while updating notification status.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* 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.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Features
|
||||||
|
*/
|
||||||
|
@Produces({"application/json", "application/xml"})
|
||||||
|
@Consumes({"application/json", "application/xml"})
|
||||||
|
public class Feature {
|
||||||
|
private static Log log = LogFactory.getLog(Feature.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all features for Mobile Device Type
|
||||||
|
*
|
||||||
|
* @return Feature
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("/{type}")
|
||||||
|
public List<org.wso2.carbon.device.mgt.common.Feature> getFeatures(@PathParam("type") String type)
|
||||||
|
throws MDMAPIException {
|
||||||
|
List<org.wso2.carbon.device.mgt.common.Feature> features;
|
||||||
|
DeviceManagementProviderService dmService;
|
||||||
|
try {
|
||||||
|
dmService = MDMAPIUtils.getDeviceManagementService();
|
||||||
|
features = dmService.getFeatureManager(type).getFeatures();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while retrieving the list of features";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return features;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* 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.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.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents license related operations.
|
||||||
|
*/
|
||||||
|
public class License {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(License.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the license text related to a given device type and language code.
|
||||||
|
*
|
||||||
|
* @param deviceType Device type, ex: android, ios
|
||||||
|
* @param languageCode Language code, ex: en_US
|
||||||
|
* @return Returns the license text
|
||||||
|
* @throws MDMAPIException If the device type or language code arguments are not available or invalid.
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path ("{deviceType}/{languageCode}")
|
||||||
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
|
public Response getLicense(@PathParam ("deviceType") String deviceType,
|
||||||
|
@PathParam ("languageCode") String languageCode) throws MDMAPIException {
|
||||||
|
|
||||||
|
org.wso2.carbon.device.mgt.common.license.mgt.License license;
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
license = MDMAPIUtils.getDeviceManagementService().getLicense(deviceType, languageCode);
|
||||||
|
if (license == null) {
|
||||||
|
return Response.status(HttpStatus.SC_NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
responsePayload = ResponsePayload.statusCode(HttpStatus.SC_OK).
|
||||||
|
messageFromServer("License for '" + deviceType + "' was retrieved successfully").
|
||||||
|
responseContent(license.getText()).
|
||||||
|
build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while retrieving the license configured for '" + deviceType + "' device type";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to add license to a specific device type.
|
||||||
|
*
|
||||||
|
* @param deviceType Device type, ex: android, ios
|
||||||
|
* @param license License object
|
||||||
|
* @return Returns the acknowledgement for the action
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path ("{deviceType}")
|
||||||
|
public Response addLicense(@PathParam ("deviceType") String deviceType,
|
||||||
|
org.wso2.carbon.device.mgt.common.license.mgt.License license) throws MDMAPIException {
|
||||||
|
|
||||||
|
ResponsePayload responsePayload;
|
||||||
|
try {
|
||||||
|
MDMAPIUtils.getDeviceManagementService().addLicense(deviceType, license);
|
||||||
|
responsePayload = ResponsePayload.statusCode(HttpStatus.SC_OK).
|
||||||
|
messageFromServer("License added successfully for '" + deviceType + "' device type").
|
||||||
|
build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while adding license for '" + deviceType + "' device type";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,218 @@
|
|||||||
|
/*
|
||||||
|
* 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.*;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Device related operations
|
||||||
|
*/
|
||||||
|
public class MobileDevice {
|
||||||
|
private static Log log = LogFactory.getLog(MobileDevice.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all devices. We have to use accept all the necessary query parameters sent by datatable.
|
||||||
|
* Hence had to put lot of query params here.
|
||||||
|
*
|
||||||
|
* @return Device List
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
public Object getAllDevices(@QueryParam("type") String type, @QueryParam("user") String user,
|
||||||
|
@QueryParam("role") String role, @QueryParam("status") EnrolmentInfo.Status status,
|
||||||
|
@QueryParam("start") int startIdx, @QueryParam("length") int length,
|
||||||
|
@QueryParam("device-name") String deviceName,
|
||||||
|
@QueryParam("ownership") EnrolmentInfo.OwnerShip ownership
|
||||||
|
) throws MDMAPIException {
|
||||||
|
try {
|
||||||
|
DeviceManagementProviderService service = MDMAPIUtils.getDeviceManagementService();
|
||||||
|
//Length > 0 means this is a pagination request.
|
||||||
|
if (length > 0) {
|
||||||
|
PaginationRequest paginationRequest = new PaginationRequest(startIdx, length);
|
||||||
|
paginationRequest.setDeviceName(deviceName);
|
||||||
|
paginationRequest.setOwner(user);
|
||||||
|
if (ownership != null) {
|
||||||
|
paginationRequest.setOwnership(ownership.toString());
|
||||||
|
}
|
||||||
|
if (status != null) {
|
||||||
|
paginationRequest.setStatus(status.toString());
|
||||||
|
}
|
||||||
|
paginationRequest.setDeviceType(type);
|
||||||
|
return service.getAllDevices(paginationRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Device> allDevices = null;
|
||||||
|
if ((type != null) && !type.isEmpty()) {
|
||||||
|
allDevices = service.getAllDevices(type);
|
||||||
|
} else if ((user != null) && !user.isEmpty()) {
|
||||||
|
allDevices = service.getDevicesOfUser(user);
|
||||||
|
} else if ((role != null) && !role.isEmpty()) {
|
||||||
|
allDevices = service.getAllDevicesOfRole(role);
|
||||||
|
} else if (status != null) {
|
||||||
|
allDevices = service.getDevicesByStatus(status);
|
||||||
|
} else if (deviceName != null) {
|
||||||
|
allDevices = service.getDevicesByName(deviceName);
|
||||||
|
} else {
|
||||||
|
allDevices = service.getAllDevices();
|
||||||
|
}
|
||||||
|
return allDevices;
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the device list.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch device details for a given device type and device Id.
|
||||||
|
*
|
||||||
|
* @return Device wrapped inside Response
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("view")
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response getDevice(@QueryParam("type") String type,
|
||||||
|
@QueryParam("id") String id) throws MDMAPIException {
|
||||||
|
DeviceIdentifier deviceIdentifier = MDMAPIUtils.instantiateDeviceIdentifier(type, id);
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService = MDMAPIUtils.getDeviceManagementService();
|
||||||
|
Device device;
|
||||||
|
try {
|
||||||
|
device = deviceManagementProviderService.getDevice(deviceIdentifier);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String error = "Error occurred while fetching the device information.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
if (device == null) {
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND);
|
||||||
|
responsePayload.setMessageFromServer("Requested device by type: " +
|
||||||
|
type + " and id: " + id + " does not exist.");
|
||||||
|
return Response.status(HttpStatus.SC_NOT_FOUND).entity(responsePayload).build();
|
||||||
|
} else {
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Sending Requested device by type: " + type + " and id: " + id + ".");
|
||||||
|
responsePayload.setResponseContent(device);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch Android device details of a given user.
|
||||||
|
*
|
||||||
|
* @param user User Name
|
||||||
|
* @param tenantDomain tenant domain
|
||||||
|
* @return Device
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("user/{user}/{tenantDomain}")
|
||||||
|
public List<Device> getDeviceByUser(@PathParam("user") String user,
|
||||||
|
@PathParam("tenantDomain") String tenantDomain) throws MDMAPIException {
|
||||||
|
List<Device> devices;
|
||||||
|
try {
|
||||||
|
devices = MDMAPIUtils.getDeviceManagementService().getDevicesOfUser(user);
|
||||||
|
if (devices == null) {
|
||||||
|
Response.status(Response.Status.NOT_FOUND);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the devices list of given user.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current device count
|
||||||
|
*
|
||||||
|
* @return device count
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("count")
|
||||||
|
public int getDeviceCount() throws MDMAPIException {
|
||||||
|
try {
|
||||||
|
return MDMAPIUtils.getDeviceManagementService().getDeviceCount();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the device count.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of devices that matches with the given name.
|
||||||
|
*
|
||||||
|
* @param deviceName Device name
|
||||||
|
* @param tenantDomain Callee tenant domain
|
||||||
|
* @return list of devices.
|
||||||
|
* @throws MDMAPIException If some unusual behaviour is observed while fetching the device list
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("name/{name}/{tenantDomain}")
|
||||||
|
public List<Device> getDevicesByName(@PathParam("name") String deviceName,
|
||||||
|
@PathParam("tenantDomain") String tenantDomain) throws MDMAPIException {
|
||||||
|
|
||||||
|
List<Device> devices;
|
||||||
|
try {
|
||||||
|
devices = MDMAPIUtils.getDeviceManagementService().getDevicesByName(deviceName);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the devices list of device name.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of available device types.
|
||||||
|
*
|
||||||
|
* @return list of device types.
|
||||||
|
* @throws MDMAPIException If some unusual behaviour is observed while fetching the device list
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("types")
|
||||||
|
public List<DeviceType> getDeviceTypes() throws MDMAPIException {
|
||||||
|
|
||||||
|
List<DeviceType> deviceTypes;
|
||||||
|
try {
|
||||||
|
deviceTypes = MDMAPIUtils.getDeviceManagementService().getAvailableDeviceTypes();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the list of device types.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return deviceTypes;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,230 @@
|
|||||||
|
/*
|
||||||
|
* 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.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Platform;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.api.context.DeviceOperationContext;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAndroidOperationUtil;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMIOSOperationUtil;
|
||||||
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
import org.wso2.carbon.mdm.beans.ApplicationWrapper;
|
||||||
|
import org.wso2.carbon.mdm.beans.MobileApp;
|
||||||
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operation related REST-API implementation.
|
||||||
|
*/
|
||||||
|
@Produces({"application/json", "application/xml"})
|
||||||
|
@Consumes({"application/json", "application/xml"})
|
||||||
|
public class Operation {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(Operation.class);
|
||||||
|
/* @deprecated */
|
||||||
|
@GET
|
||||||
|
public List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> getAllOperations()
|
||||||
|
throws MDMAPIException {
|
||||||
|
List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> operations;
|
||||||
|
DeviceManagementProviderService dmService;
|
||||||
|
try {
|
||||||
|
dmService = MDMAPIUtils.getDeviceManagementService();
|
||||||
|
operations = dmService.getOperations(null);
|
||||||
|
} catch (OperationManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the operations for the device.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("paginate/{type}/{id}")
|
||||||
|
public PaginationResult getDeviceOperations(
|
||||||
|
@PathParam("type") String type, @PathParam("id") String id, @QueryParam("start") int startIdx,
|
||||||
|
@QueryParam("length") int length, @QueryParam("search") String search)
|
||||||
|
throws MDMAPIException {
|
||||||
|
PaginationResult operations;
|
||||||
|
DeviceManagementProviderService dmService;
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
PaginationRequest paginationRequest = new PaginationRequest(startIdx, length);
|
||||||
|
try {
|
||||||
|
deviceIdentifier.setType(type);
|
||||||
|
deviceIdentifier.setId(id);
|
||||||
|
dmService = MDMAPIUtils.getDeviceManagementService();
|
||||||
|
operations = dmService.getOperations(deviceIdentifier, paginationRequest);
|
||||||
|
} catch (OperationManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the operations for the device.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("{type}/{id}")
|
||||||
|
public List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> getDeviceOperations(
|
||||||
|
@PathParam("type") String type, @PathParam("id") String id)
|
||||||
|
throws MDMAPIException {
|
||||||
|
List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> operations;
|
||||||
|
DeviceManagementProviderService dmService;
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
try {
|
||||||
|
deviceIdentifier.setType(type);
|
||||||
|
deviceIdentifier.setId(id);
|
||||||
|
dmService = MDMAPIUtils.getDeviceManagementService();
|
||||||
|
operations = dmService.getOperations(deviceIdentifier);
|
||||||
|
} catch (OperationManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the operations for the device.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @deprecated */
|
||||||
|
@POST
|
||||||
|
public ResponsePayload addOperation(DeviceOperationContext operationContext) throws MDMAPIException {
|
||||||
|
DeviceManagementProviderService dmService;
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
dmService = MDMAPIUtils.getDeviceManagementService();
|
||||||
|
int operationId = dmService.addOperation(operationContext.getOperation(),
|
||||||
|
operationContext.getDevices());
|
||||||
|
if (operationId>0) {
|
||||||
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setMessageFromServer("Operation has added successfully.");
|
||||||
|
}
|
||||||
|
return responseMsg;
|
||||||
|
} catch (OperationManagementException e) {
|
||||||
|
String msg = "Error occurred while saving the operation";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("{type}/{id}/apps")
|
||||||
|
public List<? extends Application> getInstalledApps(
|
||||||
|
@PathParam("type") String type,
|
||||||
|
@PathParam("id") String id)
|
||||||
|
throws MDMAPIException {
|
||||||
|
List<Application> applications;
|
||||||
|
ApplicationManagementProviderService appManagerConnector;
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
try {
|
||||||
|
deviceIdentifier.setType(type);
|
||||||
|
deviceIdentifier.setId(id);
|
||||||
|
appManagerConnector = MDMAPIUtils.getAppManagementService();
|
||||||
|
applications = appManagerConnector.getApplicationListForDevice(deviceIdentifier);
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the apps of the device.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return applications;
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("installApp/{tenantDomain}")
|
||||||
|
public ResponsePayload installApplication(ApplicationWrapper applicationWrapper,
|
||||||
|
@PathParam("tenantDomain") String tenantDomain) throws MDMAPIException {
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
ApplicationManager appManagerConnector;
|
||||||
|
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null;
|
||||||
|
ArrayList<DeviceIdentifier> deviceIdentifiers;
|
||||||
|
try {
|
||||||
|
appManagerConnector = MDMAPIUtils.getAppManagementService();
|
||||||
|
MobileApp mobileApp = applicationWrapper.getApplication();
|
||||||
|
|
||||||
|
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
||||||
|
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
||||||
|
deviceIdentifiers = new ArrayList<DeviceIdentifier>();
|
||||||
|
|
||||||
|
if (deviceIdentifier.getType().equals(Platform.android.toString())) {
|
||||||
|
operation = MDMAndroidOperationUtil.createInstallAppOperation(mobileApp);
|
||||||
|
} else if (deviceIdentifier.getType().equals(Platform.ios.toString())) {
|
||||||
|
operation = MDMIOSOperationUtil.createInstallAppOperation(mobileApp);
|
||||||
|
}
|
||||||
|
deviceIdentifiers.add(deviceIdentifier);
|
||||||
|
}
|
||||||
|
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
||||||
|
}
|
||||||
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setMessageFromServer("Application installation request has been sent to the device.");
|
||||||
|
return responseMsg;
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
String msg = "Error occurred while saving the operation";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("uninstallApp/{tenantDomain}")
|
||||||
|
public ResponsePayload uninstallApplication(ApplicationWrapper applicationWrapper,
|
||||||
|
@PathParam("tenantDomain") String tenantDomain) throws MDMAPIException {
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
ApplicationManager appManagerConnector;
|
||||||
|
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null;
|
||||||
|
ArrayList<DeviceIdentifier> deviceIdentifiers;
|
||||||
|
try {
|
||||||
|
appManagerConnector = MDMAPIUtils.getAppManagementService();
|
||||||
|
MobileApp mobileApp = applicationWrapper.getApplication();
|
||||||
|
|
||||||
|
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
||||||
|
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
||||||
|
deviceIdentifiers = new ArrayList<DeviceIdentifier>();
|
||||||
|
|
||||||
|
if (deviceIdentifier.getType().equals(Platform.android.toString())) {
|
||||||
|
operation = MDMAndroidOperationUtil.createAppUninstallOperation(mobileApp);
|
||||||
|
} else if (deviceIdentifier.getType().equals(Platform.ios.toString())) {
|
||||||
|
operation = MDMIOSOperationUtil.createAppUninstallOperation(mobileApp);
|
||||||
|
}
|
||||||
|
deviceIdentifiers.add(deviceIdentifier);
|
||||||
|
}
|
||||||
|
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
||||||
|
}
|
||||||
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setMessageFromServer("Application removal request has been sent to the device.");
|
||||||
|
return responseMsg;
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
String msg = "Error occurred while saving the operation";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,431 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
import org.wso2.carbon.mdm.beans.PolicyWrapper;
|
||||||
|
import org.wso2.carbon.mdm.beans.PriorityUpdatedPolicyWrapper;
|
||||||
|
import org.wso2.carbon.mdm.util.MDMUtil;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Policy {
|
||||||
|
private static Log log = LogFactory.getLog(Policy.class);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("inactive-policy")
|
||||||
|
public ResponsePayload addPolicy(PolicyWrapper policyWrapper) throws MDMAPIException {
|
||||||
|
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
||||||
|
policy.setPolicyName(policyWrapper.getPolicyName());
|
||||||
|
policy.setProfileId(policyWrapper.getProfileId());
|
||||||
|
policy.setDescription(policyWrapper.getDescription());
|
||||||
|
policy.setProfile(MDMUtil.convertProfile(policyWrapper.getProfile()));
|
||||||
|
policy.setOwnershipType(policyWrapper.getOwnershipType());
|
||||||
|
policy.setRoles(policyWrapper.getRoles());
|
||||||
|
policy.setUsers(policyWrapper.getUsers());
|
||||||
|
policy.setTenantId(policyWrapper.getTenantId());
|
||||||
|
policy.setCompliance(policyWrapper.getCompliance());
|
||||||
|
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
pap.addPolicy(policy);
|
||||||
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setMessageFromServer("Policy has been added successfully.");
|
||||||
|
return responseMsg;
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Policy Management related exception";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("active-policy")
|
||||||
|
public ResponsePayload addActivePolicy(PolicyWrapper policyWrapper) throws MDMAPIException {
|
||||||
|
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
||||||
|
policy.setPolicyName(policyWrapper.getPolicyName());
|
||||||
|
policy.setProfileId(policyWrapper.getProfileId());
|
||||||
|
policy.setDescription(policyWrapper.getDescription());
|
||||||
|
policy.setProfile(MDMUtil.convertProfile(policyWrapper.getProfile()));
|
||||||
|
policy.setOwnershipType(policyWrapper.getOwnershipType());
|
||||||
|
policy.setRoles(policyWrapper.getRoles());
|
||||||
|
policy.setUsers(policyWrapper.getUsers());
|
||||||
|
policy.setTenantId(policyWrapper.getTenantId());
|
||||||
|
policy.setCompliance(policyWrapper.getCompliance());
|
||||||
|
policy.setActive(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
pap.addPolicy(policy);
|
||||||
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setMessageFromServer("Policy has been added successfully.");
|
||||||
|
return responseMsg;
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Policy Management related exception";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response getAllPolicies() throws MDMAPIException {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
List<org.wso2.carbon.policy.mgt.common.Policy> policies;
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
||||||
|
policies = policyAdministratorPoint.getPolicies();
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Policy Management related exception";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Sending all retrieved device policies.");
|
||||||
|
responsePayload.setResponseContent(policies);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
@Path("{id}")
|
||||||
|
public Response getPolicy(@PathParam("id") int policyId) throws MDMAPIException {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
final org.wso2.carbon.policy.mgt.common.Policy policy;
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
||||||
|
policy = policyAdministratorPoint.getPolicy(policyId);
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Policy Management related exception";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
if (policy == null){
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND);
|
||||||
|
responsePayload.setMessageFromServer("Policy for ID " + policyId + " not found.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Sending all retrieved device policies.");
|
||||||
|
responsePayload.setResponseContent(policy);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("count")
|
||||||
|
public int getPolicyCount() throws MDMAPIException {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
||||||
|
return policyAdministratorPoint.getPolicyCount();
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Policy Management related exception";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("{id}")
|
||||||
|
public ResponsePayload updatePolicy(PolicyWrapper policyWrapper, @PathParam("id") int policyId)
|
||||||
|
throws MDMAPIException {
|
||||||
|
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
||||||
|
policy.setPolicyName(policyWrapper.getPolicyName());
|
||||||
|
policy.setId(policyId);
|
||||||
|
policy.setProfileId(policyWrapper.getProfileId());
|
||||||
|
policy.setDescription(policyWrapper.getDescription());
|
||||||
|
policy.setProfile(MDMUtil.convertProfile(policyWrapper.getProfile()));
|
||||||
|
policy.setOwnershipType(policyWrapper.getOwnershipType());
|
||||||
|
policy.setRoles(policyWrapper.getRoles());
|
||||||
|
policy.setUsers(policyWrapper.getUsers());
|
||||||
|
policy.setTenantId(policyWrapper.getTenantId());
|
||||||
|
policy.setCompliance(policyWrapper.getCompliance());
|
||||||
|
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
pap.updatePolicy(policy);
|
||||||
|
Response.status(HttpStatus.SC_OK);
|
||||||
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setMessageFromServer("Policy has been updated successfully.");
|
||||||
|
return responseMsg;
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Policy Management related exception in policy update.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("priorities")
|
||||||
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response updatePolicyPriorities(List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies)
|
||||||
|
throws MDMAPIException {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
List<org.wso2.carbon.policy.mgt.common.Policy> policiesToUpdate =
|
||||||
|
new ArrayList<org.wso2.carbon.policy.mgt.common.Policy>(priorityUpdatedPolicies.size());
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < priorityUpdatedPolicies.size(); i++) {
|
||||||
|
org.wso2.carbon.policy.mgt.common.Policy policyObj = new org.wso2.carbon.policy.mgt.common.Policy();
|
||||||
|
policyObj.setId(priorityUpdatedPolicies.get(i).getId());
|
||||||
|
policyObj.setPriorityId(priorityUpdatedPolicies.get(i).getPriority());
|
||||||
|
policiesToUpdate.add(policyObj);
|
||||||
|
}
|
||||||
|
boolean policiesUpdated;
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
policiesUpdated = pap.updatePolicyPriorities(policiesToUpdate);
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Exception in updating policy priorities.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
if (policiesUpdated) {
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Policy Priorities successfully updated.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
} else {
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
|
responsePayload.setMessageFromServer("Policy priorities did not update. Bad Request.");
|
||||||
|
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("bulk-remove")
|
||||||
|
@Consumes("application/json")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response bulkRemovePolicy(List<Integer> policyIds) throws MDMAPIException {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
boolean policyDeleted = true;
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
for(int i : policyIds) {
|
||||||
|
org.wso2.carbon.policy.mgt.common.Policy policy = pap.getPolicy(i);
|
||||||
|
if(!pap.deletePolicy(policy)){
|
||||||
|
policyDeleted = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Exception in deleting policies.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
if (policyDeleted) {
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Policies have been successfully deleted.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
} else {
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
|
responsePayload.setMessageFromServer("Policy does not exist.");
|
||||||
|
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Produces("application/json")
|
||||||
|
@Path("activate")
|
||||||
|
public Response activatePolicy(List<Integer> policyIds) throws MDMAPIException {
|
||||||
|
try {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
for(int i : policyIds) {
|
||||||
|
pap.activatePolicy(i);
|
||||||
|
}
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Exception in activating policies.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Selected policies have been successfully activated.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Produces("application/json")
|
||||||
|
@Path("inactivate")
|
||||||
|
public Response inactivatePolicy(List<Integer> policyIds) throws MDMAPIException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
for(int i : policyIds) {
|
||||||
|
pap.inactivatePolicy(i);
|
||||||
|
}
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Exception in inactivating policies.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Selected policies have been successfully inactivated.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Produces("application/json")
|
||||||
|
@Path("apply-changes")
|
||||||
|
public Response applyChanges() throws MDMAPIException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
pap.publishChanges();
|
||||||
|
|
||||||
|
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Exception in applying changes.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Changes have been successfully updated.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("start-task/{milliseconds}")
|
||||||
|
public Response startTaskService(@PathParam("milliseconds") int monitoringFrequency) throws MDMAPIException {
|
||||||
|
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
try {
|
||||||
|
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
||||||
|
taskScheduleService.startTask(monitoringFrequency);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (PolicyMonitoringTaskException e) {
|
||||||
|
String error = "Policy Management related exception.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Policy monitoring service started successfully.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("update-task/{milliseconds}")
|
||||||
|
public Response updateTaskService(@PathParam("milliseconds") int monitoringFrequency) throws MDMAPIException {
|
||||||
|
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
try {
|
||||||
|
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
||||||
|
taskScheduleService.updateTask(monitoringFrequency);
|
||||||
|
|
||||||
|
} catch (PolicyMonitoringTaskException e) {
|
||||||
|
String error = "Policy Management related exception.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Policy monitoring service updated successfully.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("stop-task")
|
||||||
|
public Response stopTaskService() throws MDMAPIException {
|
||||||
|
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
try {
|
||||||
|
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
||||||
|
taskScheduleService.stopTask();
|
||||||
|
|
||||||
|
} catch (PolicyMonitoringTaskException e) {
|
||||||
|
String error = "Policy Management related exception.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Policy monitoring service stopped successfully.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("{type}/{id}")
|
||||||
|
public ComplianceData getComplianceDataOfDevice(@PathParam("type") String type, @PathParam("id") String id) throws
|
||||||
|
MDMAPIException {
|
||||||
|
try {
|
||||||
|
DeviceIdentifier deviceIdentifier = MDMAPIUtils.instantiateDeviceIdentifier(type, id);
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
return policyManagementService.getDeviceCompliance(deviceIdentifier);
|
||||||
|
} catch (PolicyComplianceException e) {
|
||||||
|
String error = "Error occurred while getting the compliance data.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("{type}/{id}/active-policy")
|
||||||
|
public org.wso2.carbon.policy.mgt.common.Policy getDeviceActivePolicy(@PathParam("type") String type,
|
||||||
|
@PathParam("id") String id) throws MDMAPIException {
|
||||||
|
try {
|
||||||
|
DeviceIdentifier deviceIdentifier = MDMAPIUtils.instantiateDeviceIdentifier(type, id);
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
return policyManagementService.getAppliedPolicyToDevice(deviceIdentifier);
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Error occurred while getting the current policy.";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.api;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
public class Profile {
|
||||||
|
private static Log log = LogFactory.getLog(Profile.class);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
public org.wso2.carbon.policy.mgt.common.Profile addProfile(org.wso2.carbon.policy.mgt.common.Profile profile) throws MDMAPIException {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
profile = pap.addProfile(profile);
|
||||||
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
|
return profile;
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Policy Management related exception";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@POST
|
||||||
|
@Path("{id}")
|
||||||
|
public ResponsePayload updateProfile(org.wso2.carbon.policy.mgt.common.Profile profile, @PathParam("id") String profileId)
|
||||||
|
throws MDMAPIException {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
pap.updateProfile(profile);
|
||||||
|
Response.status(HttpStatus.SC_OK);
|
||||||
|
responseMsg.setMessageFromServer("Profile has been updated successfully.");
|
||||||
|
return responseMsg;
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Policy Management related exception";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@DELETE
|
||||||
|
@Path("{id}")
|
||||||
|
public ResponsePayload deleteProfile(@PathParam("id") int profileId) throws MDMAPIException {
|
||||||
|
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
||||||
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
|
org.wso2.carbon.policy.mgt.common.Profile profile = pap.getProfile(profileId);
|
||||||
|
pap.deleteProfile(profile);
|
||||||
|
Response.status(HttpStatus.SC_OK);
|
||||||
|
responseMsg.setMessageFromServer("Profile has been deleted successfully.");
|
||||||
|
return responseMsg;
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String error = "Policy Management related exception";
|
||||||
|
log.error(error, e);
|
||||||
|
throw new MDMAPIException(error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,454 @@
|
|||||||
|
/*
|
||||||
|
* 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.CarbonConstants;
|
||||||
|
import org.wso2.carbon.base.MultitenantConstants;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
import org.wso2.carbon.mdm.beans.RoleWrapper;
|
||||||
|
import org.wso2.carbon.mdm.util.SetReferenceTransformer;
|
||||||
|
import org.wso2.carbon.user.api.*;
|
||||||
|
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
||||||
|
import org.wso2.carbon.user.mgt.UserRealmProxy;
|
||||||
|
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
||||||
|
import org.wso2.carbon.user.mgt.common.UserAdminException;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Role {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(Role.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user roles (except all internal roles) from system.
|
||||||
|
*
|
||||||
|
* @return A list of users
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
|
public Response getRoles() throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
String[] roles;
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the list of user roles");
|
||||||
|
}
|
||||||
|
roles = userStoreManager.getRoleNames();
|
||||||
|
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving the list of user roles.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
// removing all internal roles and roles created for Service-providers
|
||||||
|
List<String> filteredRoles = new ArrayList<String>();
|
||||||
|
for (String role : roles) {
|
||||||
|
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
||||||
|
filteredRoles.add(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
||||||
|
responsePayload.setResponseContent(filteredRoles);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user roles by user store(except all internal roles) from system.
|
||||||
|
*
|
||||||
|
* @return A list of users
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path ("{userStore}")
|
||||||
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
|
public Response getRoles(@PathParam ("userStore") String userStore) throws MDMAPIException {
|
||||||
|
AbstractUserStoreManager abstractUserStoreManager = (AbstractUserStoreManager) MDMAPIUtils.getUserStoreManager();
|
||||||
|
String[] roles;
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the list of user roles");
|
||||||
|
}
|
||||||
|
roles = abstractUserStoreManager.getRoleNames(userStore+"/*", -1, false, true, true);
|
||||||
|
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving the list of user roles.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
// removing all internal roles and roles created for Service-providers
|
||||||
|
List<String> filteredRoles = new ArrayList<String>();
|
||||||
|
for (String role : roles) {
|
||||||
|
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
||||||
|
filteredRoles.add(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
||||||
|
responsePayload.setResponseContent(filteredRoles);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user roles by providing a filtering criteria(except all internal roles & system roles) from system.
|
||||||
|
*
|
||||||
|
* @return A list of users
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path ("search")
|
||||||
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
|
public Response getMatchingRoles(@QueryParam ("filter") String filter) throws MDMAPIException {
|
||||||
|
AbstractUserStoreManager abstractUserStoreManager = (AbstractUserStoreManager) MDMAPIUtils.getUserStoreManager();
|
||||||
|
String[] roles;
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the list of user roles using filter : " + filter);
|
||||||
|
}
|
||||||
|
roles = abstractUserStoreManager.getRoleNames("*" + filter + "*", -1, true, true, true);
|
||||||
|
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving the list of user roles using the filter : " + filter;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
// removing all internal roles and roles created for Service-providers
|
||||||
|
List<String> filteredRoles = new ArrayList<String>();
|
||||||
|
for (String role : roles) {
|
||||||
|
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
||||||
|
filteredRoles.add(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("All matching user roles were successfully retrieved.");
|
||||||
|
responsePayload.setResponseContent(filteredRoles);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get role permissions.
|
||||||
|
*
|
||||||
|
* @return list of permissions
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path ("permissions")
|
||||||
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
|
public ResponsePayload getPermissions(@QueryParam ("rolename") String roleName) throws MDMAPIException {
|
||||||
|
final UserRealm userRealm = MDMAPIUtils.getUserRealm();
|
||||||
|
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
||||||
|
final UIPermissionNode rolePermissions;
|
||||||
|
if (userRealm instanceof org.wso2.carbon.user.core.UserRealm) {
|
||||||
|
userRealmCore = (org.wso2.carbon.user.core.UserRealm) userRealm;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
||||||
|
rolePermissions = userRealmProxy.getRolePermissions(roleName, MultitenantConstants.SUPER_TENANT_ID);
|
||||||
|
UIPermissionNode[] deviceMgtPermissions = new UIPermissionNode[2];
|
||||||
|
|
||||||
|
for (UIPermissionNode permissionNode : rolePermissions.getNodeList()) {
|
||||||
|
if (permissionNode.getResourcePath().equals("/permission/admin")) {
|
||||||
|
for (UIPermissionNode node : permissionNode.getNodeList()) {
|
||||||
|
if (node.getResourcePath().equals("/permission/admin/device-mgt")) {
|
||||||
|
deviceMgtPermissions[0] = node;
|
||||||
|
} else if (node.getResourcePath().equals("/permission/admin/login")) {
|
||||||
|
deviceMgtPermissions[1] = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rolePermissions.setNodeList(deviceMgtPermissions);
|
||||||
|
} catch (UserAdminException e) {
|
||||||
|
String msg = "Error occurred while retrieving the user role";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("All permissions retrieved");
|
||||||
|
responsePayload.setResponseContent(rolePermissions);
|
||||||
|
return responsePayload;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user role of the system
|
||||||
|
*
|
||||||
|
* @return user role
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("role")
|
||||||
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
|
public ResponsePayload getRole(@QueryParam ("rolename") String roleName) throws MDMAPIException {
|
||||||
|
final UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
final UserRealm userRealm = MDMAPIUtils.getUserRealm();
|
||||||
|
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
||||||
|
if (userRealm instanceof org.wso2.carbon.user.core.UserRealm) {
|
||||||
|
userRealmCore = (org.wso2.carbon.user.core.UserRealm) userRealm;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoleWrapper roleWrapper = new RoleWrapper();
|
||||||
|
try {
|
||||||
|
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the list of user roles");
|
||||||
|
}
|
||||||
|
if (userStoreManager.isExistingRole(roleName)) {
|
||||||
|
roleWrapper.setRoleName(roleName);
|
||||||
|
roleWrapper.setUsers(userStoreManager.getUserListOfRole(roleName));
|
||||||
|
// Get the permission nodes and hand picking only device management and login perms
|
||||||
|
final UIPermissionNode rolePermissions =
|
||||||
|
userRealmProxy.getRolePermissions(roleName, MultitenantConstants.SUPER_TENANT_ID);
|
||||||
|
UIPermissionNode[] deviceMgtPermissions = new UIPermissionNode[2];
|
||||||
|
|
||||||
|
for (UIPermissionNode permissionNode : rolePermissions.getNodeList()) {
|
||||||
|
if (permissionNode.getResourcePath().equals("/permission/admin")) {
|
||||||
|
for (UIPermissionNode node : permissionNode.getNodeList()) {
|
||||||
|
if (node.getResourcePath().equals("/permission/admin/device-mgt")) {
|
||||||
|
deviceMgtPermissions[0] = node;
|
||||||
|
} else if (node.getResourcePath().equals("/permission/admin/login")) {
|
||||||
|
deviceMgtPermissions[1] = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rolePermissions.setNodeList(deviceMgtPermissions);
|
||||||
|
ArrayList<String> permList = new ArrayList<String>();
|
||||||
|
iteratePermissions(rolePermissions, permList);
|
||||||
|
roleWrapper.setPermissionList(rolePermissions);
|
||||||
|
String[] permListAr = new String[permList.size()];
|
||||||
|
roleWrapper.setPermissions(permList.toArray(permListAr));
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving the user role";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
} catch (UserAdminException e) {
|
||||||
|
String msg = "Error occurred while retrieving the user role";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
||||||
|
responsePayload.setResponseContent(roleWrapper);
|
||||||
|
return responsePayload;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API is used to persist a new Role
|
||||||
|
*
|
||||||
|
* @param roleWrapper
|
||||||
|
* @return
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
|
public Response addRole(RoleWrapper roleWrapper) throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Persisting the role to user store");
|
||||||
|
}
|
||||||
|
Permission[] permissions = null;
|
||||||
|
if (roleWrapper.getPermissions() != null && roleWrapper.getPermissions().length > 0) {
|
||||||
|
permissions = new Permission[roleWrapper.getPermissions().length];
|
||||||
|
|
||||||
|
for (int i = 0; i < permissions.length; i++) {
|
||||||
|
String permission = roleWrapper.getPermissions()[i];
|
||||||
|
permissions[i] = new Permission(permission, CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
userStoreManager.addRole(roleWrapper.getRoleName(), roleWrapper.getUsers(), permissions);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = e.getMessage();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return Response.status(HttpStatus.SC_CREATED).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API is used to update a role Role
|
||||||
|
*
|
||||||
|
* @param roleWrapper
|
||||||
|
* @return
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
|
public Response updateRole(@QueryParam ("rolename") String roleName, RoleWrapper roleWrapper) throws
|
||||||
|
MDMAPIException {
|
||||||
|
final UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
final AuthorizationManager authorizationManager = MDMAPIUtils.getAuthorizationManager();
|
||||||
|
String newRoleName = roleWrapper.getRoleName();
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updating the role to user store");
|
||||||
|
}
|
||||||
|
if (newRoleName != null && !roleName.equals(newRoleName)) {
|
||||||
|
userStoreManager.updateRoleName(roleName, newRoleName);
|
||||||
|
}
|
||||||
|
if (roleWrapper.getUsers() != null) {
|
||||||
|
SetReferenceTransformer transformer = new SetReferenceTransformer();
|
||||||
|
transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(newRoleName)),
|
||||||
|
Arrays.asList(roleWrapper.getUsers()));
|
||||||
|
final String[] usersToAdd = (String[])
|
||||||
|
transformer.getObjectsToAdd().toArray(new String[transformer.getObjectsToAdd().size()]);
|
||||||
|
final String[] usersToDelete = (String[])
|
||||||
|
transformer.getObjectsToRemove().toArray(new String[transformer.getObjectsToRemove().size()]);
|
||||||
|
userStoreManager.updateUserListOfRole(newRoleName, usersToDelete, usersToAdd);
|
||||||
|
}
|
||||||
|
if (roleWrapper.getPermissions() != null) {
|
||||||
|
// Delete all authorizations for the current role before authorizing the permission tree
|
||||||
|
authorizationManager.clearRoleAuthorization(roleName);
|
||||||
|
if (roleWrapper.getPermissions().length > 0) {
|
||||||
|
for (int i = 0; i < roleWrapper.getPermissions().length; i++) {
|
||||||
|
String permission = roleWrapper.getPermissions()[i];
|
||||||
|
authorizationManager.authorizeRole(roleName, permission, CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = e.getMessage();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return Response.status(HttpStatus.SC_OK).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API is used to delete a role and authorizations
|
||||||
|
*
|
||||||
|
* @param roleName
|
||||||
|
* @return
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@DELETE
|
||||||
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
|
public Response deleteRole(@QueryParam ("rolename") String roleName) throws MDMAPIException {
|
||||||
|
final UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
final AuthorizationManager authorizationManager = MDMAPIUtils.getAuthorizationManager();
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Deleting the role in user store");
|
||||||
|
}
|
||||||
|
userStoreManager.deleteRole(roleName);
|
||||||
|
// Delete all authorizations for the current role before deleting
|
||||||
|
authorizationManager.clearRoleAuthorization(roleName);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while deleting the role: " + roleName;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return Response.status(HttpStatus.SC_OK).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API is used to update users of a role
|
||||||
|
*
|
||||||
|
* @param roleName
|
||||||
|
* @param userList
|
||||||
|
* @return
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
@Path ("users")
|
||||||
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
|
public Response updateUsers(@QueryParam ("rolename") String roleName, List<String> userList)
|
||||||
|
throws MDMAPIException {
|
||||||
|
final UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updating the users of a role");
|
||||||
|
}
|
||||||
|
SetReferenceTransformer transformer = new SetReferenceTransformer();
|
||||||
|
transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(roleName)),
|
||||||
|
userList);
|
||||||
|
final String[] usersToAdd = (String[])
|
||||||
|
transformer.getObjectsToAdd().toArray(new String[transformer.getObjectsToAdd().size()]);
|
||||||
|
final String[] usersToDelete = (String[])
|
||||||
|
transformer.getObjectsToRemove().toArray(new String[transformer.getObjectsToRemove().size()]);
|
||||||
|
|
||||||
|
userStoreManager.updateUserListOfRole(roleName, usersToDelete, usersToAdd);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while saving the users of the role: " + roleName;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return Response.status(HttpStatus.SC_OK).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> iteratePermissions(UIPermissionNode uiPermissionNode, ArrayList<String> list) {
|
||||||
|
for (UIPermissionNode permissionNode : uiPermissionNode.getNodeList()) {
|
||||||
|
list.add(permissionNode.getResourcePath());
|
||||||
|
if (permissionNode.getNodeList() != null && permissionNode.getNodeList().length > 0) {
|
||||||
|
iteratePermissions(permissionNode, list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to retrieve the role count of the system.
|
||||||
|
*
|
||||||
|
* @return returns the count.
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("count")
|
||||||
|
public int getRoleCount() throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
String[] roles;
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the list of user roles");
|
||||||
|
}
|
||||||
|
roles = userStoreManager.getRoleNames();
|
||||||
|
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving the list of user roles.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
// removing all internal roles and roles created for Service-providers
|
||||||
|
List<String> filteredRoles = new ArrayList<String>();
|
||||||
|
for (String role : roles) {
|
||||||
|
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
||||||
|
filteredRoles.add(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredRoles.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,763 @@
|
|||||||
|
/*
|
||||||
|
* 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.codec.binary.Base64;
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.api.util.CredentialManagementResponseBuilder;
|
||||||
|
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
import org.wso2.carbon.mdm.beans.UserCredentialWrapper;
|
||||||
|
import org.wso2.carbon.mdm.beans.UserWrapper;
|
||||||
|
import org.wso2.carbon.mdm.util.Constants;
|
||||||
|
import org.wso2.carbon.mdm.util.SetReferenceTransformer;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
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.Response;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the JAX-RS services of User related functionality.
|
||||||
|
*/
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(User.class);
|
||||||
|
private static final String ROLE_EVERYONE = "Internal/everyone";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to add user to emm-user-store.
|
||||||
|
*
|
||||||
|
* @param userWrapper Wrapper object representing input json payload
|
||||||
|
* @return {Response} Status of the request wrapped inside Response object
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response addUser(UserWrapper userWrapper) throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
|
||||||
|
// if user already exists
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User by username: " + userWrapper.getUsername() +
|
||||||
|
" already exists. Therefore, request made to add user was refused.");
|
||||||
|
}
|
||||||
|
// returning response with bad request state
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_CONFLICT);
|
||||||
|
responsePayload.
|
||||||
|
setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
||||||
|
" already exists. Therefore, request made to add user was refused.");
|
||||||
|
return Response.status(HttpStatus.SC_CONFLICT).entity(responsePayload).build();
|
||||||
|
} else {
|
||||||
|
String initialUserPassword = generateInitialUserPassword();
|
||||||
|
Map<String, String> defaultUserClaims =
|
||||||
|
buildDefaultUserClaims(userWrapper.getFirstname(), userWrapper.getLastname(),
|
||||||
|
userWrapper.getEmailAddress());
|
||||||
|
// calling addUser method of carbon user api
|
||||||
|
userStoreManager.addUser(userWrapper.getUsername(), initialUserPassword,
|
||||||
|
userWrapper.getRoles(), defaultUserClaims, null);
|
||||||
|
// invite newly added user to enroll device
|
||||||
|
inviteNewlyAddedUserToEnrollDevice(userWrapper.getUsername(), initialUserPassword);
|
||||||
|
// Outputting debug message upon successful addition of user
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User by username: " + userWrapper.getUsername() + " was successfully added.");
|
||||||
|
}
|
||||||
|
// returning response with success state
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
|
responsePayload.setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
||||||
|
" was successfully added.");
|
||||||
|
return Response.status(HttpStatus.SC_CREATED).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Exception in trying to add user by username: " + userWrapper.getUsername();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to get user information from emm-user-store.
|
||||||
|
*
|
||||||
|
* @param username User-name of the user
|
||||||
|
* @return {Response} Status of the request wrapped inside Response object
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("view")
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response getUser(@QueryParam("username") String username) throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
if (userStoreManager.isExistingUser(username)) {
|
||||||
|
UserWrapper user = new UserWrapper();
|
||||||
|
user.setUsername(username);
|
||||||
|
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
|
||||||
|
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
||||||
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
||||||
|
// Outputting debug message upon successful retrieval of user
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User by username: " + username + " was found.");
|
||||||
|
}
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("User information was retrieved successfully.");
|
||||||
|
responsePayload.setResponseContent(user);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
} else {
|
||||||
|
// Outputting debug message upon trying to remove non-existing user
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User by username: " + username + " does not exist.");
|
||||||
|
}
|
||||||
|
// returning response with bad request state
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
|
responsePayload.setMessageFromServer(
|
||||||
|
"User by username: " + username + " does not exist.");
|
||||||
|
return Response.status(HttpStatus.SC_NOT_FOUND).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Exception in trying to retrieve user by username: " + username;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update user in user store
|
||||||
|
*
|
||||||
|
* @param userWrapper Wrapper object representing input json payload
|
||||||
|
* @return {Response} Status of the request wrapped inside Response object
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response updateUser(UserWrapper userWrapper, @QueryParam("username") String username)
|
||||||
|
throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
|
||||||
|
Map<String, String> defaultUserClaims =
|
||||||
|
buildDefaultUserClaims(userWrapper.getFirstname(), userWrapper.getLastname(),
|
||||||
|
userWrapper.getEmailAddress());
|
||||||
|
if (StringUtils.isNotEmpty(userWrapper.getPassword())) {
|
||||||
|
// Decoding Base64 encoded password
|
||||||
|
byte[] decodedBytes = Base64.decodeBase64(userWrapper.getPassword());
|
||||||
|
userStoreManager.updateCredentialByAdmin(userWrapper.getUsername(),
|
||||||
|
new String(decodedBytes, "UTF-8"));
|
||||||
|
log.debug("User credential of username: " + userWrapper.getUsername() + " has been changed");
|
||||||
|
}
|
||||||
|
List<String> listofFilteredRoles = getFilteredRoles(userStoreManager, userWrapper.getUsername());
|
||||||
|
final String[] existingRoles = listofFilteredRoles.toArray(new String[listofFilteredRoles.size()]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Use the Set theory to find the roles to delete and roles to add
|
||||||
|
The difference of roles in existingRolesSet and newRolesSet needed to be deleted
|
||||||
|
new roles to add = newRolesSet - The intersection of roles in existingRolesSet and newRolesSet
|
||||||
|
*/
|
||||||
|
final TreeSet<String> existingRolesSet = new TreeSet<>();
|
||||||
|
Collections.addAll(existingRolesSet, existingRoles);
|
||||||
|
final TreeSet<String> newRolesSet = new TreeSet<>();
|
||||||
|
Collections.addAll(newRolesSet, userWrapper.getRoles());
|
||||||
|
existingRolesSet.removeAll(newRolesSet);
|
||||||
|
// Now we have the roles to delete
|
||||||
|
String[] rolesToDelete = existingRolesSet.toArray(new String[existingRolesSet.size()]);
|
||||||
|
List<String> roles = new ArrayList<>(Arrays.asList(rolesToDelete));
|
||||||
|
roles.remove(ROLE_EVERYONE);
|
||||||
|
rolesToDelete = new String[0];
|
||||||
|
// Clearing and re-initializing the set
|
||||||
|
existingRolesSet.clear();
|
||||||
|
Collections.addAll(existingRolesSet, existingRoles);
|
||||||
|
newRolesSet.removeAll(existingRolesSet);
|
||||||
|
// Now we have the roles to add
|
||||||
|
String[] rolesToAdd = newRolesSet.toArray(new String[newRolesSet.size()]);
|
||||||
|
userStoreManager.updateRoleListOfUser(userWrapper.getUsername(), rolesToDelete, rolesToAdd);
|
||||||
|
userStoreManager.setUserClaimValues(userWrapper.getUsername(), defaultUserClaims, null);
|
||||||
|
// Outputting debug message upon successful addition of user
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User by username: " + userWrapper.getUsername() + " was successfully updated.");
|
||||||
|
}
|
||||||
|
// returning response with success state
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
|
responsePayload.setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
||||||
|
" was successfully updated.");
|
||||||
|
return Response.status(HttpStatus.SC_CREATED).entity(responsePayload).build();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User by username: " + userWrapper.getUsername() +
|
||||||
|
" doesn't exists. Therefore, request made to update user was refused.");
|
||||||
|
}
|
||||||
|
// returning response with bad request state
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_CONFLICT);
|
||||||
|
responsePayload.
|
||||||
|
setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
||||||
|
" doesn't exists. Therefore, request made to update user was refused.");
|
||||||
|
return Response.status(HttpStatus.SC_CONFLICT).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
} catch (UserStoreException | UnsupportedEncodingException e) {
|
||||||
|
String msg = "Exception in trying to update user by username: " + userWrapper.getUsername();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private method to be used by addUser() to
|
||||||
|
* generate an initial user password for a user.
|
||||||
|
* This will be the password used by a user for his initial login to the system.
|
||||||
|
*
|
||||||
|
* @return {string} Initial User Password
|
||||||
|
*/
|
||||||
|
private String generateInitialUserPassword() {
|
||||||
|
int passwordLength = 6;
|
||||||
|
//defining the pool of characters to be used for initial password generation
|
||||||
|
String lowerCaseCharset = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
String upperCaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
String numericCharset = "0123456789";
|
||||||
|
Random randomGenerator = new Random();
|
||||||
|
String totalCharset = lowerCaseCharset + upperCaseCharset + numericCharset;
|
||||||
|
int totalCharsetLength = totalCharset.length();
|
||||||
|
StringBuilder initialUserPassword = new StringBuilder();
|
||||||
|
for (int i = 0; i < passwordLength; i++) {
|
||||||
|
initialUserPassword
|
||||||
|
.append(totalCharset.charAt(randomGenerator.nextInt(totalCharsetLength)));
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initial user password is created for new user: " + initialUserPassword);
|
||||||
|
}
|
||||||
|
return initialUserPassword.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to build default user claims.
|
||||||
|
*
|
||||||
|
* @param firstname First name of the user
|
||||||
|
* @param lastname Last name of the user
|
||||||
|
* @param emailAddress Email address of the user
|
||||||
|
* @return {Object} Default user claims to be provided
|
||||||
|
*/
|
||||||
|
private Map<String, String> buildDefaultUserClaims(String firstname, String lastname, String emailAddress) {
|
||||||
|
Map<String, String> defaultUserClaims = new HashMap<>();
|
||||||
|
defaultUserClaims.put(Constants.USER_CLAIM_FIRST_NAME, firstname);
|
||||||
|
defaultUserClaims.put(Constants.USER_CLAIM_LAST_NAME, lastname);
|
||||||
|
defaultUserClaims.put(Constants.USER_CLAIM_EMAIL_ADDRESS, emailAddress);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Default claim map is created for new user: " + defaultUserClaims.toString());
|
||||||
|
}
|
||||||
|
return defaultUserClaims;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to remove user from emm-user-store.
|
||||||
|
*
|
||||||
|
* @param username Username of the user
|
||||||
|
* @return {Response} Status of the request wrapped inside Response object
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@DELETE
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response removeUser(@QueryParam("username") String username) throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
if (userStoreManager.isExistingUser(username)) {
|
||||||
|
// if user already exists, trying to remove user
|
||||||
|
userStoreManager.deleteUser(username);
|
||||||
|
// Outputting debug message upon successful removal of user
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User by username: " + username + " was successfully removed.");
|
||||||
|
}
|
||||||
|
// returning response with success state
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer(
|
||||||
|
"User by username: " + username + " was successfully removed.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
} else {
|
||||||
|
// Outputting debug message upon trying to remove non-existing user
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User by username: " + username + " does not exist for removal.");
|
||||||
|
}
|
||||||
|
// returning response with bad request state
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
|
responsePayload.setMessageFromServer(
|
||||||
|
"User by username: " + username + " does not exist for removal.");
|
||||||
|
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Exception in trying to remove user by username: " + username;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get all the roles except for the internal/xxx and application/xxx
|
||||||
|
*
|
||||||
|
* @param userStoreManager User Store Manager associated with the currently logged in user
|
||||||
|
* @param username Username of the currently logged in user
|
||||||
|
* @return the list of filtered roles
|
||||||
|
* @throws UserStoreException
|
||||||
|
*/
|
||||||
|
private List<String> getFilteredRoles(UserStoreManager userStoreManager, String username)
|
||||||
|
throws UserStoreException {
|
||||||
|
String[] roleListOfUser = userStoreManager.getRoleListOfUser(username);
|
||||||
|
List<String> filteredRoles = new ArrayList<>();
|
||||||
|
for (String role : roleListOfUser) {
|
||||||
|
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
||||||
|
filteredRoles.add(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user's roles by username
|
||||||
|
*
|
||||||
|
* @param username Username of the user
|
||||||
|
* @return {Response} Status of the request wrapped inside Response object
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("roles")
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response getRoles(@QueryParam("username") String username) throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
if (userStoreManager.isExistingUser(username)) {
|
||||||
|
responsePayload.setResponseContent(Arrays.asList(getFilteredRoles(userStoreManager, username)));
|
||||||
|
// Outputting debug message upon successful removal of user
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User by username: " + username + " was successfully removed.");
|
||||||
|
}
|
||||||
|
// returning response with success state
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer(
|
||||||
|
"User roles obtained for user " + username);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
} else {
|
||||||
|
// Outputting debug message upon trying to remove non-existing user
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User by username: " + username + " does not exist for role retrieval.");
|
||||||
|
}
|
||||||
|
// returning response with bad request state
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
|
responsePayload.setMessageFromServer(
|
||||||
|
"User by username: " + username + " does not exist for role retrieval.");
|
||||||
|
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Exception in trying to retrieve roles for user by username: " + username;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of all users with all user-related info.
|
||||||
|
*
|
||||||
|
* @return A list of users
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response getAllUsers() throws MDMAPIException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the list of users with all user-related information");
|
||||||
|
}
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
List<UserWrapper> userList;
|
||||||
|
try {
|
||||||
|
String[] users = userStoreManager.listUsers("*", -1);
|
||||||
|
userList = new ArrayList<>(users.length);
|
||||||
|
UserWrapper user;
|
||||||
|
for (String username : users) {
|
||||||
|
user = new UserWrapper();
|
||||||
|
user.setUsername(username);
|
||||||
|
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
|
||||||
|
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
||||||
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
||||||
|
userList.add(user);
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving the list of users";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
int count;
|
||||||
|
count = userList.size();
|
||||||
|
responsePayload.setMessageFromServer("All users were successfully retrieved. " +
|
||||||
|
"Obtained user count: " + count);
|
||||||
|
responsePayload.setResponseContent(userList);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of all users with all user-related info.
|
||||||
|
*
|
||||||
|
* @return A list of users
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("{filter}")
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response getMatchingUsers(@PathParam("filter") String filter) throws MDMAPIException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the list of users with all user-related information using the filter : " + filter);
|
||||||
|
}
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
List<UserWrapper> userList;
|
||||||
|
try {
|
||||||
|
String[] users = userStoreManager.listUsers(filter + "*", -1);
|
||||||
|
userList = new ArrayList<>(users.length);
|
||||||
|
UserWrapper user;
|
||||||
|
for (String username : users) {
|
||||||
|
user = new UserWrapper();
|
||||||
|
user.setUsername(username);
|
||||||
|
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
|
||||||
|
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
||||||
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
||||||
|
userList.add(user);
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving the list of users using the filter : " + filter;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
int count;
|
||||||
|
count = userList.size();
|
||||||
|
responsePayload.setMessageFromServer("All users were successfully retrieved. " +
|
||||||
|
"Obtained user count: " + count);
|
||||||
|
responsePayload.setResponseContent(userList);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of user names in the system.
|
||||||
|
*
|
||||||
|
* @return A list of user names.
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("view-users")
|
||||||
|
public Response getAllUsersByUsername(@QueryParam("username") String userName) throws MDMAPIException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the list of users by name");
|
||||||
|
}
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
List<UserWrapper> userList;
|
||||||
|
try {
|
||||||
|
String[] users = userStoreManager.listUsers("*" + userName + "*", -1);
|
||||||
|
userList = new ArrayList<>(users.length);
|
||||||
|
UserWrapper user;
|
||||||
|
for (String username : users) {
|
||||||
|
user = new UserWrapper();
|
||||||
|
user.setUsername(username);
|
||||||
|
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
|
||||||
|
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
||||||
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
||||||
|
userList.add(user);
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving the list of users";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
int count;
|
||||||
|
count = userList.size();
|
||||||
|
responsePayload.setMessageFromServer("All users by username were successfully retrieved. " +
|
||||||
|
"Obtained user count: " + count);
|
||||||
|
responsePayload.setResponseContent(userList);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of user names in the system.
|
||||||
|
*
|
||||||
|
* @return A list of user names.
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("users-by-username")
|
||||||
|
public Response getAllUserNamesByUsername(@QueryParam("username") String userName) throws MDMAPIException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the list of users by name");
|
||||||
|
}
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
List<String> userList;
|
||||||
|
try {
|
||||||
|
String[] users = userStoreManager.listUsers("*" + userName + "*", -1);
|
||||||
|
userList = new ArrayList<>(users.length);
|
||||||
|
Collections.addAll(userList, users);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving the list of users";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
int count;
|
||||||
|
count = userList.size();
|
||||||
|
responsePayload.setMessageFromServer("All users by username were successfully retrieved. " +
|
||||||
|
"Obtained user count: " + count);
|
||||||
|
responsePayload.setResponseContent(userList);
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a claim-value from user-store.
|
||||||
|
*
|
||||||
|
* @param username Username of the user
|
||||||
|
* @param claimUri required ClaimUri
|
||||||
|
* @return A list of usernames
|
||||||
|
* @throws MDMAPIException, UserStoreException
|
||||||
|
*/
|
||||||
|
private String getClaimValue(String username, String claimUri) throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
try {
|
||||||
|
return userStoreManager.getUserClaimValue(username, claimUri, null);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
throw new MDMAPIException("Error occurred while retrieving value assigned to the claim '" +
|
||||||
|
claimUri + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method used to send an invitation email to a new user to enroll a device.
|
||||||
|
*
|
||||||
|
* @param username Username of the user
|
||||||
|
* @throws MDMAPIException, UserStoreException, DeviceManagementException
|
||||||
|
*/
|
||||||
|
private void inviteNewlyAddedUserToEnrollDevice(
|
||||||
|
String username, String password) throws MDMAPIException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Sending invitation mail to user by username: " + username);
|
||||||
|
}
|
||||||
|
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
||||||
|
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain)) {
|
||||||
|
tenantDomain = "";
|
||||||
|
}
|
||||||
|
if (!username.contains("/")) {
|
||||||
|
username = "/" + username;
|
||||||
|
}
|
||||||
|
String[] usernameBits = username.split("/");
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService = MDMAPIUtils.getDeviceManagementService();
|
||||||
|
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("username", usernameBits[1]);
|
||||||
|
props.setProperty("domain-name", tenantDomain);
|
||||||
|
props.setProperty("first-name", getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
||||||
|
props.setProperty("password", password);
|
||||||
|
|
||||||
|
String recipient = getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS);
|
||||||
|
|
||||||
|
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
||||||
|
try {
|
||||||
|
deviceManagementProviderService.sendRegistrationEmail(metaInfo);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while sending registration email to user '" + username + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method used to send an invitation email to a existing user to enroll a device.
|
||||||
|
*
|
||||||
|
* @param usernames Username list of the users to be invited
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("email-invitation")
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response inviteExistingUsersToEnrollDevice(List<String> usernames) throws MDMAPIException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Sending enrollment invitation mail to existing user.");
|
||||||
|
}
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService = MDMAPIUtils.getDeviceManagementService();
|
||||||
|
try {
|
||||||
|
for (String username : usernames) {
|
||||||
|
String recipient = getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS);
|
||||||
|
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("first-name", getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
||||||
|
props.setProperty("username", username);
|
||||||
|
|
||||||
|
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
||||||
|
deviceManagementProviderService.sendEnrolmentInvitation(metaInfo);
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while inviting user to enrol their device";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("Email invitation was successfully sent to user.");
|
||||||
|
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of devices based on the username.
|
||||||
|
*
|
||||||
|
* @param username Username of the device owner
|
||||||
|
* @return A list of devices
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
@Path("devices")
|
||||||
|
public Object getAllDeviceOfUser(@QueryParam("username") String username, @QueryParam("start") int startIdx,
|
||||||
|
@QueryParam("length") int length)
|
||||||
|
throws MDMAPIException {
|
||||||
|
DeviceManagementProviderService dmService;
|
||||||
|
try {
|
||||||
|
dmService = MDMAPIUtils.getDeviceManagementService();
|
||||||
|
if (length > 0) {
|
||||||
|
PaginationRequest request = new PaginationRequest(startIdx, length);
|
||||||
|
request.setOwner(username);
|
||||||
|
return dmService.getDevicesOfUser(request);
|
||||||
|
}
|
||||||
|
return dmService.getDevicesOfUser(username);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Device management error";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to retrieve the user count of the system.
|
||||||
|
*
|
||||||
|
* @return returns the count.
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("count")
|
||||||
|
public int getUserCount() throws MDMAPIException {
|
||||||
|
try {
|
||||||
|
String[] users = MDMAPIUtils.getUserStoreManager().listUsers("*", -1);
|
||||||
|
if (users == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return users.length;
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg =
|
||||||
|
"Error occurred while retrieving the list of users that exist within the current tenant";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API is used to update roles of a user
|
||||||
|
*
|
||||||
|
* @param username
|
||||||
|
* @param userList
|
||||||
|
* @return
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
@Path("{roleName}/users")
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response updateRoles(@PathParam("username") String username, List<String> userList)
|
||||||
|
throws MDMAPIException {
|
||||||
|
final UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updating the roles of a user");
|
||||||
|
}
|
||||||
|
SetReferenceTransformer transformer = new SetReferenceTransformer();
|
||||||
|
transformer.transform(Arrays.asList(userStoreManager.getRoleListOfUser(username)),
|
||||||
|
userList);
|
||||||
|
final String[] rolesToAdd = (String[])
|
||||||
|
transformer.getObjectsToAdd().toArray(new String[transformer.getObjectsToAdd().size()]);
|
||||||
|
final String[] rolesToDelete = (String[])
|
||||||
|
transformer.getObjectsToRemove().toArray(new String[transformer.getObjectsToRemove().size()]);
|
||||||
|
|
||||||
|
userStoreManager.updateRoleListOfUser(username, rolesToDelete, rolesToAdd);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while saving the roles for user: " + username;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return Response.status(HttpStatus.SC_OK).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to change the user password.
|
||||||
|
*
|
||||||
|
* @param credentials Wrapper object representing user credentials.
|
||||||
|
* @return {Response} Status of the request wrapped inside Response object.
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("change-password")
|
||||||
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response resetPassword(UserCredentialWrapper credentials) throws MDMAPIException {
|
||||||
|
return CredentialManagementResponseBuilder.buildChangePasswordResponse(credentials);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to change the user password.
|
||||||
|
*
|
||||||
|
* @param credentials Wrapper object representing user credentials.
|
||||||
|
* @return {Response} Status of the request wrapped inside Response object.
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("reset-password")
|
||||||
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response resetPasswordByAdmin(UserCredentialWrapper credentials) throws MDMAPIException {
|
||||||
|
return CredentialManagementResponseBuilder.buildResetPasswordResponse(credentials);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.mdm.api.common;
|
||||||
|
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.ext.ExceptionMapper;
|
||||||
|
|
||||||
|
@Produces({ "application/json", "application/xml" })
|
||||||
|
public class ErrorHandler implements ExceptionMapper<MDMAPIException> {
|
||||||
|
|
||||||
|
public Response toResponse(MDMAPIException exception) {
|
||||||
|
ErrorMessage errorMessage = new ErrorMessage();
|
||||||
|
errorMessage.setErrorMessage(exception.getErrorMessage());
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.api.common;
|
||||||
|
|
||||||
|
|
||||||
|
public class ErrorMessage {
|
||||||
|
|
||||||
|
private String errorMessage;
|
||||||
|
private String errorCode;
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrorCode() {
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorCode(String errorCode) {
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.api.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom exception class for handling CDM API related exceptions.
|
||||||
|
*/
|
||||||
|
public class MDMAPIException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7950151650447893900L;
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MDMAPIException(String msg, Exception e) {
|
||||||
|
super(msg, e);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MDMAPIException(String msg, Throwable cause) {
|
||||||
|
super(msg, cause);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MDMAPIException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MDMAPIException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MDMAPIException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.api.context;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Model object of DeviceOperation.
|
||||||
|
*/
|
||||||
|
@XmlRootElement
|
||||||
|
public class DeviceOperationContext {
|
||||||
|
|
||||||
|
private List<DeviceIdentifier> devices;
|
||||||
|
private Operation operation;
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public List<DeviceIdentifier> getDevices() {
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDevices(List<DeviceIdentifier> devices) {
|
||||||
|
this.devices = devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public Operation getOperation() {
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOperation(Operation operation) {
|
||||||
|
this.operation = operation;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* 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.util;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.beans.UserCredentialWrapper;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class builds Credential modification related Responses
|
||||||
|
*/
|
||||||
|
public class CredentialManagementResponseBuilder {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(CredentialManagementResponseBuilder.class);
|
||||||
|
|
||||||
|
private ResponsePayload responsePayload;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the response to change the password of a user
|
||||||
|
* @param credentials - User credentials
|
||||||
|
* @return Response Object
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
public static Response buildChangePasswordResponse(UserCredentialWrapper credentials) throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword());
|
||||||
|
byte[] decodedOldPassword = Base64.decodeBase64(credentials.getOldPassword());
|
||||||
|
userStoreManager.updateCredential(credentials.getUsername(), new String(
|
||||||
|
decodedNewPassword, "UTF-8"), new String(decodedOldPassword, "UTF-8"));
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
|
responsePayload.setMessageFromServer("User password by username: " + credentials.getUsername() +
|
||||||
|
" was successfully changed.");
|
||||||
|
return Response.status(HttpStatus.SC_CREATED).entity(responsePayload).build();
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
|
responsePayload.setMessageFromServer("Old password does not match.");
|
||||||
|
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
String errorMsg = "Could not change the password of the user: " + credentials.getUsername() +
|
||||||
|
". The Character Encoding is not supported.";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new MDMAPIException(errorMsg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the response to reset the password of a user
|
||||||
|
* @param credentials - User credentials
|
||||||
|
* @return Response Object
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
public static Response buildResetPasswordResponse(UserCredentialWrapper credentials) throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
try {
|
||||||
|
byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword());
|
||||||
|
userStoreManager.updateCredentialByAdmin(credentials.getUsername(), new String(
|
||||||
|
decodedNewPassword, "UTF-8"));
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
|
responsePayload.setMessageFromServer("User password by username: " + credentials.getUsername() +
|
||||||
|
" was successfully changed.");
|
||||||
|
return Response.status(HttpStatus.SC_CREATED).entity(responsePayload).build();
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
|
responsePayload.setMessageFromServer("Could not change the password.");
|
||||||
|
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
String errorMsg = "Could not change the password of the user: " + credentials.getUsername() +
|
||||||
|
". The Character Encoding is not supported.";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new MDMAPIException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,313 @@
|
|||||||
|
/*
|
||||||
|
* 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.util;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||||
|
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.notification.mgt.NotificationManagementService;
|
||||||
|
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.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.ntask.core.TaskManager;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
||||||
|
import org.wso2.carbon.user.api.AuthorizationManager;
|
||||||
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MDMAPIUtils class provides utility function used by CDM REST-API classes.
|
||||||
|
*/
|
||||||
|
public class MDMAPIUtils {
|
||||||
|
|
||||||
|
private static final String NOTIFIER_FREQUENCY = "notifierFrequency";
|
||||||
|
public static final MediaType DEFAULT_CONTENT_TYPE = MediaType.APPLICATION_JSON_TYPE;
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(MDMAPIUtils.class);
|
||||||
|
|
||||||
|
public static int getNotifierFrequency(TenantConfiguration tenantConfiguration) {
|
||||||
|
List<ConfigurationEntry> configEntryList = tenantConfiguration.getConfiguration();
|
||||||
|
if (configEntryList != null && !configEntryList.isEmpty()) {
|
||||||
|
for(ConfigurationEntry entry : configEntryList) {
|
||||||
|
if (NOTIFIER_FREQUENCY.equals(entry.getName())) {
|
||||||
|
return Integer.parseInt((String) entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scheduleTaskService(int notifierFrequency) {
|
||||||
|
TaskScheduleService taskScheduleService;
|
||||||
|
try {
|
||||||
|
taskScheduleService = getPolicyManagementService().getTaskScheduleService();
|
||||||
|
if (taskScheduleService.isTaskScheduled()) {
|
||||||
|
taskScheduleService.updateTask(notifierFrequency);
|
||||||
|
} else {
|
||||||
|
taskScheduleService.startTask(notifierFrequency);
|
||||||
|
}
|
||||||
|
} catch (PolicyMonitoringTaskException e) {
|
||||||
|
log.error("Exception occurred while starting the Task service.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeviceManagementProviderService getDeviceManagementService() {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService =
|
||||||
|
(DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null);
|
||||||
|
if (deviceManagementProviderService == null) {
|
||||||
|
String msg = "Device Management provider service has not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
return deviceManagementProviderService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getTenantId(String tenantDomain) throws MDMAPIException {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||||
|
try {
|
||||||
|
return realmService.getTenantManager().getTenantId(tenantDomain);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
throw new MDMAPIException(
|
||||||
|
"Error obtaining tenant id from tenant domain " + tenantDomain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UserStoreManager getUserStoreManager() throws MDMAPIException {
|
||||||
|
RealmService realmService;
|
||||||
|
UserStoreManager userStoreManager;
|
||||||
|
try {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||||
|
if (realmService == null) {
|
||||||
|
String msg = "Realm service has not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
int tenantId = ctx.getTenantId();
|
||||||
|
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving current user store manager";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return userStoreManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting the current tenant's user realm
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
public static UserRealm getUserRealm() throws MDMAPIException {
|
||||||
|
RealmService realmService;
|
||||||
|
UserRealm realm;
|
||||||
|
try {
|
||||||
|
//PrivilegedCarbonContext.startTenantFlow();
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
//ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||||
|
//ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||||
|
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||||
|
|
||||||
|
if (realmService == null) {
|
||||||
|
String msg = "Realm service not initialized";
|
||||||
|
log.error(msg);
|
||||||
|
throw new MDMAPIException(msg);
|
||||||
|
}
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
realm = realmService.getTenantUserRealm(tenantId);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving current user realm";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
} finally {
|
||||||
|
//PrivilegedCarbonContext.endTenantFlow();
|
||||||
|
}
|
||||||
|
return realm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AuthorizationManager getAuthorizationManager() throws MDMAPIException {
|
||||||
|
RealmService realmService;
|
||||||
|
AuthorizationManager authorizationManager;
|
||||||
|
try {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||||
|
if (realmService == null) {
|
||||||
|
String msg = "Realm service has not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
int tenantId = ctx.getTenantId();
|
||||||
|
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while retrieving current Authorization manager.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MDMAPIException(msg, e);
|
||||||
|
}
|
||||||
|
return authorizationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to get the current tenant id.
|
||||||
|
*
|
||||||
|
* @return returns the tenant id.
|
||||||
|
*/
|
||||||
|
public static int getTenantId() {
|
||||||
|
return CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeviceIdentifier instantiateDeviceIdentifier(String deviceType, String deviceId) {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setType(deviceType);
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
return deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApplicationManagementProviderService getAppManagementService() {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
ApplicationManagementProviderService applicationManagementProviderService =
|
||||||
|
(ApplicationManagementProviderService) ctx.getOSGiService(ApplicationManagementProviderService.class, null);
|
||||||
|
if (applicationManagementProviderService == null) {
|
||||||
|
String msg = "Application management service has not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
return applicationManagementProviderService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PolicyManagerService getPolicyManagementService() {
|
||||||
|
PolicyManagerService policyManagementService;
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
policyManagementService =
|
||||||
|
(PolicyManagerService) ctx.getOSGiService(PolicyManagerService.class, null);
|
||||||
|
if (policyManagementService == null) {
|
||||||
|
String msg = "Policy Management service not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
return policyManagementService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TenantConfigurationManagementService getTenantConfigurationManagementService() {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
TenantConfigurationManagementService tenantConfigurationManagementService =
|
||||||
|
(TenantConfigurationManagementService) ctx.getOSGiService(TenantConfigurationManagementService.class, null);
|
||||||
|
if (tenantConfigurationManagementService == null) {
|
||||||
|
String msg = "Tenant configuration Management service not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
return tenantConfigurationManagementService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NotificationManagementService getNotificationManagementService() {
|
||||||
|
NotificationManagementService notificationManagementService;
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
notificationManagementService = (NotificationManagementService) ctx.getOSGiService(
|
||||||
|
NotificationManagementService.class, null);
|
||||||
|
if (notificationManagementService == null) {
|
||||||
|
String msg = "Notification Management service not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
return notificationManagementService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PaginationResult getPagingResponse(int recordsTotal, int recordsFiltered, int draw, List<?> data) {
|
||||||
|
PaginationResult pagingResponse = new PaginationResult();
|
||||||
|
pagingResponse.setRecordsTotal(recordsTotal);
|
||||||
|
pagingResponse.setRecordsFiltered(recordsFiltered);
|
||||||
|
pagingResponse.setDraw(draw);
|
||||||
|
pagingResponse.setData(data);
|
||||||
|
return pagingResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CertificateManagementService getCertificateManagementService() {
|
||||||
|
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
CertificateManagementService certificateManagementService = (CertificateManagementService)
|
||||||
|
ctx.getOSGiService(CertificateManagementService.class, null);
|
||||||
|
|
||||||
|
if (certificateManagementService == null) {
|
||||||
|
String msg = "Certificate Management service not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return certificateManagementService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static MediaType getResponseMediaType(String acceptHeader) {
|
||||||
|
MediaType responseMediaType;
|
||||||
|
if (acceptHeader == null || MediaType.WILDCARD.equals(acceptHeader)) {
|
||||||
|
responseMediaType = DEFAULT_CONTENT_TYPE;
|
||||||
|
} else {
|
||||||
|
responseMediaType = MediaType.valueOf(acceptHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.api.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.beans.MobileApp;
|
||||||
|
import org.wso2.carbon.mdm.beans.android.WebApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This class contains the all the operations related to Android.
|
||||||
|
*/
|
||||||
|
public class MDMAndroidOperationUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to create Install Application operation.
|
||||||
|
*
|
||||||
|
* @param application MobileApp application
|
||||||
|
* @return operation
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static Operation createInstallAppOperation(MobileApp application) throws MDMAPIException {
|
||||||
|
|
||||||
|
ProfileOperation operation = new ProfileOperation();
|
||||||
|
operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION);
|
||||||
|
operation.setType(Operation.Type.PROFILE);
|
||||||
|
|
||||||
|
switch (application.getType()) {
|
||||||
|
case ENTERPRISE:
|
||||||
|
org.wso2.carbon.mdm.beans.android.EnterpriseApplication enterpriseApplication =
|
||||||
|
new org.wso2.carbon.mdm.beans.android.EnterpriseApplication();
|
||||||
|
enterpriseApplication.setType(application.getType().toString());
|
||||||
|
enterpriseApplication.setUrl(application.getLocation());
|
||||||
|
operation.setPayLoad(enterpriseApplication.toJSON());
|
||||||
|
break;
|
||||||
|
case PUBLIC:
|
||||||
|
org.wso2.carbon.mdm.beans.android.AppStoreApplication appStoreApplication =
|
||||||
|
new org.wso2.carbon.mdm.beans.android.AppStoreApplication();
|
||||||
|
appStoreApplication.setType(application.getType().toString());
|
||||||
|
appStoreApplication.setAppIdentifier(application.getIdentifier());
|
||||||
|
operation.setPayLoad(appStoreApplication.toJSON());
|
||||||
|
break;
|
||||||
|
case WEBAPP:
|
||||||
|
WebApplication webApplication = new WebApplication();
|
||||||
|
webApplication.setUrl(application.getLocation());
|
||||||
|
webApplication.setName(application.getName());
|
||||||
|
webApplication.setType(application.getType().toString());
|
||||||
|
operation.setPayLoad(webApplication.toJSON());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
String errorMessage = "Invalid application type.";
|
||||||
|
throw new MDMAPIException(errorMessage);
|
||||||
|
}
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to create Uninstall Application operation.
|
||||||
|
* @param application MobileApp application
|
||||||
|
* @return operation
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*/
|
||||||
|
public static Operation createAppUninstallOperation(MobileApp application) throws MDMAPIException {
|
||||||
|
|
||||||
|
ProfileOperation operation = new ProfileOperation();
|
||||||
|
operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION);
|
||||||
|
operation.setType(Operation.Type.PROFILE);
|
||||||
|
|
||||||
|
switch (application.getType()) {
|
||||||
|
case ENTERPRISE:
|
||||||
|
org.wso2.carbon.mdm.beans.android.EnterpriseApplication enterpriseApplication =
|
||||||
|
new org.wso2.carbon.mdm.beans.android.EnterpriseApplication();
|
||||||
|
enterpriseApplication.setType(application.getType().toString());
|
||||||
|
enterpriseApplication.setAppIdentifier(application.getAppIdentifier());
|
||||||
|
operation.setPayLoad(enterpriseApplication.toJSON());
|
||||||
|
break;
|
||||||
|
case PUBLIC:
|
||||||
|
org.wso2.carbon.mdm.beans.android.AppStoreApplication appStoreApplication =
|
||||||
|
new org.wso2.carbon.mdm.beans.android.AppStoreApplication();
|
||||||
|
appStoreApplication.setType(application.getType().toString());
|
||||||
|
appStoreApplication.setAppIdentifier(application.getAppIdentifier());
|
||||||
|
operation.setPayLoad(appStoreApplication.toJSON());
|
||||||
|
break;
|
||||||
|
case WEBAPP:
|
||||||
|
WebApplication webApplication = new WebApplication();
|
||||||
|
webApplication.setUrl(application.getLocation());
|
||||||
|
webApplication.setName(application.getName());
|
||||||
|
webApplication.setType(application.getType().toString());
|
||||||
|
operation.setPayLoad(webApplication.toJSON());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
String errorMessage = "Invalid application type.";
|
||||||
|
throw new MDMAPIException(errorMessage);
|
||||||
|
}
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.mdm.api.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds all the constants used for IOS and Android.
|
||||||
|
*/
|
||||||
|
public class MDMAppConstants {
|
||||||
|
|
||||||
|
public class IOSConstants {
|
||||||
|
|
||||||
|
private IOSConstants() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
public static final String IS_REMOVE_APP = "isRemoveApp";
|
||||||
|
public static final String IS_PREVENT_BACKUP = "isPreventBackup";
|
||||||
|
public static final String I_TUNES_ID = "iTunesId";
|
||||||
|
public static final String LABEL = "label";
|
||||||
|
public static final String OPCODE_INSTALL_ENTERPRISE_APPLICATION = "INSTALL_ENTERPRISE_APPLICATION";
|
||||||
|
public static final String OPCODE_INSTALL_STORE_APPLICATION = "INSTALL_STORE_APPLICATION";
|
||||||
|
public static final String OPCODE_INSTALL_WEB_APPLICATION = "WEB_CLIP";
|
||||||
|
public static final String OPCODE_REMOVE_APPLICATION = "REMOVE_APPLICATION";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AndroidConstants {
|
||||||
|
|
||||||
|
private AndroidConstants() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
public static final String OPCODE_INSTALL_APPLICATION = "INSTALL_APPLICATION";
|
||||||
|
public static final String OPCODE_UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RegistryConstants {
|
||||||
|
|
||||||
|
private RegistryConstants() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
public static final String GENERAL_CONFIG_RESOURCE_PATH = "general";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.mdm.api.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import org.wso2.carbon.mdm.beans.MobileApp;
|
||||||
|
import org.wso2.carbon.mdm.beans.ios.WebClip;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains the all the operations related to IOS.
|
||||||
|
*/
|
||||||
|
public class MDMIOSOperationUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to create Install Application operation.
|
||||||
|
*
|
||||||
|
* @param application MobileApp application
|
||||||
|
* @return operation
|
||||||
|
* @throws MDMAPIException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static Operation createInstallAppOperation(MobileApp application) throws MDMAPIException {
|
||||||
|
|
||||||
|
ProfileOperation operation = new ProfileOperation();
|
||||||
|
|
||||||
|
switch (application.getType()) {
|
||||||
|
case ENTERPRISE:
|
||||||
|
org.wso2.carbon.mdm.beans.ios.EnterpriseApplication enterpriseApplication =
|
||||||
|
new org.wso2.carbon.mdm.beans.ios.EnterpriseApplication();
|
||||||
|
enterpriseApplication.setBundleId(application.getId());
|
||||||
|
enterpriseApplication.setIdentifier(application.getIdentifier());
|
||||||
|
enterpriseApplication.setManifestURL(application.getLocation());
|
||||||
|
|
||||||
|
Properties properties = application.getProperties();
|
||||||
|
enterpriseApplication.setPreventBackupOfAppData((Boolean) properties.
|
||||||
|
get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP));
|
||||||
|
enterpriseApplication.setRemoveAppUponMDMProfileRemoval((Boolean) properties.
|
||||||
|
get(MDMAppConstants.IOSConstants.IS_REMOVE_APP));
|
||||||
|
operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_ENTERPRISE_APPLICATION);
|
||||||
|
operation.setPayLoad(enterpriseApplication.toJSON());
|
||||||
|
operation.setType(Operation.Type.COMMAND);
|
||||||
|
break;
|
||||||
|
case PUBLIC:
|
||||||
|
org.wso2.carbon.mdm.beans.ios.AppStoreApplication appStoreApplication =
|
||||||
|
new org.wso2.carbon.mdm.beans.ios.AppStoreApplication();
|
||||||
|
appStoreApplication.setRemoveAppUponMDMProfileRemoval((Boolean) application.getProperties().
|
||||||
|
get(MDMAppConstants.IOSConstants.IS_REMOVE_APP));
|
||||||
|
appStoreApplication.setIdentifier(application.getIdentifier());
|
||||||
|
appStoreApplication.setPreventBackupOfAppData((Boolean) application.getProperties().
|
||||||
|
get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP));
|
||||||
|
appStoreApplication.setBundleId(application.getId());
|
||||||
|
appStoreApplication.setiTunesStoreID((Integer) application.getProperties().
|
||||||
|
get(MDMAppConstants.IOSConstants.I_TUNES_ID));
|
||||||
|
operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_STORE_APPLICATION);
|
||||||
|
operation.setType(Operation.Type.COMMAND);
|
||||||
|
operation.setPayLoad(appStoreApplication.toJSON());
|
||||||
|
break;
|
||||||
|
case WEBAPP:
|
||||||
|
WebClip webClip = new WebClip();
|
||||||
|
webClip.setIcon(application.getIconImage());
|
||||||
|
webClip.setIsRemovable(application.getProperties().
|
||||||
|
getProperty(MDMAppConstants.IOSConstants.IS_REMOVE_APP));
|
||||||
|
webClip.setLabel(application.getProperties().
|
||||||
|
getProperty(MDMAppConstants.IOSConstants.LABEL));
|
||||||
|
webClip.setURL(application.getLocation());
|
||||||
|
|
||||||
|
operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_WEB_APPLICATION);
|
||||||
|
operation.setType(Operation.Type.PROFILE);
|
||||||
|
operation.setPayLoad(webClip.toJSON());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Operation createAppUninstallOperation(MobileApp application) throws MDMAPIException{
|
||||||
|
|
||||||
|
ProfileOperation operation = new ProfileOperation();
|
||||||
|
operation.setCode(MDMAppConstants.IOSConstants.OPCODE_REMOVE_APPLICATION);
|
||||||
|
operation.setType(Operation.Type.PROFILE);
|
||||||
|
|
||||||
|
org.wso2.carbon.mdm.beans.ios.RemoveApplication removeApplication =
|
||||||
|
new org.wso2.carbon.mdm.beans.ios.RemoveApplication();
|
||||||
|
removeApplication.setBundleId(application.getIdentifier());
|
||||||
|
operation.setPayLoad(removeApplication.toJSON());
|
||||||
|
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* 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.util;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
@XmlRootElement
|
||||||
|
public class ResponsePayload {
|
||||||
|
|
||||||
|
private int statusCode;
|
||||||
|
private String messageFromServer;
|
||||||
|
private Object responseContent;
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public int getStatusCode() {
|
||||||
|
return statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatusCode(int statusCode) {
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public String getMessageFromServer() {
|
||||||
|
return messageFromServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageFromServer(String messageFromServer) {
|
||||||
|
this.messageFromServer = messageFromServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public Object getResponseContent() {
|
||||||
|
return responseContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponseContent(Object responseContent) {
|
||||||
|
this.responseContent = responseContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResponsePayloadBuilder getBuilder() {
|
||||||
|
return new ResponsePayloadBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponsePayloadBuilder statusCode(int statusCode) {
|
||||||
|
ResponsePayload message = new ResponsePayload();
|
||||||
|
return message.getBuilder().statusCode(statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponsePayloadBuilder messageFromServer(String messageFromServer) {
|
||||||
|
ResponsePayload message = new ResponsePayload();
|
||||||
|
return message.getBuilder().messageFromServer(messageFromServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponsePayloadBuilder responseContent(String responseContent) {
|
||||||
|
ResponsePayload message = new ResponsePayload();
|
||||||
|
return message.getBuilder().responseContent(responseContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ResponsePayloadBuilder {
|
||||||
|
|
||||||
|
private int statusCode;
|
||||||
|
private String messageFromServer;
|
||||||
|
private Object responseContent;
|
||||||
|
|
||||||
|
public ResponsePayloadBuilder statusCode(int statusCode) {
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponsePayloadBuilder messageFromServer(String messageFromServer) {
|
||||||
|
this.messageFromServer = messageFromServer;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponsePayloadBuilder responseContent(String responseContent) {
|
||||||
|
this.responseContent = responseContent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponsePayload build() {
|
||||||
|
ResponsePayload payload = new ResponsePayload();
|
||||||
|
payload.setStatusCode(statusCode);
|
||||||
|
payload.setMessageFromServer(messageFromServer);
|
||||||
|
payload.setResponseContent(responseContent);
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.mdm.beans;
|
||||||
|
|
||||||
|
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 MobileApp application;
|
||||||
|
|
||||||
|
public MobileApp getApplication() {
|
||||||
|
return application;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplication(MobileApp application) {
|
||||||
|
this.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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.beans;
|
||||||
|
|
||||||
|
public class EnrollmentCertificate {
|
||||||
|
String serial;
|
||||||
|
String pem;
|
||||||
|
int tenantId;
|
||||||
|
|
||||||
|
public int getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(int tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSerial() {
|
||||||
|
return serial;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSerial(String serial) {
|
||||||
|
this.serial = serial;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPem() {
|
||||||
|
return pem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPem(String pem) {
|
||||||
|
this.pem = pem;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.beans;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the generic mobile Application information
|
||||||
|
* which is used by AppM.
|
||||||
|
*/
|
||||||
|
public class MobileApp {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private MobileAppTypes type;
|
||||||
|
private String platform;
|
||||||
|
private String version;
|
||||||
|
private String identifier;
|
||||||
|
private String iconImage;
|
||||||
|
private String packageName;
|
||||||
|
private String appIdentifier;
|
||||||
|
private String location;
|
||||||
|
private Properties properties;
|
||||||
|
|
||||||
|
public MobileAppTypes getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(MobileAppTypes type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlatform() {
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlatform(String platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdentifier() {
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentifier(String identifier) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIconImage() {
|
||||||
|
return iconImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIconImage(String iconImage) {
|
||||||
|
this.iconImage = iconImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPackageName() {
|
||||||
|
return packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPackageName(String packageName) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppIdentifier() {
|
||||||
|
return appIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppIdentifier(String appIdentifier) {
|
||||||
|
this.appIdentifier = appIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(String location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Properties getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProperties(Properties properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.beans;
|
||||||
|
|
||||||
|
public enum MobileAppTypes {
|
||||||
|
ENTERPRISE,WEBAPP,PUBLIC
|
||||||
|
}
|
||||||
@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.beans;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PolicyWrapper {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private Profile profile;
|
||||||
|
private String policyName;
|
||||||
|
private String description;
|
||||||
|
private String compliance;
|
||||||
|
private List<String> roles;
|
||||||
|
private String ownershipType;
|
||||||
|
private List<Device> devices;
|
||||||
|
private List<String> users;
|
||||||
|
private int tenantId;
|
||||||
|
private int profileId;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Profile getProfile() {
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfile(Profile profile) {
|
||||||
|
this.profile = profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCompliance() {
|
||||||
|
return compliance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompliance(String compliance) {
|
||||||
|
this.compliance = compliance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPolicyName() {
|
||||||
|
return policyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPolicyName(String policyName) {
|
||||||
|
this.policyName = policyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getRoles() {
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoles(List<String> roles) {
|
||||||
|
this.roles = roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwnershipType() {
|
||||||
|
return ownershipType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnershipType(String ownershipType) {
|
||||||
|
this.ownershipType = ownershipType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Device> getDevices() {
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDevices(List<Device> devices) {
|
||||||
|
this.devices = devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsers(List<String> users) {
|
||||||
|
this.users = users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(int tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProfileId() {
|
||||||
|
return profileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfileId(int profileId) {
|
||||||
|
this.profileId = profileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.beans;
|
||||||
|
|
||||||
|
public class PriorityUpdatedPolicyWrapper {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private int priority;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPriority() {
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriority(int priority) {
|
||||||
|
this.priority = priority;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.beans;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@XmlRootElement
|
||||||
|
public class Profile {
|
||||||
|
|
||||||
|
private int profileId;
|
||||||
|
private String profileName;
|
||||||
|
private int tenantId;
|
||||||
|
private DeviceType deviceType;
|
||||||
|
private Timestamp createdDate;
|
||||||
|
private Timestamp updatedDate;
|
||||||
|
private List<ProfileFeature> profileFeaturesList; // Features included in the policies.
|
||||||
|
|
||||||
|
public DeviceType getDeviceType() {
|
||||||
|
return deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceType(DeviceType deviceType) {
|
||||||
|
this.deviceType = deviceType;
|
||||||
|
}
|
||||||
|
@XmlElement
|
||||||
|
public int getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(int tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* public List<Feature> getFeaturesList() {
|
||||||
|
return featuresList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeaturesList(List<Feature> featuresList) {
|
||||||
|
this.featuresList = featuresList;
|
||||||
|
}*/
|
||||||
|
@XmlElement
|
||||||
|
public int getProfileId() {
|
||||||
|
return profileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfileId(int profileId) {
|
||||||
|
this.profileId = profileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public String getProfileName() {
|
||||||
|
return profileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfileName(String profileName) {
|
||||||
|
this.profileName = profileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public Timestamp getCreatedDate() {
|
||||||
|
return createdDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedDate(Timestamp createdDate) {
|
||||||
|
this.createdDate = createdDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public Timestamp getUpdatedDate() {
|
||||||
|
return updatedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedDate(Timestamp updatedDate) {
|
||||||
|
this.updatedDate = updatedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public List<ProfileFeature> getProfileFeaturesList() {
|
||||||
|
return profileFeaturesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfileFeaturesList(List<ProfileFeature> profileFeaturesList) {
|
||||||
|
this.profileFeaturesList = profileFeaturesList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.beans;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
public class ProfileFeature implements Serializable {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private String featureCode;
|
||||||
|
private int profileId;
|
||||||
|
private int deviceTypeId;
|
||||||
|
private Object content;
|
||||||
|
private String payLoad;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFeatureCode() {
|
||||||
|
return featureCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeatureCode(String featureCode) {
|
||||||
|
this.featureCode = featureCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProfileId() {
|
||||||
|
return profileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfileId(int profileId) {
|
||||||
|
this.profileId = profileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeviceTypeId() {
|
||||||
|
return deviceTypeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceTypeId(int deviceTypeId) {
|
||||||
|
this.deviceTypeId = deviceTypeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getPayLoad() {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
this.payLoad = gson.toJson(content);
|
||||||
|
return payLoad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPayLoad(String payLoad) {
|
||||||
|
this.payLoad = payLoad;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Object getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(Object content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
package org.wso2.carbon.mdm.beans;
|
||||||
|
|
||||||
|
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
public class RoleWrapper {
|
||||||
|
private String roleName;
|
||||||
|
private String[] permissions;
|
||||||
|
private String[] users;
|
||||||
|
private UIPermissionNode permissionList;
|
||||||
|
|
||||||
|
public String getRoleName() {
|
||||||
|
return roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleName(String roleName) {
|
||||||
|
this.roleName = roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissions(String[] permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsers(String[] users) {
|
||||||
|
this.users = users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UIPermissionNode getPermissionList() {
|
||||||
|
return permissionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissionList(UIPermissionNode permissionList) {
|
||||||
|
this.permissionList = permissionList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.beans;
|
||||||
|
|
||||||
|
public class UserCredentialWrapper {
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
/*
|
||||||
|
Base64 encoded password
|
||||||
|
*/
|
||||||
|
private String oldPassword;
|
||||||
|
private String newPassword;
|
||||||
|
|
||||||
|
public String getNewPassword() {
|
||||||
|
return newPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewPassword(String newPassword) {
|
||||||
|
this.newPassword = newPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOldPassword() {
|
||||||
|
return oldPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOldPassword(String oldPassword) {
|
||||||
|
this.oldPassword = oldPassword;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* 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.beans;
|
||||||
|
|
||||||
|
public class UserWrapper {
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
/*
|
||||||
|
Base64 encoded password
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
private String firstname;
|
||||||
|
private String lastname;
|
||||||
|
private String emailAddress;
|
||||||
|
private String[] roles;
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstname() {
|
||||||
|
return firstname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstname(String firstname) {
|
||||||
|
this.firstname = firstname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastname() {
|
||||||
|
return lastname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastname(String lastname) {
|
||||||
|
this.lastname = lastname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmailAddress() {
|
||||||
|
return emailAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmailAddress(String emailAddress) {
|
||||||
|
this.emailAddress = emailAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Giving a clone of the array since arrays are mutable
|
||||||
|
*/
|
||||||
|
public String[] getRoles() {
|
||||||
|
String[] copiedRoles = roles;
|
||||||
|
if (roles != null){
|
||||||
|
copiedRoles = roles.clone();
|
||||||
|
}
|
||||||
|
return copiedRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoles(String[] roles) {
|
||||||
|
this.roles = roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.mdm.beans.android;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the Appstore Application information.
|
||||||
|
*/
|
||||||
|
public class AppStoreApplication implements Serializable {
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
private String appIdentifier;
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppIdentifier() {
|
||||||
|
return appIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppIdentifier(String appIdentifier) {
|
||||||
|
this.appIdentifier = appIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJSON() throws MDMAPIException {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
return gson.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.mdm.beans.android;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the Enterprise Application information.
|
||||||
|
*/
|
||||||
|
public class EnterpriseApplication implements Serializable {
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
private String url;
|
||||||
|
private String appIdentifier;
|
||||||
|
|
||||||
|
public String getAppIdentifier() {
|
||||||
|
return appIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppIdentifier(String appIdentifier) {
|
||||||
|
this.appIdentifier = appIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJSON() throws MDMAPIException {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
return gson.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.mdm.beans.android;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the Web Application information.
|
||||||
|
*/
|
||||||
|
public class WebApplication implements Serializable {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String url;
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJSON() throws MDMAPIException {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
return gson.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.beans.ios;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class AppStoreApplication implements Serializable {
|
||||||
|
|
||||||
|
private String identifier;
|
||||||
|
private int iTunesStoreID;
|
||||||
|
private boolean removeAppUponMDMProfileRemoval;
|
||||||
|
private boolean preventBackupOfAppData;
|
||||||
|
private String bundleId;
|
||||||
|
private String UUID;
|
||||||
|
|
||||||
|
public String getUUID() {
|
||||||
|
return UUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUUID(String UUID) {
|
||||||
|
this.UUID = UUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdentifier() {
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentifier(String identifier) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getiTunesStoreID() {
|
||||||
|
return iTunesStoreID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setiTunesStoreID(int iTunesStoreID) {
|
||||||
|
this.iTunesStoreID = iTunesStoreID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRemoveAppUponMDMProfileRemoval() {
|
||||||
|
return removeAppUponMDMProfileRemoval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemoveAppUponMDMProfileRemoval(boolean removeAppUponMDMProfileRemoval) {
|
||||||
|
this.removeAppUponMDMProfileRemoval = removeAppUponMDMProfileRemoval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPreventBackupOfAppData() {
|
||||||
|
return preventBackupOfAppData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreventBackupOfAppData(boolean preventBackupOfAppData) {
|
||||||
|
this.preventBackupOfAppData = preventBackupOfAppData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBundleId() {
|
||||||
|
return bundleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBundleId(String bundleId) {
|
||||||
|
this.bundleId = bundleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJSON() throws MDMAPIException {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
return gson.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.beans.ios;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class EnterpriseApplication implements Serializable {
|
||||||
|
|
||||||
|
private String identifier;
|
||||||
|
private String manifestURL;
|
||||||
|
private boolean removeAppUponMDMProfileRemoval;
|
||||||
|
private boolean preventBackupOfAppData;
|
||||||
|
private String bundleId;
|
||||||
|
private String UUID;
|
||||||
|
|
||||||
|
public void setUUID(String UUID) {
|
||||||
|
this.UUID = UUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdentifier() {
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentifier(String identifier) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getManifestURL() {
|
||||||
|
return manifestURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManifestURL(String manifestURL) {
|
||||||
|
this.manifestURL = manifestURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRemoveAppUponMDMProfileRemoval() {
|
||||||
|
return removeAppUponMDMProfileRemoval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemoveAppUponMDMProfileRemoval(boolean removeAppUponMDMProfileRemoval) {
|
||||||
|
this.removeAppUponMDMProfileRemoval = removeAppUponMDMProfileRemoval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPreventBackupOfAppData() {
|
||||||
|
return preventBackupOfAppData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreventBackupOfAppData(boolean preventBackupOfAppData) {
|
||||||
|
this.preventBackupOfAppData = preventBackupOfAppData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBundleId() {
|
||||||
|
return bundleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBundleId(String bundleId) {
|
||||||
|
this.bundleId = bundleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJSON() throws MDMAPIException {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
return gson.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package org.wso2.carbon.mdm.beans.ios;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class RemoveApplication implements Serializable {
|
||||||
|
|
||||||
|
private String bundleId;
|
||||||
|
|
||||||
|
public String getBundleId() {
|
||||||
|
return bundleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBundleId(String bundleId) {
|
||||||
|
this.bundleId = bundleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJSON() throws MDMAPIException {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
return gson.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
package org.wso2.carbon.mdm.beans.ios;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class WebClip {
|
||||||
|
|
||||||
|
private String URL;
|
||||||
|
private String label;
|
||||||
|
private String icon;
|
||||||
|
private String isRemovable;
|
||||||
|
private String UUID;
|
||||||
|
|
||||||
|
public String getUUID() {
|
||||||
|
return UUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUUID(String UUID) {
|
||||||
|
this.UUID = UUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getURL() {
|
||||||
|
return URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setURL(String URL) {
|
||||||
|
this.URL = URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(String icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIsRemovable() {
|
||||||
|
return isRemovable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsRemovable(String isRemovable) {
|
||||||
|
this.isRemovable = isRemovable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJSON() throws MDMAPIException {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
return gson.toJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.exception;
|
||||||
|
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
public class BadRequestException extends WebApplicationException {
|
||||||
|
|
||||||
|
public BadRequestException(Message message, MediaType mediaType) {
|
||||||
|
super(Response.status(Response.Status.BAD_REQUEST).entity(message).type(mediaType).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.exception;
|
||||||
|
|
||||||
|
public class Message {
|
||||||
|
|
||||||
|
private String errorMessage;
|
||||||
|
private String discription;
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDiscription() {
|
||||||
|
return discription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDiscription(String discription) {
|
||||||
|
this.discription = discription;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the constants used by MDM-Admin web application.
|
||||||
|
*/
|
||||||
|
public class Constants {
|
||||||
|
|
||||||
|
public static final String USER_CLAIM_EMAIL_ADDRESS = "http://wso2.org/claims/emailaddress";
|
||||||
|
public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname";
|
||||||
|
public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname";
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.mdm.beans.ProfileFeature;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MDMUtil {
|
||||||
|
|
||||||
|
public static Profile convertProfile(org.wso2.carbon.mdm.beans.Profile mdmProfile) {
|
||||||
|
Profile profile = new Profile();
|
||||||
|
profile.setTenantId(mdmProfile.getTenantId());
|
||||||
|
profile.setCreatedDate(mdmProfile.getCreatedDate());
|
||||||
|
profile.setDeviceType(mdmProfile.getDeviceType());
|
||||||
|
|
||||||
|
List<org.wso2.carbon.policy.mgt.common.ProfileFeature> profileFeatures =
|
||||||
|
new ArrayList<org.wso2.carbon.policy.
|
||||||
|
mgt.common.ProfileFeature>(mdmProfile.getProfileFeaturesList().size());
|
||||||
|
for (ProfileFeature mdmProfileFeature : mdmProfile.getProfileFeaturesList()) {
|
||||||
|
profileFeatures.add(convertProfileFeature(mdmProfileFeature));
|
||||||
|
}
|
||||||
|
profile.setProfileFeaturesList(profileFeatures);
|
||||||
|
profile.setProfileId(mdmProfile.getProfileId());
|
||||||
|
profile.setProfileName(mdmProfile.getProfileName());
|
||||||
|
profile.setUpdatedDate(mdmProfile.getUpdatedDate());
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static org.wso2.carbon.policy.mgt.common.ProfileFeature convertProfileFeature(ProfileFeature
|
||||||
|
mdmProfileFeature) {
|
||||||
|
|
||||||
|
org.wso2.carbon.policy.mgt.common.ProfileFeature profileFeature =
|
||||||
|
new org.wso2.carbon.policy.mgt.common.ProfileFeature();
|
||||||
|
profileFeature.setProfileId(mdmProfileFeature.getProfileId());
|
||||||
|
profileFeature.setContent(mdmProfileFeature.getPayLoad());
|
||||||
|
profileFeature.setDeviceTypeId(mdmProfileFeature.getDeviceTypeId());
|
||||||
|
profileFeature.setFeatureCode(mdmProfileFeature.getFeatureCode());
|
||||||
|
profileFeature.setId(mdmProfileFeature.getId());
|
||||||
|
return profileFeature;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
public class SetReferenceTransformer<T>{
|
||||||
|
private List<T> objectsToRemove;
|
||||||
|
private List<T> objectsToAdd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the Set theory to find the objects to delete and objects to add
|
||||||
|
|
||||||
|
The difference of objects in existingSet and newSet needed to be deleted
|
||||||
|
|
||||||
|
new roles to add = newSet - The intersection of roles in existingSet and newSet
|
||||||
|
* @param currentList
|
||||||
|
* @param nextList
|
||||||
|
*/
|
||||||
|
public void transform(List<T> currentList, List<T> nextList){
|
||||||
|
TreeSet<T> existingSet = new TreeSet<T>(currentList);
|
||||||
|
TreeSet<T> newSet = new TreeSet<T>(nextList);
|
||||||
|
|
||||||
|
existingSet.removeAll(newSet);
|
||||||
|
|
||||||
|
objectsToRemove = new ArrayList<T>(existingSet);
|
||||||
|
|
||||||
|
// Clearing and re-initializing the set
|
||||||
|
existingSet = new TreeSet<T>(currentList);
|
||||||
|
|
||||||
|
newSet.removeAll(existingSet);
|
||||||
|
objectsToAdd = new ArrayList<T>(newSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> getObjectsToRemove() {
|
||||||
|
return objectsToRemove;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> getObjectsToAdd() {
|
||||||
|
return objectsToAdd;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.mdm.common;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
private String applicationName;
|
||||||
|
private String appId;
|
||||||
|
private String locationUrl;
|
||||||
|
private String imageUrl;
|
||||||
|
private String platform;
|
||||||
|
private String version;
|
||||||
|
private List<String> userNameList;
|
||||||
|
private List<String> roleNameList;
|
||||||
|
|
||||||
|
public List<DeviceIdentifier> getDeviceIdentifiers() {
|
||||||
|
return deviceIdentifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceIdentifiers(List<DeviceIdentifier> deviceIdentifiers) {
|
||||||
|
this.deviceIdentifiers = deviceIdentifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DeviceIdentifier> deviceIdentifiers;
|
||||||
|
|
||||||
|
|
||||||
|
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 getPlatform() {
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlatform(String platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.mdm.common;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
import javax.ws.rs.ext.MessageBodyReader;
|
||||||
|
import javax.ws.rs.ext.MessageBodyWriter;
|
||||||
|
import javax.ws.rs.ext.Provider;
|
||||||
|
import java.io.*;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||||
|
|
||||||
|
@Provider
|
||||||
|
@Produces(APPLICATION_JSON)
|
||||||
|
@Consumes(APPLICATION_JSON)
|
||||||
|
public class GsonMessageBodyHandler implements MessageBodyWriter<Object>, MessageBodyReader<Object> {
|
||||||
|
|
||||||
|
private Gson gson;
|
||||||
|
private static final String UTF_8 = "UTF-8";
|
||||||
|
|
||||||
|
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Gson getGson() {
|
||||||
|
if (gson == null) {
|
||||||
|
final GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
|
gson = gsonBuilder.create();
|
||||||
|
}
|
||||||
|
return gson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object readFrom(Class<Object> objectClass, Type type, Annotation[] annotations, MediaType mediaType,
|
||||||
|
MultivaluedMap<String, String> stringStringMultivaluedMap, InputStream entityStream)
|
||||||
|
throws IOException, WebApplicationException {
|
||||||
|
|
||||||
|
InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8");
|
||||||
|
|
||||||
|
try {
|
||||||
|
return getGson().fromJson(reader, type);
|
||||||
|
} finally {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSize(Object o, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeTo(Object object, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType,
|
||||||
|
MultivaluedMap<String, Object> stringObjectMultivaluedMap, OutputStream entityStream)
|
||||||
|
throws IOException, WebApplicationException {
|
||||||
|
|
||||||
|
OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8);
|
||||||
|
try {
|
||||||
|
Type jsonType = null;
|
||||||
|
if (type.equals(type)) {
|
||||||
|
jsonType = type;
|
||||||
|
}
|
||||||
|
getGson().toJson(object, jsonType, writer);
|
||||||
|
} finally {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,858 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- This file contains the list of permissions that are associated with URL end points
|
||||||
|
of the web app. Each permission should contain the name, permission path ,API path
|
||||||
|
(URL) , HTTP method and OAUTH2 authorization scope (not-required).
|
||||||
|
When defining dynamic paths for APIs, path variables are denoted by '*' notation.
|
||||||
|
For ex:
|
||||||
|
Actual API endpoint: mdm-admin/1.0.0/devices/{device-id}
|
||||||
|
URL to be represented here: /devices/*
|
||||||
|
NOTE: All the endpoints of the web app should be available in this file. Otherwise
|
||||||
|
it will result 403 error at the runtime.
|
||||||
|
-->
|
||||||
|
<PermissionConfiguration>
|
||||||
|
<APIVersion></APIVersion>
|
||||||
|
<!-- Device related APIs -->
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Device Management</name>
|
||||||
|
<path>/device-mgt</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Device Management Admin</name>
|
||||||
|
<path>/device-mgt/emm-admin</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Device Management User</name>
|
||||||
|
<path>/device-mgt/user</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Devices</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Policies</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Notifications</name>
|
||||||
|
<path>/device-mgt/emm-admin/notifications</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Users</name>
|
||||||
|
<path>/device-mgt/emm-admin/users</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Operations</name>
|
||||||
|
<path>/device-mgt/emm-admin/operations</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Applications</name>
|
||||||
|
<path>/device-mgt/emm-admin/operations/applications</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Roles</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Configurations</name>
|
||||||
|
<path>/device-mgt/emm-admin/platform-configs</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View Dashboard</name>
|
||||||
|
<path>/device-mgt/emm-admin/dashboard</path>
|
||||||
|
<url>/</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List devices</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/list</path>
|
||||||
|
<url>/devices</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List devices</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/list</path>
|
||||||
|
<url>/devices/types</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/devices/types</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Edit policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/update</path>
|
||||||
|
<url>/devices/types</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/view</path>
|
||||||
|
<url>/devices/view</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/user/devices/view</path>
|
||||||
|
<url>/devices/view</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<!--<Permission>-->
|
||||||
|
<!--<name>Get device</name>-->
|
||||||
|
<!--<path>/device-mgt/devices/view</path>-->
|
||||||
|
<!--<url>/devices/*/*</url>-->
|
||||||
|
<!--<method>GET</method>-->
|
||||||
|
<!--<scope>emm_admin,emm_user</scope>-->
|
||||||
|
<!--</Permission>-->
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/view</path>
|
||||||
|
<url>/devices/user/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List devices</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/list</path>
|
||||||
|
<url>/devices/count</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List devices</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/list</path>
|
||||||
|
<url>/devices/name/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
<!-- End of Device related APIs -->
|
||||||
|
|
||||||
|
<!-- Notification related APIs -->
|
||||||
|
<Permission>
|
||||||
|
<name>View notifications</name>
|
||||||
|
<path>/device-mgt/emm-admin/notifications/view</path>
|
||||||
|
<url>/notifications</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add notification</name>
|
||||||
|
<path>/device-mgt/emm-admin/notifications/add</path>
|
||||||
|
<url>/notifications</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Update notification</name>
|
||||||
|
<path>/device-mgt/emm-admin/notifications/update</path>
|
||||||
|
<url>/notifications/*/*</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View notifications</name>
|
||||||
|
<path>/device-mgt/emm-admin/notifications/view</path>
|
||||||
|
<url>/notifications/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
<!-- End of Notification related APIs -->
|
||||||
|
|
||||||
|
<!-- Operations related APIs -->
|
||||||
|
<Permission>
|
||||||
|
<name>View user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/view</path>
|
||||||
|
<url>/operations</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Install application</name>
|
||||||
|
<path>/device-mgt/emm-admin/operations/applications/install-applications</path>
|
||||||
|
<url>/operations</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Install application</name>
|
||||||
|
<path>/device-mgt/emm-admin/operations/applications/install-applications</path>
|
||||||
|
<url>/operations/installApp/*</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Uninstall application</name>
|
||||||
|
<path>/device-mgt/emm-admin/operations/applications/uninstall-applications</path>
|
||||||
|
<url>/operations/uninstallApp/*</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View application</name>
|
||||||
|
<path>/device-mgt/emm-admin/operations/applications/view-applications</path>
|
||||||
|
<url>/operations/*/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View devices</name>
|
||||||
|
<path>/device-mgt/user/devices/view</path>
|
||||||
|
<url>/operations/*/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/view</path>
|
||||||
|
<url>/operations/*/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/view</path>
|
||||||
|
<url>/operations/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/view</path>
|
||||||
|
<url>/operations/paginate/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/user/devices/view</path>
|
||||||
|
<url>/operations/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/user/devices/view</path>
|
||||||
|
<url>/operations/paginate/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<!--<Permission>-->
|
||||||
|
<!--<name>Get Applications For Device Type</name>-->
|
||||||
|
<!--<path>/device-mgt/operations/application/view</path>-->
|
||||||
|
<!--<url>/operations/*</url>-->
|
||||||
|
<!--<method>GET</method>-->
|
||||||
|
<!--<scope>emm_admin,emm_user</scope>-->
|
||||||
|
<!--</Permission>-->
|
||||||
|
<!-- End of Operations related APIs -->
|
||||||
|
|
||||||
|
<!-- Feature related APIs -->
|
||||||
|
<Permission>
|
||||||
|
<name>List policies</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/list</path>
|
||||||
|
<url>/features/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/view</path>
|
||||||
|
<url>/features/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/user/devices/view</path>
|
||||||
|
<url>/features/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/user/devices/view</path>
|
||||||
|
<url>/features</url>
|
||||||
|
<method>GET</method>
|
||||||
|
<scope>emm_admin</scope>
|
||||||
|
</Permission>
|
||||||
|
<!-- End of Feature related APIs -->
|
||||||
|
|
||||||
|
<!-- Role related APIs -->
|
||||||
|
<Permission>
|
||||||
|
<name>List roles</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles/list</path>
|
||||||
|
<url>/roles</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/view</path>
|
||||||
|
<url>/roles</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/roles</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Update policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/update</path>
|
||||||
|
<url>/roles</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List roles</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles/list</path>
|
||||||
|
<url>/roles/permissions</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List roles</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles/list</path>
|
||||||
|
<url>/roles/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/add</path>
|
||||||
|
<url>/roles/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Update role</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles/update</path>
|
||||||
|
<url>/roles</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<!--<Permission>-->
|
||||||
|
<!--<name>Update a specific role</name>-->
|
||||||
|
<!--<path>/device-mgt/roles/update</path>-->
|
||||||
|
<!--<url>/roles/*</url>-->
|
||||||
|
<!--<method>PUT</method>-->
|
||||||
|
<!--<scope>emm_admin</scope>-->
|
||||||
|
<!--</Permission>-->
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Update role</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles/update</path>
|
||||||
|
<url>/roles/users</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add role</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles/add</path>
|
||||||
|
<url>/roles</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Remove role</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles/remove</path>
|
||||||
|
<url>/roles</url>
|
||||||
|
<method>DELETE</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List roles</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles/list</path>
|
||||||
|
<url>/roles/count</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
<!-- End of Role related APIs -->
|
||||||
|
|
||||||
|
<!-- User related APIs -->
|
||||||
|
<Permission>
|
||||||
|
<name>List users</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/list</path>
|
||||||
|
<url>/users</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/add</path>
|
||||||
|
<url>/users</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/view</path>
|
||||||
|
<url>/users/view</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Update user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/update</path>
|
||||||
|
<url>/users</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Change user password</name>
|
||||||
|
<path>/login</path>
|
||||||
|
<url>/users/change-password</url>
|
||||||
|
<method>POST</method>
|
||||||
|
<scope>emm_admin</scope>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Reset password</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/password-reset</path>
|
||||||
|
<url>/users/reset-password</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Remove user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/remove</path>
|
||||||
|
<url>/users</url>
|
||||||
|
<method>DELETE</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/view</path>
|
||||||
|
<url>/users/roles</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<!--<Permission>-->
|
||||||
|
<!--<name>Get user roles by name</name>-->
|
||||||
|
<!--<path>/device-mgt/emm-admin/users/view</path>-->
|
||||||
|
<!--<url>/roles</url>-->
|
||||||
|
<!--<method>GET</method>-->
|
||||||
|
<!--</Permission>-->
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/add</path>
|
||||||
|
<url>/roles</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List devices</name>
|
||||||
|
<path>/device-mgt/user/devices/list</path>
|
||||||
|
<url>/users/devices</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List devices</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/list</path>
|
||||||
|
<url>/users/devices</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/view</path>
|
||||||
|
<url>/users/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List users</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/list</path>
|
||||||
|
<url>/users/count</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List users</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/list</path>
|
||||||
|
<url>/users/view-users</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add role</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles/add</path>
|
||||||
|
<url>/users/view-users</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Update role</name>
|
||||||
|
<path>/device-mgt/emm-admin/roles/update</path>
|
||||||
|
<url>/users/view-users</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/users/view-users</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Update policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/update</path>
|
||||||
|
<url>/users/view-users</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List users</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/list</path>
|
||||||
|
<url>/users/users-by-username</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List users</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/list</path>
|
||||||
|
<url>/users/users-by-username/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Invite user</name>
|
||||||
|
<path>/device-mgt/emm-admin/users/invite</path>
|
||||||
|
<url>/users/email-invitation</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Authorize user</name>
|
||||||
|
<path>/login</path>
|
||||||
|
<url>/users/authorize</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
<!-- End of User related APIs -->
|
||||||
|
|
||||||
|
<!-- Policy related APIs -->
|
||||||
|
<Permission>
|
||||||
|
<name>Add Policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/policies/inactive-policy</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List policies</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/list</path>
|
||||||
|
<url>/policies/*/*</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List policies</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/list</path>
|
||||||
|
<url>/policies/*/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/emm-admin/devices/view</path>
|
||||||
|
<url>/policies/*/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>View device</name>
|
||||||
|
<path>/device-mgt/user/devices/view</path>
|
||||||
|
<url>/policies/*/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/policies/active-policy</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Remove policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/remove</path>
|
||||||
|
<url>/policies/bulk-remove</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List policies</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/list</path>
|
||||||
|
<url>/policies</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List policies</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/list</path>
|
||||||
|
<url>/policies/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Update policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/update</path>
|
||||||
|
<url>/policies/*</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Remove policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/remove</path>
|
||||||
|
<url>/policies</url>
|
||||||
|
<method>DELETE</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List policies</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/list</path>
|
||||||
|
<url>/policies/count</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Edit policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/update</path>
|
||||||
|
<url>/policies/priorities</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Edit policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/update</path>
|
||||||
|
<url>/policies/activate</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/policies/activate</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Edit policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/update</path>
|
||||||
|
<url>/policies/inactivate</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/policies/inactivate</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Edit policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/update</path>
|
||||||
|
<url>/policies/apply-changes</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/policies/start-task/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/policies/update-task/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/policies/stop-task</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>List policies</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/list</path>
|
||||||
|
<url>/policies/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
<!-- End of Policy related APIs -->
|
||||||
|
|
||||||
|
<!-- Profile related APIs -->
|
||||||
|
<Permission>
|
||||||
|
<name>Add policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/add</path>
|
||||||
|
<url>/profiles</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Edit policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/update</path>
|
||||||
|
<url>/profiles/*</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Remove policy</name>
|
||||||
|
<path>/device-mgt/emm-admin/policies/remove</path>
|
||||||
|
<url>/profiles/*</url>
|
||||||
|
<method>DELETE</method>
|
||||||
|
</Permission>
|
||||||
|
<!-- 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 -->
|
||||||
|
<!--<Permission>-->
|
||||||
|
<!--<name>Get license</name>-->
|
||||||
|
<!--<path>/device-mgt/license/view</path>-->
|
||||||
|
<!--<url>/license/*/*</url>-->
|
||||||
|
<!--<method>GET</method>-->
|
||||||
|
<!--<scope>emm_admin</scope>-->
|
||||||
|
<!--</Permission>-->
|
||||||
|
<!--<Permission>-->
|
||||||
|
<!--<name>Add license</name>-->
|
||||||
|
<!--<path>/device-mgt/license/add</path>-->
|
||||||
|
<!--<url>/license</url>-->
|
||||||
|
<!--<method>POST</method>-->
|
||||||
|
<!--<scope>emm_admin</scope>-->
|
||||||
|
<!--</Permission>-->
|
||||||
|
<!-- End of License related APIs -->
|
||||||
|
|
||||||
|
<!-- Configuration related APIs -->
|
||||||
|
<Permission>
|
||||||
|
<name>View configuration</name>
|
||||||
|
<path>/device-mgt/emm-admin/platform-configs/view</path>
|
||||||
|
<url>/configuration</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Add configuration</name>
|
||||||
|
<path>/device-mgt/emm-admin/platform-configs/add</path>
|
||||||
|
<url>/configuration</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Update configuration</name>
|
||||||
|
<path>/device-mgt/emm-admin/platform-configs/modify</path>
|
||||||
|
<url>/configuration</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<!-- End of Configuration related APIs -->
|
||||||
|
|
||||||
|
<!-- Certificate related APIs -->
|
||||||
|
<Permission>
|
||||||
|
<name>Save certificate in the database</name>
|
||||||
|
<path>/device-mgt/android/certificate/save</path>
|
||||||
|
<url>/certificates/saveCertificate</url>
|
||||||
|
<method>POST</method>
|
||||||
|
<scope>emm_admin</scope>
|
||||||
|
</Permission>
|
||||||
|
<Permission>
|
||||||
|
<name>get certificate in the database</name>
|
||||||
|
<path>/device-mgt/android/certificate/Get</path>
|
||||||
|
<url>/certificates/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
<scope>emm_admin</scope>
|
||||||
|
</Permission>
|
||||||
|
<Permission>
|
||||||
|
<name>get certificate in the database</name>
|
||||||
|
<path>/device-mgt/android/certificate/Get</path>
|
||||||
|
<url>/certificates/*</url>
|
||||||
|
<method>DELETE</method>
|
||||||
|
<scope>emm_admin</scope>
|
||||||
|
</Permission>
|
||||||
|
<!-- End of Certificate related APIs -->
|
||||||
|
</PermissionConfiguration>
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
This file defines class loading policy of the whole container. But this behaviour can be overridden by individual webapps by putting this file into the META-INF/ directory.
|
||||||
|
-->
|
||||||
|
<Classloading xmlns="http://wso2.org/projects/as/classloading">
|
||||||
|
|
||||||
|
<!-- Parent-first or child-first. Default behaviour is child-first.-->
|
||||||
|
<ParentFirst>false</ParentFirst>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Default environments that contains provides to all the webapps. This can be overridden by individual webapps by specifing required environments
|
||||||
|
Tomcat environment is the default and every webapps gets it even if they didn't specify it.
|
||||||
|
e.g. If a webapps requires CXF, they will get both Tomcat and CXF.
|
||||||
|
-->
|
||||||
|
<Environments>CXF,Carbon</Environments>
|
||||||
|
</Classloading>
|
||||||
@ -0,0 +1,178 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||||
|
xsi:schemaLocation="
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||||
|
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||||
|
|
||||||
|
<jaxrs:server id="operationService" address="/operations">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="operationServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="featureService" address="/features">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="featureServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="deviceService" address="/devices">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="deviceServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="userService" address="/users">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="userServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="roleService" address="/roles">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="roleServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="policyService" address="/policies">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="policyServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="profileService" address="/profiles">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="profileServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="configurationService" address="/configuration">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="configurationServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="licenseService" address="/license">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="licenseServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="certificateService" address="/certificates">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="certificateServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="notificationService" address="/notifications">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="notificationServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</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:serviceBeans>
|
||||||
|
<ref bean="authenticationServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
-->
|
||||||
|
<bean id="operationServiceBean" class="org.wso2.carbon.mdm.api.Operation"/>
|
||||||
|
<bean id="deviceServiceBean" class="org.wso2.carbon.mdm.api.MobileDevice"/>
|
||||||
|
<bean id="userServiceBean" class="org.wso2.carbon.mdm.api.User"/>
|
||||||
|
<bean id="roleServiceBean" class="org.wso2.carbon.mdm.api.Role"/>
|
||||||
|
<bean id="featureServiceBean" class="org.wso2.carbon.mdm.api.Feature"/>
|
||||||
|
<bean id="configurationServiceBean" class="org.wso2.carbon.mdm.api.Configuration"/>
|
||||||
|
<bean id="notificationServiceBean" class="org.wso2.carbon.mdm.api.DeviceNotification"/>
|
||||||
|
<bean id="licenseServiceBean" class="org.wso2.carbon.mdm.api.License"/>
|
||||||
|
<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="policyServiceBean" class="org.wso2.carbon.mdm.api.Policy"/>
|
||||||
|
<bean id="profileServiceBean" class="org.wso2.carbon.mdm.api.Profile"/>
|
||||||
|
<bean id="jsonProvider" class="org.wso2.mdm.common.GsonMessageBodyHandler"/>
|
||||||
|
<bean id="errorHandler" class="org.wso2.carbon.mdm.api.common.ErrorHandler"/>
|
||||||
|
|
||||||
|
</beans>
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
~ Version 2.0 (the "License"); you may not use this file except
|
||||||
|
~ in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
|
~ software distributed under the License is distributed on an
|
||||||
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
~ KIND, either express or implied. See the License for the
|
||||||
|
~ specific language governing permissions and limitations
|
||||||
|
~ under the License.
|
||||||
|
-->
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
|
||||||
|
<display-name>Admin-Webapp</display-name>
|
||||||
|
<servlet>
|
||||||
|
<description>JAX-WS/JAX-RS MDM Endpoint</description>
|
||||||
|
<display-name>JAX-WS/JAX-RS Servlet</display-name>
|
||||||
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
|
<servlet-class>
|
||||||
|
org.apache.cxf.transport.servlet.CXFServlet
|
||||||
|
</servlet-class>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<session-config>
|
||||||
|
<session-timeout>60</session-timeout>
|
||||||
|
</session-config>
|
||||||
|
|
||||||
|
<context-param>
|
||||||
|
<param-name>isAdminService</param-name>
|
||||||
|
<param-value>false</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>doAuthentication</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<!--context-param>
|
||||||
|
<param-name>managed-api-enabled</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>managed-api-owner</param-name>
|
||||||
|
<param-value>admin</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>managed-api-version</param-name>
|
||||||
|
<param-value>1.0.0</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>managed-api-isSecured</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param-->
|
||||||
|
|
||||||
|
<!-- Below configuration is used to redirect http requests to https -->
|
||||||
|
<security-constraint>
|
||||||
|
<web-resource-collection>
|
||||||
|
<web-resource-name>MDM-Admin</web-resource-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</web-resource-collection>
|
||||||
|
<user-data-constraint>
|
||||||
|
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
|
||||||
|
</user-data-constraint>
|
||||||
|
</security-constraint>
|
||||||
|
|
||||||
|
</web-app>
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 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
|
||||||
@ -11,15 +11,18 @@
|
|||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.dao;
|
package org.wso2.carbon.device.mgt.core.dao;
|
||||||
|
|
||||||
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.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -211,6 +214,16 @@ public interface DeviceDAO {
|
|||||||
*/
|
*/
|
||||||
List<Device> getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException;
|
List<Device> getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to retrieve the device count of a given tenant.
|
||||||
|
*
|
||||||
|
* @param username user name.
|
||||||
|
* @param tenantId tenant id.
|
||||||
|
* @return returns the device count.
|
||||||
|
* @throws DeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
int getDeviceCount(String username, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is used to retrieve the device count of a given tenant.
|
* This method is used to retrieve the device count of a given tenant.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 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
|
||||||
@ -11,7 +11,7 @@
|
|||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
@ -29,11 +29,15 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|||||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
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.DeviceType;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
||||||
@ -331,6 +335,39 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
return DeviceManagementDAOFactory.getConnection();
|
return DeviceManagementDAOFactory.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get device count of user.
|
||||||
|
*
|
||||||
|
* @return device count
|
||||||
|
* @throws DeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getDeviceCount(String username, int tenantId) throws DeviceManagementDAOException {
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
int deviceCount = 0;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "SELECT COUNT(d1.DEVICE_ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID FROM " +
|
||||||
|
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE " +
|
||||||
|
"d1.DEVICE_ID = e.DEVICE_ID AND e.OWNER = ? AND TENANT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setString(2, username);
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (rs.next()) {
|
||||||
|
deviceCount = rs.getInt("DEVICE_COUNT");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while getting the device count", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return deviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get device count of all devices.
|
* Get device count of all devices.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -237,7 +237,7 @@ public class GroupDAOImpl implements GroupDAO {
|
|||||||
List<DeviceGroupBuilder> deviceGroups = new ArrayList<>();
|
List<DeviceGroupBuilder> deviceGroups = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Connection conn = GroupManagementDAOFactory.getConnection();
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT DESCRIPTION, GROUP_NAME, DATE_OF_CREATE, DATE_OF_LAST_UPDATE, OWNER "
|
String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, DATE_OF_CREATE, DATE_OF_LAST_UPDATE, OWNER "
|
||||||
+ "FROM DM_GROUP WHERE GROUP_NAME LIKE ? AND TENANT_ID = ?";
|
+ "FROM DM_GROUP WHERE GROUP_NAME LIKE ? AND TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, "%" + groupName + "%");
|
stmt.setString(1, "%" + groupName + "%");
|
||||||
|
|||||||
@ -1,20 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* 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
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* 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.
|
|
||||||
*
|
*
|
||||||
|
* 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.core.group.mgt.dao;
|
package org.wso2.carbon.device.mgt.core.group.mgt.dao;
|
||||||
@ -39,7 +38,7 @@ public class GroupManagementDAOFactory {
|
|||||||
|
|
||||||
private static final Log log = LogFactory.getLog(GroupManagementDAOFactory.class);
|
private static final Log log = LogFactory.getLog(GroupManagementDAOFactory.class);
|
||||||
private static DataSource dataSource;
|
private static DataSource dataSource;
|
||||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get instance of GroupDAO
|
* Get instance of GroupDAO
|
||||||
@ -162,7 +161,8 @@ public class GroupManagementDAOFactory {
|
|||||||
Connection conn = currentConnection.get();
|
Connection conn = currentConnection.get();
|
||||||
if (conn == null) {
|
if (conn == null) {
|
||||||
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
|
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
|
||||||
"This might have ideally been caused by not properly initiating the transaction via " +
|
"This might have ideally been caused by not properly " +
|
||||||
|
"initiating the transaction via " +
|
||||||
"'beginTransaction'/'openConnection' methods");
|
"'beginTransaction'/'openConnection' methods");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -82,6 +82,7 @@ public final class GroupManagementDAOUtil {
|
|||||||
|
|
||||||
public static DeviceGroupBuilder loadGroup(ResultSet resultSet) throws SQLException {
|
public static DeviceGroupBuilder loadGroup(ResultSet resultSet) throws SQLException {
|
||||||
DeviceGroupBuilder group = new DeviceGroupBuilder(new DeviceGroup());
|
DeviceGroupBuilder group = new DeviceGroupBuilder(new DeviceGroup());
|
||||||
|
group.setGroupId(resultSet.getInt("ID"));
|
||||||
group.setDescription(resultSet.getString("DESCRIPTION"));
|
group.setDescription(resultSet.getString("DESCRIPTION"));
|
||||||
group.setName(resultSet.getString("GROUP_NAME"));
|
group.setName(resultSet.getString("GROUP_NAME"));
|
||||||
group.setDateOfCreation(resultSet.getLong("DATE_OF_CREATE"));
|
group.setDateOfCreation(resultSet.getLong("DATE_OF_CREATE"));
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 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
|
||||||
@ -11,7 +11,7 @@
|
|||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
@ -43,6 +43,7 @@ import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
|||||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.config.tenant.TenantConfigurationManagementServiceImpl;
|
import org.wso2.carbon.device.mgt.core.config.tenant.TenantConfigurationManagementServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl;
|
import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||||
@ -53,7 +54,6 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceIm
|
|||||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
|
||||||
import org.wso2.carbon.email.sender.core.service.EmailSenderService;
|
|
||||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
@ -103,14 +103,32 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class DeviceManagementServiceComponent {
|
public class DeviceManagementServiceComponent {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
|
|
||||||
|
|
||||||
private static final Object LOCK = new Object();
|
private static final Object LOCK = new Object();
|
||||||
|
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
|
||||||
private static List<PluginInitializationListener> listeners = new ArrayList<>();
|
private static List<PluginInitializationListener> listeners = new ArrayList<>();
|
||||||
private static List<DeviceManagementService> deviceManagers = new ArrayList<>();
|
private static List<DeviceManagementService> deviceManagers = new ArrayList<>();
|
||||||
private static List<DeviceManagerStartupListener> startupListeners = new ArrayList<>();
|
private static List<DeviceManagerStartupListener> startupListeners = new ArrayList<>();
|
||||||
private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
|
private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
|
||||||
|
|
||||||
|
public static void registerPluginInitializationListener(PluginInitializationListener listener) {
|
||||||
|
synchronized (LOCK) {
|
||||||
|
listeners.add(listener);
|
||||||
|
for (DeviceManagementService deviceManagementService : deviceManagers) {
|
||||||
|
listener.registerDeviceManagementService(deviceManagementService);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerStartupListener(DeviceManagerStartupListener startupListener) {
|
||||||
|
startupListeners.add(startupListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void notifyStartupListeners() {
|
||||||
|
for (DeviceManagerStartupListener startupListener : startupListeners) {
|
||||||
|
startupListener.notifyObserver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
protected void activate(ComponentContext componentContext) {
|
protected void activate(ComponentContext componentContext) {
|
||||||
try {
|
try {
|
||||||
@ -124,6 +142,7 @@ public class DeviceManagementServiceComponent {
|
|||||||
|
|
||||||
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
|
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
|
||||||
DeviceManagementDAOFactory.init(dsConfig);
|
DeviceManagementDAOFactory.init(dsConfig);
|
||||||
|
GroupManagementDAOFactory.init(dsConfig);
|
||||||
NotificationManagementDAOFactory.init(dsConfig);
|
NotificationManagementDAOFactory.init(dsConfig);
|
||||||
|
|
||||||
OperationManagementDAOFactory.init(dsConfig);
|
OperationManagementDAOFactory.init(dsConfig);
|
||||||
@ -135,7 +154,7 @@ public class DeviceManagementServiceComponent {
|
|||||||
if (setupOption != null) {
|
if (setupOption != null) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("-Dsetup is enabled. Device management repository schema initialization is about to " +
|
log.debug("-Dsetup is enabled. Device management repository schema initialization is about to " +
|
||||||
"begin");
|
"begin");
|
||||||
}
|
}
|
||||||
this.setupDeviceManagementSchema(dsConfig);
|
this.setupDeviceManagementSchema(dsConfig);
|
||||||
}
|
}
|
||||||
@ -159,15 +178,6 @@ public class DeviceManagementServiceComponent {
|
|||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerPluginInitializationListener(PluginInitializationListener listener) {
|
|
||||||
synchronized (LOCK) {
|
|
||||||
listeners.add(listener);
|
|
||||||
for (DeviceManagementService deviceManagementService : deviceManagers) {
|
|
||||||
listener.registerDeviceManagementService(deviceManagementService);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initOperationsManager() throws OperationManagementException {
|
private void initOperationsManager() throws OperationManagementException {
|
||||||
OperationManager operationManager = new OperationManagerImpl();
|
OperationManager operationManager = new OperationManagerImpl();
|
||||||
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
|
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
|
||||||
@ -349,14 +359,4 @@ public class DeviceManagementServiceComponent {
|
|||||||
DeviceManagementDataHolder.getInstance().setConfigurationContextService(null);
|
DeviceManagementDataHolder.getInstance().setConfigurationContextService(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerStartupListener(DeviceManagerStartupListener startupListener) {
|
|
||||||
startupListeners.add(startupListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void notifyStartupListeners() {
|
|
||||||
for (DeviceManagerStartupListener startupListener : startupListeners) {
|
|
||||||
startupListener.notifyObserver();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 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
|
||||||
@ -11,13 +11,19 @@
|
|||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.service;
|
package org.wso2.carbon.device.mgt.core.service;
|
||||||
|
|
||||||
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.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
@ -112,6 +118,15 @@ public interface DeviceManagementProviderService extends OperationManager {
|
|||||||
*/
|
*/
|
||||||
List<Device> getAllDevicesOfRole(String roleName) throws DeviceManagementException;
|
List<Device> getAllDevicesOfRole(String roleName) throws DeviceManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to get the device count of user.
|
||||||
|
*
|
||||||
|
* @return device count
|
||||||
|
* @throws DeviceManagementException If some unusual behaviour is observed while counting
|
||||||
|
* the devices
|
||||||
|
*/
|
||||||
|
int getDeviceCount(String username) throws DeviceManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get the count of all types of devices.
|
* Method to get the count of all types of devices.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 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
|
||||||
@ -11,7 +11,7 @@
|
|||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
@ -20,7 +20,16 @@ package org.wso2.carbon.device.mgt.core.service;
|
|||||||
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.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
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.DeviceManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
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.LicenseManagementException;
|
||||||
@ -28,7 +37,11 @@ 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.OperationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.*;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||||
|
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.dao.EnrollmentDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
||||||
@ -38,18 +51,23 @@ import org.wso2.carbon.email.sender.core.TypedValue;
|
|||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
|
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
|
||||||
PluginInitializationListener {
|
PluginInitializationListener {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
|
||||||
private DeviceDAO deviceDAO;
|
private DeviceDAO deviceDAO;
|
||||||
private DeviceTypeDAO deviceTypeDAO;
|
private DeviceTypeDAO deviceTypeDAO;
|
||||||
private EnrollmentDAO enrollmentDAO;
|
private EnrollmentDAO enrollmentDAO;
|
||||||
private DeviceManagementPluginRepository pluginRepository;
|
private DeviceManagementPluginRepository pluginRepository;
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
|
|
||||||
|
|
||||||
public DeviceManagementProviderServiceImpl() {
|
public DeviceManagementProviderServiceImpl() {
|
||||||
this.pluginRepository = new DeviceManagementPluginRepository();
|
this.pluginRepository = new DeviceManagementPluginRepository();
|
||||||
initDataAccessObjects();
|
initDataAccessObjects();
|
||||||
@ -1012,6 +1030,21 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDeviceCount(String username) throws DeviceManagementException {
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
return deviceDAO.getDeviceCount(username, this.getTenantId());
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
throw new DeviceManagementException("Error occurred while retrieving the device count of user '"
|
||||||
|
+ username + "'", e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDeviceCount() throws DeviceManagementException {
|
public int getDeviceCount() throws DeviceManagementException {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -93,6 +93,17 @@ public interface GroupManagementProviderService {
|
|||||||
*/
|
*/
|
||||||
PaginationResult getGroups(int startIndex, int rowCount) throws GroupManagementException;
|
PaginationResult getGroups(int startIndex, int rowCount) throws GroupManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get paginated device groups in tenant
|
||||||
|
*
|
||||||
|
* @param username of user.
|
||||||
|
* @param startIndex for pagination.
|
||||||
|
* @param rowCount for pagination.
|
||||||
|
* @return paginated list of groups
|
||||||
|
* @throws GroupManagementException
|
||||||
|
*/
|
||||||
|
PaginationResult getGroups(String username, int startIndex, int rowCount) throws GroupManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all device group count in tenant
|
* Get all device group count in tenant
|
||||||
*
|
*
|
||||||
|
|||||||
@ -263,6 +263,34 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
return paginationResult;
|
return paginationResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getGroups(String username, int startIndex, int rowCount) throws GroupManagementException {
|
||||||
|
Map<Integer, DeviceGroup> groups = new HashMap<>();
|
||||||
|
UserStoreManager userStoreManager;
|
||||||
|
try {
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
||||||
|
.getUserStoreManager();
|
||||||
|
String[] roleList = userStoreManager.getRoleListOfUser(username);
|
||||||
|
int index = 0;
|
||||||
|
for (String role : roleList) {
|
||||||
|
if (role != null && role.contains("Internal/group-")) {
|
||||||
|
DeviceGroupBuilder deviceGroupBuilder = extractNewGroupFromRole(groups, role);
|
||||||
|
if (deviceGroupBuilder != null && startIndex <= index++ && index <= rowCount) {
|
||||||
|
groups.put(deviceGroupBuilder.getGroupId(), deviceGroupBuilder.getGroup());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
throw new GroupManagementException("Error occurred while getting user store manager.", e);
|
||||||
|
}
|
||||||
|
PaginationResult paginationResult = new PaginationResult();
|
||||||
|
paginationResult.setRecordsTotal(getGroupCount());
|
||||||
|
paginationResult.setData(new ArrayList<>(groups.values()));
|
||||||
|
paginationResult.setRecordsFiltered(groups.size());
|
||||||
|
return paginationResult;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getGroupCount() throws GroupManagementException {
|
public int getGroupCount() throws GroupManagementException {
|
||||||
try {
|
try {
|
||||||
@ -563,7 +591,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
public List<Device> getDevices(String groupName, String owner) throws GroupManagementException {
|
public List<Device> getDevices(String groupName, String owner) throws GroupManagementException {
|
||||||
try {
|
try {
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
GroupManagementDAOFactory.getConnection();
|
GroupManagementDAOFactory.openConnection();
|
||||||
return this.groupDAO.getDevices(groupName, owner, tenantId);
|
return this.groupDAO.getDevices(groupName, owner, tenantId);
|
||||||
} catch (GroupManagementDAOException e) {
|
} catch (GroupManagementDAOException e) {
|
||||||
throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
||||||
@ -583,7 +611,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
List<Device> devices;
|
List<Device> devices;
|
||||||
try {
|
try {
|
||||||
GroupManagementDAOFactory.getConnection();
|
GroupManagementDAOFactory.openConnection();
|
||||||
devices = this.groupDAO.getDevices(groupName, owner, startIndex, rowCount, tenantId);
|
devices = this.groupDAO.getDevices(groupName, owner, startIndex, rowCount, tenantId);
|
||||||
} catch (GroupManagementDAOException e) {
|
} catch (GroupManagementDAOException e) {
|
||||||
throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
||||||
@ -606,7 +634,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
public int getDeviceCount(String groupName, String owner) throws GroupManagementException {
|
public int getDeviceCount(String groupName, String owner) throws GroupManagementException {
|
||||||
try {
|
try {
|
||||||
int count;
|
int count;
|
||||||
GroupManagementDAOFactory.getConnection();
|
GroupManagementDAOFactory.openConnection();
|
||||||
count = groupDAO.getDeviceCount(groupName, owner,
|
count = groupDAO.getDeviceCount(groupName, owner,
|
||||||
CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||||
return count;
|
return count;
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
* This backendServiceInvoker contains the wrappers for back end jaggary calls.
|
* This backendServiceInvoker contains the wrappers for back end jaggary calls.
|
||||||
*/
|
*/
|
||||||
var backendServiceInvoker = function () {
|
var backendServiceInvoker = function () {
|
||||||
var log = new Log("/app/modules/backend-service-invoker.js")
|
var log = new Log("/app/modules/backend-service-invoker.js");
|
||||||
var publicXMLHTTPInvokers = {};
|
var publicXMLHTTPInvokers = {};
|
||||||
var privateMethods = {};
|
var privateMethods = {};
|
||||||
var publicWSInvokers = {};
|
var publicWSInvokers = {};
|
||||||
@ -72,14 +72,12 @@ var backendServiceInvoker = function () {
|
|||||||
} else {
|
} else {
|
||||||
xmlHttpRequest.send();
|
xmlHttpRequest.send();
|
||||||
}
|
}
|
||||||
log.debug("Service Invoker-URL: " + url);
|
|
||||||
log.debug("Service Invoker-Method: " + method);
|
|
||||||
|
|
||||||
if ((xmlHttpRequest.status >= 200 && xmlHttpRequest.status < 300) || xmlHttpRequest.status == 302) {
|
if ((xmlHttpRequest.status >= 200 && xmlHttpRequest.status < 300) || xmlHttpRequest.status == 302) {
|
||||||
if (xmlHttpRequest.responseText != null) {
|
if (xmlHttpRequest.responseText != null) {
|
||||||
return successCallback(parse(xmlHttpRequest.responseText));
|
return successCallback(parse(xmlHttpRequest.responseText));
|
||||||
} else {
|
} else {
|
||||||
return successCallback({"statusCode": 200, "messageFromServer": "Operation Completed"});
|
return successCallback({"status": xmlHttpRequest.status, "messageFromServer": "Operation Completed"});
|
||||||
}
|
}
|
||||||
} else if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED ||
|
} else if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED ||
|
||||||
xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) {
|
xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) {
|
||||||
@ -188,7 +186,7 @@ var backendServiceInvoker = function () {
|
|||||||
privateMethods.initiateWSRequest = function (action, endpoint, successCallback, errorCallback, soapVersion, payload) {
|
privateMethods.initiateWSRequest = function (action, endpoint, successCallback, errorCallback, soapVersion, payload) {
|
||||||
var ws = require('ws');
|
var ws = require('ws');
|
||||||
var wsRequest = new ws.WSRequest();
|
var wsRequest = new ws.WSRequest();
|
||||||
var options = new Array();
|
var options = [];
|
||||||
if (IS_OAUTH_ENABLED) {
|
if (IS_OAUTH_ENABLED) {
|
||||||
var accessToken = privateMethods.getAccessToken();
|
var accessToken = privateMethods.getAccessToken();
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
|
|||||||
@ -274,40 +274,39 @@ deviceModule = function () {
|
|||||||
utility.startTenantFlow(carbonUser);
|
utility.startTenantFlow(carbonUser);
|
||||||
|
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/view?type=" + deviceType + "&id=" + deviceId;
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/view?type=" + deviceType + "&id=" + deviceId;
|
||||||
var dataNew = serviceInvokers.XMLHttp.get(
|
return serviceInvokers.XMLHttp.get(
|
||||||
url, function (responsePayload) {
|
url, function (responsePayload) {
|
||||||
var device = responsePayload.responseContent;
|
var device = responsePayload.responseContent;
|
||||||
if (device) {
|
if (device) {
|
||||||
var propertiesList = device["properties"];
|
var propertiesList = device["properties"];
|
||||||
var properties = {};
|
var properties = {};
|
||||||
for (var i = 0; i < propertiesList.length; i++) {
|
for (var i = 0; i < propertiesList.length; i++) {
|
||||||
properties[propertiesList[i]["name"]] =
|
properties[propertiesList[i]["name"]] =
|
||||||
propertiesList[i]["value"];
|
propertiesList[i]["value"];
|
||||||
|
}
|
||||||
|
var deviceObject = {};
|
||||||
|
deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"];
|
||||||
|
deviceObject[constants["DEVICE_NAME"]] = device["name"];
|
||||||
|
deviceObject[constants["DEVICE_OWNERSHIP"]] = device["enrolmentInfo"]["ownership"];
|
||||||
|
deviceObject[constants["DEVICE_OWNER"]] = device["enrolmentInfo"]["owner"];
|
||||||
|
deviceObject[constants["DEVICE_STATUS"]] = device["enrolmentInfo"]["status"];
|
||||||
|
deviceObject[constants["DEVICE_TYPE"]] = device["type"];
|
||||||
|
if (device["type"] == constants["PLATFORM_IOS"]) {
|
||||||
|
properties[constants["DEVICE_MODEL"]] = properties[constants["DEVICE_PRODUCT"]];
|
||||||
|
delete properties[constants["DEVICE_PRODUCT"]];
|
||||||
|
properties[constants["DEVICE_VENDOR"]] = constants["VENDOR_APPLE"];
|
||||||
|
}
|
||||||
|
deviceObject[constants["DEVICE_PROPERTIES"]] = properties;
|
||||||
|
return deviceObject;
|
||||||
}
|
}
|
||||||
var deviceObject = {};
|
|
||||||
deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"];
|
|
||||||
deviceObject[constants["DEVICE_NAME"]] = device["name"];
|
|
||||||
deviceObject[constants["DEVICE_OWNERSHIP"]] = device["enrolmentInfo"]["ownership"];
|
|
||||||
deviceObject[constants["DEVICE_OWNER"]] = device["enrolmentInfo"]["owner"];
|
|
||||||
deviceObject[constants["DEVICE_STATUS"]] = device["enrolmentInfo"]["status"];
|
|
||||||
deviceObject[constants["DEVICE_TYPE"]] = device["type"];
|
|
||||||
if (device["type"] == constants["PLATFORM_IOS"]) {
|
|
||||||
properties[constants["DEVICE_MODEL"]] = properties[constants["DEVICE_PRODUCT"]];
|
|
||||||
delete properties[constants["DEVICE_PRODUCT"]];
|
|
||||||
properties[constants["DEVICE_VENDOR"]] = constants["VENDOR_APPLE"];
|
|
||||||
}
|
|
||||||
deviceObject[constants["DEVICE_PROPERTIES"]] = properties;
|
|
||||||
return deviceObject;
|
|
||||||
}
|
}
|
||||||
}
|
,
|
||||||
,
|
function (responsePayload) {
|
||||||
function (responsePayload) {
|
var response = {};
|
||||||
var response = {};
|
response["status"] = "error";
|
||||||
response["status"] = "error";
|
return response;
|
||||||
return response;
|
}
|
||||||
}
|
|
||||||
);
|
);
|
||||||
return dataNew;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
@ -351,25 +350,32 @@ deviceModule = function () {
|
|||||||
|
|
||||||
publicMethods.getOwnDevicesCount = function () {
|
publicMethods.getOwnDevicesCount = function () {
|
||||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
var listAllDevicesEndPoint = deviceCloudService + "/device/user/" + carbonUser.username + "/all/count";
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + carbonUser.username
|
||||||
return get(listAllDevicesEndPoint, {}, "json").data;
|
+ "/count";
|
||||||
|
return serviceInvokers.XMLHttp.get(
|
||||||
|
url, function (responsePayload) {
|
||||||
|
return responsePayload;
|
||||||
|
}
|
||||||
|
,
|
||||||
|
function (responsePayload) {
|
||||||
|
log.error(responsePayload);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
publicMethods.getUnGroupedDevices = function () {
|
publicMethods.getAllDevicesCount = function () {
|
||||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/count";
|
||||||
var listAllDevicesEndPoint = deviceCloudService + "/device/user/" + carbonUser.username + "/ungrouped";
|
return serviceInvokers.XMLHttp.get(
|
||||||
return get(listAllDevicesEndPoint, {}, "json").data;
|
url, function (responsePayload) {
|
||||||
};
|
return responsePayload;
|
||||||
|
}
|
||||||
publicMethods.getUnGroupedDevicesCount = function () {
|
,
|
||||||
var result = publicMethods.getUnGroupedDevices();
|
function (responsePayload) {
|
||||||
var devices = result.data;
|
log.error(responsePayload);
|
||||||
var count = 0;
|
return -1;
|
||||||
if (devices) {
|
}
|
||||||
count = devices.length;
|
);
|
||||||
}
|
|
||||||
result.data = count;
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
publicMethods.getAllPermittedDevices = function () {
|
publicMethods.getAllPermittedDevices = function () {
|
||||||
|
|||||||
@ -23,169 +23,40 @@ var groupModule = {};
|
|||||||
var constants = require('/app/modules/constants.js');
|
var constants = require('/app/modules/constants.js');
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
var utility = require("/app/modules/utility.js").utility;
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
var deviceCloudService = devicemgtProps["httpsURL"] + "/common/group_manager";
|
var groupServiceEndpoint = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/groups";
|
||||||
|
|
||||||
var user = session.get(constants.USER_SESSION_KEY);
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
var deviceModule = require("/app/modules/device.js").deviceModule;
|
|
||||||
|
|
||||||
var endPoint, data, response;
|
var endPoint;
|
||||||
|
|
||||||
groupModule.addGroup = function (group) {
|
|
||||||
var name = group["name"];
|
|
||||||
var description = group["description"];
|
|
||||||
//URL: POST https://localhost:9443/devicecloud/group_manager/group
|
|
||||||
endPoint = deviceCloudService + "/group";
|
|
||||||
data = {"name": name, "username": user.username, "description": description};
|
|
||||||
return post(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.updateGroup = function (groupId, group) {
|
|
||||||
var name = group["name"];
|
|
||||||
var description = group["description"];
|
|
||||||
//URL: PUT https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId;
|
|
||||||
data = {"name": name, "username": user.username, "description": description};
|
|
||||||
return put(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.removeGroup = function (groupId) {
|
|
||||||
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "?username=" + user.username;
|
|
||||||
return del(endPoint, {}, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.getGroup = function (groupId) {
|
|
||||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId;
|
|
||||||
data = {"username": user.username};
|
|
||||||
return get(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.findGroups = function (name) {
|
|
||||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/name/{name}
|
|
||||||
endPoint = deviceCloudService + "/group/name/" + name;
|
|
||||||
data = {"username": user.username};
|
|
||||||
return get(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.getGroups = function () {
|
|
||||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/all
|
|
||||||
endPoint = deviceCloudService + "/group/user/" + user.username + "/all";
|
|
||||||
data = {"username": user.username};
|
|
||||||
return get(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.getGroupCount = function () {
|
groupModule.getGroupCount = function () {
|
||||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/all/count
|
endPoint = groupServiceEndpoint + "/user/" + user.username + "/count";
|
||||||
endPoint = deviceCloudService + "/group/user/" + user.username + "/all/count";
|
return serviceInvokers.XMLHttp.get(
|
||||||
data = {"username": user.username};
|
endPoint, function (responsePayload) {
|
||||||
response = get(endPoint, data, "json");
|
return responsePayload;
|
||||||
if (response) {
|
|
||||||
return response.data;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.shareGroup = function (groupId, shareUser, role) {
|
|
||||||
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/share";
|
|
||||||
data = {"username": user.username, "shareUser": shareUser, "role": role};
|
|
||||||
return post(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.unshareGroup = function (groupId, shareUser, role) {
|
|
||||||
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/unshare
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/unshare";
|
|
||||||
data = {"username": user.username, "unShareUser": unShareUser, "role": role};
|
|
||||||
return post(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.addRole = function (groupId, role, permissions) {
|
|
||||||
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/role";
|
|
||||||
data = {"username": user.username, "permissions": permissions, "role": role};
|
|
||||||
return post(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.deleteRole = function (groupId, role) {
|
|
||||||
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/role/" + role;
|
|
||||||
return del(endPoint, {}, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.getGroupRoles = function (groupId) {
|
|
||||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role/all
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/role/all";
|
|
||||||
data = {"username": user.username};
|
|
||||||
return get(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.getUserRoles = function (groupId, userId) {
|
|
||||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/{user}/role/all
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId + "/role/all";
|
|
||||||
data = {"username": user.username};
|
|
||||||
return get(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.getRoleMapping = function (groupId, userId) {
|
|
||||||
var allRoles = groupModule.getGroupRoles(groupId).data;
|
|
||||||
var userRolesObj = groupModule.getUserRoles(groupId, userId);
|
|
||||||
var userRoles = userRolesObj.data;
|
|
||||||
var roleMap = [];
|
|
||||||
for (var role in allRoles) {
|
|
||||||
var objRole = {"role": allRoles[role], "assigned": false};
|
|
||||||
for (var usrRole in userRoles) {
|
|
||||||
if (allRoles[role] == userRoles[usrRole]) {
|
|
||||||
objRole.assigned = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
,
|
||||||
roleMap.push(objRole);
|
function (responsePayload) {
|
||||||
}
|
log.error(responsePayload);
|
||||||
var result = {};
|
return -1;
|
||||||
result.data = roleMap;
|
}
|
||||||
result.xhr = userRolesObj.xhr;
|
);
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
groupModule.setRoleMapping = function (groupId, userId, roleMap) {
|
groupModule.getGroupDeviceCount = function (groupName, owner) {
|
||||||
var result;
|
endPoint = groupServiceEndpoint + "/" + owner + "/" + groupName + "/devices/count";
|
||||||
for (var role in roleMap) {
|
return serviceInvokers.XMLHttp.get(
|
||||||
if (roleMap[role].assigned == true) {
|
endPoint, function (responsePayload) {
|
||||||
result = groupModule.shareGroup(groupId,userId,roleMap[role].role);
|
return responsePayload;
|
||||||
} else {
|
}
|
||||||
result = groupModule.unshareGroup(groupId,userId,roleMap[role].role);
|
,
|
||||||
}
|
function (responsePayload) {
|
||||||
}
|
log.error(responsePayload);
|
||||||
return result;
|
return -1;
|
||||||
};
|
}
|
||||||
|
);
|
||||||
groupModule.getUsers = function (groupId) {
|
|
||||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/user/all
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/user/all";
|
|
||||||
data = {"username": user.username};
|
|
||||||
return get(endPoint, data, "json");
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.getDevices = function (groupId) {
|
|
||||||
var result = groupModule.getGroup(groupId);
|
|
||||||
var group = result.data;
|
|
||||||
if (group) {
|
|
||||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/all
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/device/all";
|
|
||||||
data = {"username": user.username};
|
|
||||||
result = get(endPoint, data, "json");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
groupModule.assignDevice = function (groupId, deviceId, deviceType) {
|
|
||||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/assign
|
|
||||||
endPoint = deviceCloudService + "/group/id/" + groupId + "/device/assign";
|
|
||||||
data = {"username": user.username, "deviceId": deviceId, "deviceType": deviceType};
|
|
||||||
return put(endPoint, data, "json");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}(groupModule));
|
}(groupModule));
|
||||||
|
|||||||
@ -53,7 +53,7 @@ var userModule = function () {
|
|||||||
throw constants.ERRORS.USER_NOT_FOUND;
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
}
|
}
|
||||||
return carbonUser;
|
return carbonUser;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only GET method is implemented for now since there are no other type of methods used this method.
|
* Only GET method is implemented for now since there are no other type of methods used this method.
|
||||||
@ -436,7 +436,7 @@ var userModule = function () {
|
|||||||
} finally {
|
} finally {
|
||||||
utility.endTenantFlow();
|
utility.endTenantFlow();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@NewlyAdded
|
@NewlyAdded
|
||||||
@ -629,44 +629,44 @@ var userModule = function () {
|
|||||||
|
|
||||||
publicMethods.getUIPermissions = function () {
|
publicMethods.getUIPermissions = function () {
|
||||||
var permissions = {};
|
var permissions = {};
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/devices/list") ||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/devices/list") ||
|
||||||
publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
||||||
permissions["LIST_DEVICES"] = true;
|
permissions["LIST_DEVICES"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/list")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/list")) {
|
||||||
permissions["LIST_GROUPS"] = true;
|
permissions["LIST_GROUPS"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/list")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/users/list")) {
|
||||||
permissions["LIST_USERS"] = true;
|
permissions["LIST_USERS"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/list")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/roles/list")) {
|
||||||
permissions["LIST_ROLES"] = true;
|
permissions["LIST_ROLES"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/list")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/list")) {
|
||||||
permissions["LIST_POLICIES"] = true;
|
permissions["LIST_POLICIES"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/add")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/groups/add")) {
|
||||||
permissions["ADD_GROUP"] = true;
|
permissions["ADD_GROUP"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/add")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/users/add")) {
|
||||||
permissions["ADD_USER"] = true;
|
permissions["ADD_USER"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/remove")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/users/remove")) {
|
||||||
permissions["REMOVE_USER"] = true;
|
permissions["REMOVE_USER"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/add")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/roles/add")) {
|
||||||
permissions["ADD_ROLE"] = true;
|
permissions["ADD_ROLE"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/add")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/add")) {
|
||||||
permissions["ADD_POLICY"] = true;
|
permissions["ADD_POLICY"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/priority")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/priority")) {
|
||||||
permissions["CHANGE_POLICY_PRIORITY"] = true;
|
permissions["CHANGE_POLICY_PRIORITY"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/dashboard/view")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/dashboard/view")) {
|
||||||
permissions["VIEW_DASHBOARD"] = true;
|
permissions["VIEW_DASHBOARD"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/platform-configs/view")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/platform-configs/view")) {
|
||||||
permissions["TENANT_CONFIGURATION"] = true;
|
permissions["TENANT_CONFIGURATION"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
||||||
|
|||||||
@ -10,5 +10,177 @@
|
|||||||
{{/zone}}
|
{{/zone}}
|
||||||
|
|
||||||
{{#zone "content"}}
|
{{#zone "content"}}
|
||||||
{{unit "cdmf.unit.dashboard"}}
|
<div class="wr-content">
|
||||||
|
{{#if permissions.VIEW_DASHBOARD}}
|
||||||
|
<div class="row wr-stats-board">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="wr-stats-board-tile">
|
||||||
|
<div class="tile-name">Devices</div>
|
||||||
|
<div>
|
||||||
|
<div class="tile-icon"><i class="fw fw-mobile"></i></div>
|
||||||
|
<div class="tile-stats">
|
||||||
|
<span id="device-count">{{device_count}}</span>
|
||||||
|
<span class="tile-stats-free">
|
||||||
|
<a href="{{@app.context}}/devices">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-view fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
View
|
||||||
|
</a>
|
||||||
|
<a href="{{@app.context}}/device/enroll">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
Add
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row wr-stats-board">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="wr-stats-board-tile">
|
||||||
|
<div class="tile-name">Groups</div>
|
||||||
|
<div>
|
||||||
|
<div class="tile-icon"><i class="fw fw-grouping"></i></div>
|
||||||
|
<div class="tile-stats">
|
||||||
|
<span id="group-count">{{group_count}}</span>
|
||||||
|
<span class="tile-stats-free">
|
||||||
|
<a href="{{@app.context}}/groups">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-view fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
View
|
||||||
|
</a>
|
||||||
|
<a href="{{@app.context}}/group/add">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
Add
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row wr-stats-board">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="wr-stats-board-tile">
|
||||||
|
<div class="tile-name">Users</div>
|
||||||
|
<div>
|
||||||
|
<div class="tile-icon"><i class="fw fw-user"></i></div>
|
||||||
|
<div class="tile-stats">
|
||||||
|
<span id="user-count">{{user_count}}</span>
|
||||||
|
<span class="tile-stats-free">
|
||||||
|
<a href="{{@app.context}}/users">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-view fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
View
|
||||||
|
</a>
|
||||||
|
<a href="{{@app.context}}/user/add">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
Add
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row wr-stats-board">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="wr-stats-board-tile">
|
||||||
|
<div class="tile-name">Policies</div>
|
||||||
|
<div>
|
||||||
|
<div class="tile-icon"><i class="fw fw-policy"></i></div>
|
||||||
|
<div class="tile-stats">
|
||||||
|
<span id="policy-count">{{policy_count}}</span>
|
||||||
|
<span class="tile-stats-free">
|
||||||
|
<a href="{{@app.context}}/policies">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-view fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
View
|
||||||
|
</a>
|
||||||
|
<a href="{{@app.context}}/policy/add">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
Add
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row wr-stats-board">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="wr-stats-board-tile">
|
||||||
|
<div class="tile-name">Roles</div>
|
||||||
|
<div>
|
||||||
|
<div class="tile-icon"><i class="fw fw-bookmark"></i></div>
|
||||||
|
<div class="tile-stats">
|
||||||
|
<span id="role-count">{{role_count}}</span>
|
||||||
|
<span class="tile-stats-free">
|
||||||
|
<a id="device-count-view-btn" href="{{@app.context}}/roles">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-view fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
View
|
||||||
|
</a>
|
||||||
|
<a href="{{@app.context}}/roles/add-role">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
Add
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
Permission denied
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div id="qr-code-modal" data-enrollment-url="{{enrollmentURL}}" class="hidden">
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>
|
||||||
|
Scan QR code to start enrollment
|
||||||
|
</h3>
|
||||||
|
<h4>
|
||||||
|
Please scan the QR code using your mobile device to retrieve enrollment URL.
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-body col-centered ">
|
||||||
|
<div class="qr-code"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
@ -35,7 +35,7 @@ function onRequest(context) {
|
|||||||
var groupModule = require("/app/modules/group.js").groupModule;
|
var groupModule = require("/app/modules/group.js").groupModule;
|
||||||
var policyModule = require("/app/modules/policy.js").policyModule;
|
var policyModule = require("/app/modules/policy.js").policyModule;
|
||||||
|
|
||||||
page.device_count = deviceModule.getOwnDevicesCount();
|
page.device_count = deviceModule.getAllDevicesCount();
|
||||||
page.group_count = groupModule.getGroupCount();
|
page.group_count = groupModule.getGroupCount();
|
||||||
page.user_count = userModule.getUsers()["content"].length;
|
page.user_count = userModule.getUsers()["content"].length;
|
||||||
page.policy_count = policyModule.getAllPolicies()["content"].length;
|
page.policy_count = policyModule.getAllPolicies()["content"].length;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{{unit "cdmf.unit.ui.title" pageTitle="Device Management"}}
|
{{unit "cdmf.unit.ui.title" pageTitle="Device Management"}}
|
||||||
|
|
||||||
{{unit "uuf.unit.lib.data-table"}}
|
{{unit "cdmf.unit.data-tables-extended"}}
|
||||||
|
|
||||||
{{#zone "breadcrumbs"}}
|
{{#zone "breadcrumbs"}}
|
||||||
<li>
|
<li>
|
||||||
@ -60,8 +60,273 @@
|
|||||||
<div class="col-md-12 wr-page-content">
|
<div class="col-md-12 wr-page-content">
|
||||||
<div>
|
<div>
|
||||||
{{unit "cdmf.unit.device.operation-mod"}}
|
{{unit "cdmf.unit.device.operation-mod"}}
|
||||||
{{unit "cdmf.unit.device.listing"}}
|
{{#if deviceCount}}
|
||||||
|
<span id="permission" data-permission="{{{permissions}}}"></span>
|
||||||
|
<div id="loading-content" class="col-centered">
|
||||||
|
<i class="fw fw-settings fw-spin fw-2x"></i>
|
||||||
|
|
||||||
|
Loading devices . . .
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
<div id="device-listing-status" class="raw hidden">
|
||||||
|
<ul style="list-style-type: none;">
|
||||||
|
<li class="message message-info">
|
||||||
|
<h4>
|
||||||
|
<i class="icon fw fw-info"></i>
|
||||||
|
<a id="device-listing-status-msg"></a>
|
||||||
|
</h4>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div id="device-table">
|
||||||
|
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
|
||||||
|
id="device-grid">
|
||||||
|
<thead>
|
||||||
|
<tr class="sort-row">
|
||||||
|
<th class="no-sort"></th>
|
||||||
|
<th>By Device Name</th>
|
||||||
|
<th>By Owner</th>
|
||||||
|
<th>By Status</th>
|
||||||
|
<th>By Platform</th>
|
||||||
|
<th>By Ownership</th>
|
||||||
|
<th class="no-sort"></th>
|
||||||
|
</tr>
|
||||||
|
<tr class="filter-row filter-box">
|
||||||
|
<th class="no-sort"></th>
|
||||||
|
<th data-for="By Device name" class="text-filter"></th>
|
||||||
|
<th data-for="By Owner" class="text-filter"></th>
|
||||||
|
<th data-for="By Status" class="select-filter"></th>
|
||||||
|
<th data-for="By Platform" class="select-filter data-platform"></th>
|
||||||
|
<th data-for="By Ownership" class="select-filter"></th>
|
||||||
|
<th class="no-sort"></th>
|
||||||
|
</tr>
|
||||||
|
<tr class="bulk-action-row">
|
||||||
|
<th colspan="7">
|
||||||
|
<div id="operation-bar" class="hidden">
|
||||||
|
{{unit "mdm.unit.device.operation-bar"}}
|
||||||
|
</div>
|
||||||
|
<div id="operation-guide" class="bs-callout bs-callout-info">
|
||||||
|
<h4>Enabling Device Operations</h4>
|
||||||
|
<p>To enable device operations, select the desired platform from above
|
||||||
|
filter.</p>
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="ast-container">
|
||||||
|
|
||||||
|
<br class="c-both"/>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<br class="c-both"/>
|
||||||
|
<div id="content-filter-types" style="display: none">
|
||||||
|
<div class="sort-title">Sort By</div>
|
||||||
|
<div class="sort-options">
|
||||||
|
<a href="#">By Device Name<span class="ico-sort-asc"></span></a>
|
||||||
|
<a href="#">By Owner</a>
|
||||||
|
<a href="#">By Status</a>
|
||||||
|
<a href="#">By Platform</a>
|
||||||
|
<a href="#">By Ownership</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div id="ast-container" class="ast-container list-view">
|
||||||
|
<div class="ctrl-info-panel col-centered text-center wr-login">
|
||||||
|
<h2>You don't have any device
|
||||||
|
{{#if groupName}}
|
||||||
|
assigned to this group
|
||||||
|
{{else}}
|
||||||
|
registered
|
||||||
|
{{/if}}
|
||||||
|
at the moment.</h2>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<p class="text-center">
|
||||||
|
{{#if groupName}}
|
||||||
|
<a href="{{@app.context}}/devices" class="wr-btn">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
Assign from My Devices
|
||||||
|
</a>
|
||||||
|
{{else}}
|
||||||
|
<a href="{{@app.context}}/device/enroll" class="wr-btn">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
Enroll New Device
|
||||||
|
</a>
|
||||||
|
{{/if}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<div id="group-device-modal-content" class="hide">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3 col-centered">
|
||||||
|
<h3>Please select group</h3>
|
||||||
|
<div id="user-groups">Loading...</div>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="group-device-yes-link" class="btn-operations">
|
||||||
|
Assign
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="#" id="group-device-cancel-link" class="btn-operations">
|
||||||
|
Cancel
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="group-associate-device-200-content" class="hide">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3 col-centered">
|
||||||
|
<h3>Device was successfully associated with group.</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="group-deassociate-device-200-content" class="hide">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3 col-centered">
|
||||||
|
<h3>Device was successfully removed from group.</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="remove-device-modal-content" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>Do you really want to remove this device from your Devices List?</h3>
|
||||||
|
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="remove-device-yes-link" class="btn-operations">
|
||||||
|
Yes
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="#" id="remove-device-cancel-link" class="btn-operations">
|
||||||
|
Cancel
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="remove-device-200-content" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>Device was successfully removed.</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="edit-device-modal-content" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>Please enter new name for the device?</h3>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input id="edit-device-name" style="color:#3f3f3f;padding:5px" type="text"
|
||||||
|
value=""
|
||||||
|
placeholder="Type here" size="60">
|
||||||
|
</div>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="edit-device-yes-link" class="btn-operations">
|
||||||
|
Rename
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="#" id="edit-device-cancel-link" class="btn-operations">
|
||||||
|
Cancel
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="edit-device-200-content" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>Device was successfully updated.</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="device-400-content" class="hide">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-7 col-centered center-container">
|
||||||
|
<h3>Exception at backend. Try Later.</h3>
|
||||||
|
<br/>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="device-400-link" class="btn-operations">
|
||||||
|
Ok
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="device-403-content" class="hide">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-7 col-centered center-container">
|
||||||
|
<h3>Operation not permitted.</h3>
|
||||||
|
<br/>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="device-403-link" class="btn-operations">
|
||||||
|
Ok
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="device-409-content" class="hide">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-7 col-centered center-container">
|
||||||
|
<h3>Device does not exist.</h3>
|
||||||
|
<br/>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="remove-device-409-link" class="btn-operations">
|
||||||
|
Ok
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
<script id="device-listing" data-current-user="{{currentUser.username}}"
|
||||||
|
data-image-resource="{{@app.context}}/public/cdmf.unit.device.type."
|
||||||
|
src="{{@page.publicUri}}/templates/listing.hbs"
|
||||||
|
type="text/x-handlebars-template"></script>
|
||||||
|
{{js "js/listing.js"}}
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
@ -18,19 +18,61 @@
|
|||||||
|
|
||||||
function onRequest(context) {
|
function onRequest(context) {
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var page = {};
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
|
|
||||||
var groupName = request.getParameter("groupName");
|
var groupName = request.getParameter("groupName");
|
||||||
|
var groupOwner = request.getParameter("groupOwner");
|
||||||
|
|
||||||
|
var page = {};
|
||||||
var title = "Devices";
|
var title = "Devices";
|
||||||
if (groupName) {
|
if (groupName) {
|
||||||
title = groupName + " " + title;
|
title = groupName + " " + title;
|
||||||
page.groupName = groupName;
|
page.groupName = groupName;
|
||||||
}
|
}
|
||||||
page.title =title;
|
page.title = title;
|
||||||
page.permissions = {};
|
page.permissions = {};
|
||||||
var currentUser = session.get(constants.USER_SESSION_KEY);
|
var currentUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var permissions = [];
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) {
|
||||||
|
permissions.push("LIST_DEVICES");
|
||||||
|
} else if (userModule.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
||||||
|
permissions.push("LIST_OWN_DEVICES");
|
||||||
|
} else if (userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/list")) {
|
||||||
|
permissions.push("LIST_POLICIES");
|
||||||
|
}
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/add")) {
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/add")) {
|
||||||
page.permissions.enroll = true;
|
permissions.enroll = true;
|
||||||
|
}
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/remove")) {
|
||||||
|
permissions.push("REMOVE_DEVICE");
|
||||||
|
}
|
||||||
|
|
||||||
|
page.permissions.list = permissions;
|
||||||
|
page.currentUser = currentUser;
|
||||||
|
var deviceCount = 0;
|
||||||
|
if (groupName && groupOwner) {
|
||||||
|
var groupModule = require("/app/modules/group.js").groupModule;
|
||||||
|
deviceCount = groupModule.getGroupDeviceCount(groupName, groupOwner);
|
||||||
|
page.groupOwner = groupOwner;
|
||||||
|
} else {
|
||||||
|
deviceCount = deviceModule.getOwnDevicesCount();
|
||||||
|
}
|
||||||
|
if (deviceCount > 0) {
|
||||||
|
page.deviceCount = deviceCount;
|
||||||
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
|
var data = deviceModule.getDeviceTypes();
|
||||||
|
var deviceTypes = [];
|
||||||
|
if (data.data) {
|
||||||
|
for (var i = 0; i < data.data.length; i++) {
|
||||||
|
deviceTypes.push({
|
||||||
|
"type": data.data[i].name,
|
||||||
|
"category": utility.getDeviceTypeConfig(data.data[i].name).deviceType.category
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
page.deviceTypes = deviceTypes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return page;
|
return page;
|
||||||
|
|||||||
@ -16,6 +16,17 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Following function would execute
|
||||||
|
* when a user clicks on the list item
|
||||||
|
* initial mode and with out select mode.
|
||||||
|
*/
|
||||||
|
function InitiateViewOption(url) {
|
||||||
|
if ($(".select-enable-btn").text() == "Select") {
|
||||||
|
$(location).attr('href', url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
var cache = {};
|
var cache = {};
|
||||||
var permissionSet = {};
|
var permissionSet = {};
|
||||||
@ -50,6 +61,44 @@
|
|||||||
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
|
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
|
||||||
var assetContainer = "#ast-container";
|
var assetContainer = "#ast-container";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DOM ready functions.
|
||||||
|
*/
|
||||||
|
$(document).ready(function () {
|
||||||
|
/* Adding selected class for selected devices */
|
||||||
|
$(deviceCheckbox).each(function () {
|
||||||
|
addDeviceSelectedClass(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
var i;
|
||||||
|
var permissionList = $("#permission").data("permission");
|
||||||
|
for (i = 0; i < permissionList.length; i++) {
|
||||||
|
$.setPermission(permissionList[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for device list sorting drop down */
|
||||||
|
$(".ctrl-filter-type-switcher").popover({
|
||||||
|
html : true,
|
||||||
|
content : function () {
|
||||||
|
return $("#content-filter-types").html();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".ast-container").on("click", ".claim-btn", function(e){
|
||||||
|
e.stopPropagation();
|
||||||
|
var deviceId = $(this).data("deviceid");
|
||||||
|
var deviceListing = $("#device-listing");
|
||||||
|
var currentUser = deviceListing.data("current-user");
|
||||||
|
var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser;
|
||||||
|
var deviceIdentifier = {id: deviceId, type: "TemperatureController"};
|
||||||
|
invokerUtil.put(serviceURL, deviceIdentifier, function(message){
|
||||||
|
console.log(message);
|
||||||
|
}, function(message){
|
||||||
|
console.log(message.content);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* On Select All Device button click function.
|
* On Select All Device button click function.
|
||||||
*
|
*
|
||||||
@ -110,52 +159,149 @@ function toTitleCase(str) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadDevices() {
|
function loadDevices(searchType, searchParam){
|
||||||
var deviceListing = $("#device-listing");
|
var deviceListing = $("#device-listing");
|
||||||
var deviceListingSrc = deviceListing.attr("src");
|
var deviceListingSrc = deviceListing.attr("src");
|
||||||
var imageResource = deviceListing.data("image-resource");
|
var imageResource = deviceListing.data("image-resource");
|
||||||
var currentUser = deviceListing.data("currentUser");
|
var currentUser = deviceListing.data("currentUser");
|
||||||
$.template("device-listing", deviceListingSrc, function (template) {
|
var frontEndPagination = false;
|
||||||
var serviceURL;
|
|
||||||
if ($.hasPermission("LIST_OWN_DEVICES") || $.hasPermission("LIST_DEVICES")) {
|
|
||||||
//Get authenticated users devices
|
|
||||||
serviceURL = "/devicemgt_admin/users/devices?username=" + currentUser;
|
|
||||||
} else {
|
|
||||||
$("#loading-content").remove();
|
|
||||||
$('#device-table').addClass('hidden');
|
|
||||||
$('#device-listing-status-msg').text('Permission denied.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var successCallback = function (data) {
|
var serviceURL;
|
||||||
data = JSON.parse(data);
|
if ($.hasPermission("LIST_DEVICES")) {
|
||||||
var viewModel = {};
|
serviceURL = "/devicemgt_admin/devices";
|
||||||
viewModel.devices = data;
|
} else if ($.hasPermission("LIST_OWN_DEVICES")) {
|
||||||
viewModel.imageLocation = imageResource;
|
//Get authenticated users devices
|
||||||
if (data.length > 0) {
|
serviceURL = "/devicemgt_admin/users/devices?username="+currentUser;
|
||||||
$('#device-listing-container').removeClass('hidden');
|
} else {
|
||||||
$('#empty-device-listing-container').addClass('hidden');
|
$("#loading-content").remove();
|
||||||
var content = template(viewModel);
|
$('#device-table').addClass('hidden');
|
||||||
$("#ast-container").html(content);
|
$('#device-listing-status-msg').text('Permission denied.');
|
||||||
/*
|
$("#device-listing-status").removeClass(' hidden');
|
||||||
* On device checkbox select add parent selected style class
|
return;
|
||||||
*/
|
}
|
||||||
$(deviceCheckbox).click(function () {
|
|
||||||
addDeviceSelectedClass(this);
|
function getPropertyValue(deviceProperties, propertyName) {
|
||||||
});
|
var property;
|
||||||
attachDeviceEvents();
|
for (var i =0; i < deviceProperties.length; i++) {
|
||||||
} else {
|
property = deviceProperties[i];
|
||||||
$('#device-listing-container').addClass('hidden');
|
if (property.name == propertyName) {
|
||||||
$('#empty-device-listing-container').removeClass('hidden');
|
return property.value;
|
||||||
}
|
}
|
||||||
$("#loading-content").remove();
|
}
|
||||||
$('#device-grid').datatables_extended();
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#device-grid').datatables_extended ({
|
||||||
|
serverSide: true,
|
||||||
|
processing: false,
|
||||||
|
searching: true,
|
||||||
|
ordering: false,
|
||||||
|
filter: false,
|
||||||
|
pageLength : 16,
|
||||||
|
ajax: { url : '/devicemgt/api/devices', data : {url : serviceURL},
|
||||||
|
dataSrc: function ( json ) {
|
||||||
|
$('#device-grid').removeClass('hidden');
|
||||||
|
$("#loading-content").remove();
|
||||||
|
var $list = $("#device-table :input[type='search']");
|
||||||
|
$list.each(function(){
|
||||||
|
$(this).addClass("hidden");
|
||||||
|
});
|
||||||
|
return json.data;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
columnDefs: [
|
||||||
|
{ targets: 0, data: 'name', className: 'remove-padding icon-only content-fill' , render: function ( data, type, row, meta ) {
|
||||||
|
return '<div class="thumbnail icon"><img class="square-element text fw " src="' + imageResource + row.type + '.type-view/images/thumb.png"/></div>';
|
||||||
|
}},
|
||||||
|
{ targets: 1, data: 'name', className: 'fade-edge' , render: function ( name, type, row, meta ) {
|
||||||
|
var model = getPropertyValue(row.properties, 'DEVICE_MODEL');
|
||||||
|
var vendor = getPropertyValue(row.properties, 'VENDOR');
|
||||||
|
var html = '<h4>Device ' + name + '</h4>';
|
||||||
|
if (model) {
|
||||||
|
html += '<div>(' + vendor + '-' + model + ')</div>';
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
}},
|
||||||
|
{ targets: 2, data: 'enrolmentInfo.owner', className: 'fade-edge remove-padding-top'},
|
||||||
|
{ targets: 3, data: 'enrolmentInfo.status', className: 'fade-edge remove-padding-top' ,
|
||||||
|
render: function ( status, type, row, meta ) {
|
||||||
|
var html;
|
||||||
|
switch (status) {
|
||||||
|
case 'ACTIVE' :
|
||||||
|
html = '<span><i class="fw fw-ok icon-success"></i> Active</span>';
|
||||||
|
break;
|
||||||
|
case 'INACTIVE' :
|
||||||
|
html = '<span><i class="fw fw-warning icon-warning"></i> Inactive</span>';
|
||||||
|
break;
|
||||||
|
case 'BLOCKED' :
|
||||||
|
html = '<span><i class="fw fw-remove icon-danger"></i> Blocked</span>';
|
||||||
|
break;
|
||||||
|
case 'REMOVED' :
|
||||||
|
html = '<span><i class="fw fw-delete icon-danger"></i> Removed</span>';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
}},
|
||||||
|
{ targets: 4, data: 'type' , className: 'fade-edge remove-padding-top' },
|
||||||
|
{ targets: 5, data: 'enrolmentInfo.ownership' , className: 'fade-edge remove-padding-top' },
|
||||||
|
{ targets: 6, data: 'enrolmentInfo.status' , className: 'text-right content-fill text-left-on-grid-view no-wrap' ,
|
||||||
|
render: function ( status, type, row, meta ) {
|
||||||
|
var deviceType = row.type;
|
||||||
|
var deviceIdentifier = row.deviceIdentifier;
|
||||||
|
var html = '<span></span>';
|
||||||
|
if (status != 'REMOVED') {
|
||||||
|
html = '<a href="device/' + deviceType + '?id=' + deviceIdentifier + '" data-click-event="remove-form"' +
|
||||||
|
' class="btn padding-reduce-on-grid-view"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
||||||
|
'<i class="fw fw-view fw-stack-1x"></i></span><span class="hidden-xs hidden-on-grid-view">View</span></a>';
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
}}
|
||||||
|
],
|
||||||
|
"createdRow": function( row, data, dataIndex ) {
|
||||||
|
$(row).attr('data-type', 'selectable');
|
||||||
|
$(row).attr('data-deviceid', data.deviceIdentifier);
|
||||||
|
$(row).attr('data-devicetype', data.type);
|
||||||
|
var model = getPropertyValue(data.properties, 'DEVICE_MODEL');
|
||||||
|
var vendor = getPropertyValue(data.properties, 'VENDOR');
|
||||||
|
var owner = data.enrolmentInfo.owner;
|
||||||
|
var status = data.enrolmentInfo.status;
|
||||||
|
var ownership = data.enrolmentInfo.ownership;
|
||||||
|
var deviceType = data.type;
|
||||||
|
$.each($('td', row), function (colIndex) {
|
||||||
|
switch(colIndex) {
|
||||||
|
case 1:
|
||||||
|
$(this).attr('data-search', model + ',' + vendor);
|
||||||
|
$(this).attr('data-display', model);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$(this).attr('data-grid-label', "Owner");
|
||||||
|
$(this).attr('data-search', owner);
|
||||||
|
$(this).attr('data-display', owner);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$(this).attr('data-grid-label', "Status");
|
||||||
|
$(this).attr('data-search', status);
|
||||||
|
$(this).attr('data-display', status);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$(this).attr('data-grid-label', "Type");
|
||||||
|
$(this).attr('data-search', deviceType);
|
||||||
|
$(this).attr('data-display', deviceType);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
$(this).attr('data-grid-label', "Ownership");
|
||||||
|
$(this).attr('data-search', ownership);
|
||||||
|
$(this).attr('data-display', ownership);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
"fnDrawCallback": function( oSettings ) {
|
||||||
$(".icon .text").res_text(0.2);
|
$(".icon .text").res_text(0.2);
|
||||||
};
|
}
|
||||||
invokerUtil.get(serviceURL,
|
});
|
||||||
successCallback, function (message) {
|
$(deviceCheckbox).click(function () {
|
||||||
console.log(message.content);
|
addDeviceSelectedClass(this);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,20 +364,37 @@ function loadGroupedDevices(groupId) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initPage() {
|
||||||
|
var groupId = getParameterByName('groupId');
|
||||||
|
invokerUtil.get(
|
||||||
|
"/devicemgt_admin/devices/count",
|
||||||
|
function (data) {
|
||||||
|
if (data) {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
if (Number(data) > 0) {
|
||||||
|
if (groupId) {
|
||||||
|
loadGroupedDevices(groupId);
|
||||||
|
} else {
|
||||||
|
loadDevices();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$("#loading-content").remove();
|
||||||
|
$("#device-listing-status-msg").text("No enrolled devices found.");
|
||||||
|
$("#device-listing-status").removeClass(' hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, function (message) {
|
||||||
|
initPage();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DOM ready functions.
|
* DOM ready functions.
|
||||||
*/
|
*/
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
var groupId = getParameterByName('groupId');
|
initPage();
|
||||||
|
|
||||||
if (groupId) {
|
|
||||||
loadGroupedDevices(groupId);
|
|
||||||
} else {
|
|
||||||
loadDevices();
|
|
||||||
}
|
|
||||||
|
|
||||||
//$('#device-grid').datatables_extended();
|
|
||||||
|
|
||||||
/* Adding selected class for selected devices */
|
/* Adding selected class for selected devices */
|
||||||
$(deviceCheckbox).each(function () {
|
$(deviceCheckbox).each(function () {
|
||||||
@ -246,29 +409,43 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
/* for device list sorting drop down */
|
/* for device list sorting drop down */
|
||||||
$(".ctrl-filter-type-switcher").popover({
|
$(".ctrl-filter-type-switcher").popover({
|
||||||
html: true,
|
html : true,
|
||||||
content: function () {
|
content : function () {
|
||||||
return $("#content-filter-types").html();
|
return $("#content-filter-types").html();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".ast-container").on("click", ".claim-btn", function(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
var deviceId = $(this).data("deviceid");
|
||||||
|
var deviceListing = $("#device-listing");
|
||||||
|
var currentUser = deviceListing.data("current-user");
|
||||||
|
var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser;
|
||||||
|
var deviceIdentifier = {id: deviceId, type: "TemperatureController"};
|
||||||
|
invokerUtil.put(serviceURL, deviceIdentifier, function(message) {
|
||||||
|
console.log(message);
|
||||||
|
}, function(message){
|
||||||
|
console.log(message.content);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/* for data tables*/
|
/* for data tables*/
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
|
|
||||||
$("[data-toggle=popover]").popover();
|
$("[data-toggle=popover]").popover();
|
||||||
|
|
||||||
$(".ctrl-filter-type-switcher").popover({
|
$(".ctrl-filter-type-switcher").popover ({
|
||||||
html: true,
|
html : true,
|
||||||
content: function () {
|
content: function() {
|
||||||
return $('#content-filter-types').html();
|
return $('#content-filter-types').html();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#nav').affix({
|
$('#nav').affix ({
|
||||||
offset: {
|
offset: {
|
||||||
top: $('header').height()
|
top: $('header').height()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -28,17 +28,9 @@
|
|||||||
<td class="fade-edge remove-padding-top" data-search="{{type}}" data-display="{{type}}"
|
<td class="fade-edge remove-padding-top" data-search="{{type}}" data-display="{{type}}"
|
||||||
data-grid-label="Type">{{type}}</td>
|
data-grid-label="Type">{{type}}</td>
|
||||||
|
|
||||||
{{#if enrolmentInfo.ownership}}
|
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.ownership}}"
|
||||||
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.ownership}}"
|
data-display="{{enrolmentInfo.ownership}}"
|
||||||
data-display="{{enrolmentInfo.ownership}}"
|
data-grid-label="Ownership">{{enrolmentInfo.ownership}}</td>
|
||||||
data-grid-label="Ownership">
|
|
||||||
{{enrolmentInfo.ownership}}
|
|
||||||
</td>
|
|
||||||
{{else}}
|
|
||||||
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.ownership}}"
|
|
||||||
data-display="{{enrolmentInfo.ownership}}">
|
|
||||||
</td>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
<td class="text-right content-fill text-left-on-grid-view no-wrap">
|
<td class="text-right content-fill text-left-on-grid-view no-wrap">
|
||||||
{{#unequal enrolmentInfo.status "REMOVED"}}
|
{{#unequal enrolmentInfo.status "REMOVED"}}
|
||||||
@ -54,59 +54,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="group-400-content" class="hide">
|
<div id="group-error-content" class="hide">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-7 col-centered center-container">
|
<div class="col-md-7 col-centered center-container">
|
||||||
<h4>Exception at backend. Try Later.</h4>
|
<h4 id="error-msg">Unexpected error occurred!</h4>
|
||||||
<br/>
|
|
||||||
<div class="buttons">
|
|
||||||
<a href="#" id="group-400-link" class="btn-operations">
|
|
||||||
Ok
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="group-403-content" class="hide">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-7 col-centered center-container">
|
|
||||||
<h4>Operation not permitted.</h4>
|
|
||||||
<br/>
|
|
||||||
<div class="buttons">
|
|
||||||
<a href="#" id="group-403-link" class="btn-operations">
|
|
||||||
Ok
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="group-409-content" class="hide">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-7 col-centered center-container">
|
|
||||||
<h4>Group Name already exists.</h4>
|
|
||||||
<br/>
|
|
||||||
<div class="buttons">
|
|
||||||
<a href="#" id="group-409-link" class="btn-operations">
|
|
||||||
Ok
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="group-unexpected-error-content" class="hide">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-7 col-centered center-container">
|
|
||||||
<h4>Unexpected error occurred!</h4>
|
|
||||||
<br/>
|
<br/>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a href="#" id="group-unexpected-error-link" class="btn-operations">
|
<a href="#" id="group-unexpected-error-link" class="btn-operations">
|
||||||
|
|||||||
@ -29,7 +29,8 @@ $(function () {
|
|||||||
} else {
|
} else {
|
||||||
var group = {"name": name, "description": description};
|
var group = {"name": name, "description": description};
|
||||||
|
|
||||||
var successCallback = function (data) {
|
var successCallback = function (jqXHR) {
|
||||||
|
var data = JSON.parse(jqXHR);
|
||||||
if (data.status == 201) {
|
if (data.status == 201) {
|
||||||
$('.wr-validation-summary strong').text("Group created. You will be redirected to groups");
|
$('.wr-validation-summary strong').text("Group created. You will be redirected to groups");
|
||||||
$('.wr-validation-summary').removeClass("hidden");
|
$('.wr-validation-summary').removeClass("hidden");
|
||||||
@ -39,13 +40,13 @@ $(function () {
|
|||||||
window.location = "../groups";
|
window.location = "../groups";
|
||||||
}, 1500);
|
}, 1500);
|
||||||
} else {
|
} else {
|
||||||
displayErrors(status);
|
displayErrors(data.status);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
invokerUtil.post("/common/group_manager/groups", group,
|
invokerUtil.post("/devicemgt_admin/groups", group,
|
||||||
successCallback, function (message) {
|
successCallback, function (message) {
|
||||||
displayErrors(message.content);
|
displayErrors(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -53,28 +54,11 @@ $(function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function displayErrors(status) {
|
function displayErrors(message) {
|
||||||
showPopup();
|
showPopup();
|
||||||
if (status == 400) {
|
$('#error-msg').html(message.responseText);
|
||||||
$(modalPopupContent).html($('#group-400-content').html());
|
$(modalPopupContent).html($('#group-error-content').html());
|
||||||
$("a#group-400-link").click(function () {
|
$("a#group-unexpected-error-link").click(function () {
|
||||||
hidePopup();
|
hidePopup();
|
||||||
});
|
});
|
||||||
} else if (status == 403) {
|
|
||||||
$(modalPopupContent).html($('#group-403-content').html());
|
|
||||||
$("a#group-403-link").click(function () {
|
|
||||||
hidePopup();
|
|
||||||
});
|
|
||||||
} else if (status == 409) {
|
|
||||||
$(modalPopupContent).html($('#group-409-content').html());
|
|
||||||
$("a#group-409-link").click(function () {
|
|
||||||
hidePopup();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$(modalPopupContent).html($('#group-unexpected-error-content').html());
|
|
||||||
$("a#group-unexpected-error-link").click(function () {
|
|
||||||
hidePopup();
|
|
||||||
});
|
|
||||||
console.log("Error code: " + status);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -268,7 +268,7 @@
|
|||||||
|
|
||||||
{{#zone "bottomJs"}}
|
{{#zone "bottomJs"}}
|
||||||
<script id="group-listing" data-current-user="{{currentUser.username}}"
|
<script id="group-listing" data-current-user="{{currentUser.username}}"
|
||||||
src="{{@unit.publicUri}}/templates/listing.hbs"
|
src="{{@page.publicUri}}/templates/listing.hbs"
|
||||||
type="text/x-handlebars-template"></script>
|
type="text/x-handlebars-template"></script>
|
||||||
{{#if groupCount}}
|
{{#if groupCount}}
|
||||||
{{js "js/listing.js"}}
|
{{js "js/listing.js"}}
|
||||||
|
|||||||
@ -108,7 +108,7 @@ function loadGroups() {
|
|||||||
$(".icon .text").res_text(0.2);
|
$(".icon .text").res_text(0.2);
|
||||||
};
|
};
|
||||||
|
|
||||||
invokerUtil.get("/common/group_manager/groups?start=0&rowCount=1000",
|
invokerUtil.get("/devicemgt_admin/groups/user/" + currentUser + "?start=0&rowCount=1000",
|
||||||
successCallback, function (message) {
|
successCallback, function (message) {
|
||||||
displayErrors(message.content);
|
displayErrors(message.content);
|
||||||
});
|
});
|
||||||
@ -282,7 +282,7 @@ function attachEvents() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
invokerUtil.delete("/common/group_manager/groups/" + groupOwner + "/" + groupName,
|
invokerUtil.delete("/devicemgt_admin/groups/" + groupOwner + "/" + groupName,
|
||||||
successCallback, function (message) {
|
successCallback, function (message) {
|
||||||
displayErrors(message.content);
|
displayErrors(message.content);
|
||||||
});
|
});
|
||||||
@ -326,7 +326,7 @@ function attachEvents() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
invokerUtil.put("/common/group_manager/groups/" + groupOwner + "/" + groupName,
|
invokerUtil.put("/devicemgt_admin/groups/" + groupOwner + "/" + groupName,
|
||||||
successCallback, function (message) {
|
successCallback, function (message) {
|
||||||
displayErrors(message.content);
|
displayErrors(message.content);
|
||||||
});
|
});
|
||||||
@ -354,7 +354,7 @@ function getAllRoles(groupName, groupOwner, selectedUser) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
invokerUtil.get("/common/group_manager/groups/" + groupOwner + "/" + groupName + "/share/roles",
|
invokerUtil.get("/devicemgt_admin/groups/" + groupOwner + "/" + groupName + "/share/roles",
|
||||||
successCallback, function (message) {
|
successCallback, function (message) {
|
||||||
displayErrors(message.content);
|
displayErrors(message.content);
|
||||||
});
|
});
|
||||||
@ -407,7 +407,7 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
invokerUtil.get("/common/group_manager/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser,
|
invokerUtil.get("/devicemgt_admin/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser,
|
||||||
successCallback, function (message) {
|
successCallback, function (message) {
|
||||||
displayErrors(message.content);
|
displayErrors(message.content);
|
||||||
});
|
});
|
||||||
@ -431,7 +431,7 @@ function updateGroupShare(groupName, groupOwner, selectedUser, role) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
invokerUtil.put("/common/group_manager/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser,
|
invokerUtil.put("/devicemgt_admin/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser,
|
||||||
role, successCallback, function (message) {
|
role, successCallback, function (message) {
|
||||||
displayErrors(message.content);
|
displayErrors(message.content);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -164,7 +164,6 @@ function getDateTime(from, to) {
|
|||||||
startDate = new Date(from);
|
startDate = new Date(from);
|
||||||
endDate = new Date(to);
|
endDate = new Date(to);
|
||||||
DateRange = convertDate(startDate) + " " + configObject.separator + " " + convertDate(endDate);
|
DateRange = convertDate(startDate) + " " + configObject.separator + " " + convertDate(endDate);
|
||||||
console.log(DateRange);
|
|
||||||
$('#date-range').html(DateRange);
|
$('#date-range').html(DateRange);
|
||||||
getStats(from / 1000, to / 1000);
|
getStats(from / 1000, to / 1000);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,173 +0,0 @@
|
|||||||
<div class="wr-content">
|
|
||||||
{{#if permissions.VIEW_DASHBOARD}}
|
|
||||||
<div class="row wr-stats-board">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="wr-stats-board-tile">
|
|
||||||
<div class="tile-name">Devices</div>
|
|
||||||
<div>
|
|
||||||
<div class="tile-icon"><i class="fw fw-mobile"></i></div>
|
|
||||||
<div class="tile-stats">
|
|
||||||
<span id="device-count">{{device_count}}</span>
|
|
||||||
<span class="tile-stats-free">
|
|
||||||
<a href="{{@app.context}}/devices">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-view fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
View
|
|
||||||
</a>
|
|
||||||
<a href="{{@app.context}}/device/enroll">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-add fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
Add
|
|
||||||
</a>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row wr-stats-board">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="wr-stats-board-tile">
|
|
||||||
<div class="tile-name">Groups</div>
|
|
||||||
<div>
|
|
||||||
<div class="tile-icon"><i class="fw fw-grouping"></i></div>
|
|
||||||
<div class="tile-stats">
|
|
||||||
<span id="group-count">{{group_count}}</span>
|
|
||||||
<span class="tile-stats-free">
|
|
||||||
<a href="{{@app.context}}/groups">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-view fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
View
|
|
||||||
</a>
|
|
||||||
<a href="{{@app.context}}/group/add">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-add fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
Add
|
|
||||||
</a>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row wr-stats-board">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="wr-stats-board-tile">
|
|
||||||
<div class="tile-name">Users</div>
|
|
||||||
<div>
|
|
||||||
<div class="tile-icon"><i class="fw fw-user"></i></div>
|
|
||||||
<div class="tile-stats">
|
|
||||||
<span id="user-count">{{user_count}}</span>
|
|
||||||
<span class="tile-stats-free">
|
|
||||||
<a href="{{@app.context}}/users">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-view fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
View
|
|
||||||
</a>
|
|
||||||
<a href="{{@app.context}}/user/add">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-add fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
Add
|
|
||||||
</a>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row wr-stats-board">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="wr-stats-board-tile">
|
|
||||||
<div class="tile-name">Policies</div>
|
|
||||||
<div>
|
|
||||||
<div class="tile-icon"><i class="fw fw-policy"></i></div>
|
|
||||||
<div class="tile-stats">
|
|
||||||
<span id="policy-count">{{policy_count}}</span>
|
|
||||||
<span class="tile-stats-free">
|
|
||||||
<a href="{{@app.context}}/policies">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-view fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
View
|
|
||||||
</a>
|
|
||||||
<a href="{{@app.context}}/policy/add">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-add fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
Add
|
|
||||||
</a>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row wr-stats-board">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="wr-stats-board-tile">
|
|
||||||
<div class="tile-name">Roles</div>
|
|
||||||
<div>
|
|
||||||
<div class="tile-icon"><i class="fw fw-bookmark"></i></div>
|
|
||||||
<div class="tile-stats">
|
|
||||||
<span id="role-count">{{role_count}}</span>
|
|
||||||
<span class="tile-stats-free">
|
|
||||||
<a id="device-count-view-btn" href="{{@app.context}}/roles">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-view fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
View
|
|
||||||
</a>
|
|
||||||
<a href="{{@app.context}}/roles/add-role">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-add fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
Add
|
|
||||||
</a>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{else}}
|
|
||||||
Permission denied
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div id="qr-code-modal" data-enrollment-url="{{enrollmentURL}}" class="hidden">
|
|
||||||
|
|
||||||
<div class="content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-5 col-md-6 col-centered">
|
|
||||||
<h3>
|
|
||||||
Scan QR code to start enrollment
|
|
||||||
</h3>
|
|
||||||
<h4>
|
|
||||||
Please scan the QR code using your mobile device to retrieve enrollment URL.
|
|
||||||
</h4>
|
|
||||||
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-body col-centered ">
|
|
||||||
<div class="qr-code"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"version" : "1.0.0"
|
|
||||||
}
|
|
||||||
@ -141,7 +141,7 @@ $.fn.datatables_extended = function(settings){
|
|||||||
*/
|
*/
|
||||||
$('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html('' +
|
$('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html('' +
|
||||||
'<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
|
'<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
|
||||||
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary">Select</li>' +
|
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
|
||||||
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
|
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
|
||||||
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
|
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
|
||||||
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
|
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
|
||||||
|
|||||||
@ -1,236 +0,0 @@
|
|||||||
<div id="device-listing-container">
|
|
||||||
<span id="permission" data-permission="{{permissions}}"></span>
|
|
||||||
<div class="container-fluid">
|
|
||||||
<span id="device-listing-status-msg"></span>
|
|
||||||
<table class="table table-striped table-hover list-table display responsive nowrap data-table table-selectable grid-view"
|
|
||||||
id="device-grid">
|
|
||||||
<thead>
|
|
||||||
<tr class="sort-row">
|
|
||||||
<th class="no-sort"></th>
|
|
||||||
<th>By Device Model and Vendor</th>
|
|
||||||
<th>By Owner</th>
|
|
||||||
<th>By Status</th>
|
|
||||||
<th>By Platform</th>
|
|
||||||
<th>By Ownership</th>
|
|
||||||
<th class="no-sort"></th>
|
|
||||||
</tr>
|
|
||||||
<tr class="filter-row filter-box">
|
|
||||||
<th></th>
|
|
||||||
<th data-for="By Device Model and Vendor" class="text-filter"></th>
|
|
||||||
<th data-for="By Owner" class="text-filter"></th>
|
|
||||||
<th data-for="By Status" class="select-filter"></th>
|
|
||||||
<th data-for="By Platform" class="select-filter data-platform"></th>
|
|
||||||
<th data-for="By Ownership" class="select-filter"></th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
|
|
||||||
<tbody id="ast-container"></tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div id="content-filter-types" style="display: none">
|
|
||||||
<div class="sort-title">Sort By</div>
|
|
||||||
<div class="sort-options">
|
|
||||||
<a href="#">By Device Model and Vendor<span class="ico-sort-asc"></span></a>
|
|
||||||
<a href="#">By Owner</a>
|
|
||||||
<a href="#">By Status</a>
|
|
||||||
<a href="#">By Platform</a>
|
|
||||||
<a href="#">By Ownership</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="empty-device-listing-container" class="ast-container list-view hidden">
|
|
||||||
<div class="ctrl-info-panel col-centered text-center wr-login">
|
|
||||||
<h2>You don't have any device
|
|
||||||
{{#if groupId}}
|
|
||||||
assigned to this group
|
|
||||||
{{else}}
|
|
||||||
registered
|
|
||||||
{{/if}}
|
|
||||||
at the moment.</h2>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<p class="text-center">
|
|
||||||
{{#if groupId}}
|
|
||||||
<a href="{{@app.context}}/devices" class="wr-btn">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-add fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
Assign from My Devices
|
|
||||||
</a>
|
|
||||||
{{else}}
|
|
||||||
<a href="{{@app.context}}/device/enroll" class="wr-btn">
|
|
||||||
<span class="fw-stack">
|
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
|
||||||
<i class="fw fw-add fw-stack-1x"></i>
|
|
||||||
</span>
|
|
||||||
Enroll New Device
|
|
||||||
</a>
|
|
||||||
{{/if}}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="group-device-modal-content" class="hide">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-3 col-centered">
|
|
||||||
<h3>Please select group</h3>
|
|
||||||
<div id="user-groups">Loading...</div>
|
|
||||||
<div class="buttons">
|
|
||||||
<a href="#" id="group-device-yes-link" class="btn-operations">
|
|
||||||
Assign
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="#" id="group-device-cancel-link" class="btn-operations">
|
|
||||||
Cancel
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="group-associate-device-200-content" class="hide">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-3 col-centered">
|
|
||||||
<h3>Device was successfully associated with group.</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="group-deassociate-device-200-content" class="hide">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-3 col-centered">
|
|
||||||
<h3>Device was successfully removed from group.</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="remove-device-modal-content" class="hide">
|
|
||||||
<div class="content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-5 col-md-6 col-centered">
|
|
||||||
<h3>Do you really want to remove this device from your Devices List?</h3>
|
|
||||||
|
|
||||||
<div class="buttons">
|
|
||||||
<a href="#" id="remove-device-yes-link" class="btn-operations">
|
|
||||||
Yes
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="#" id="remove-device-cancel-link" class="btn-operations">
|
|
||||||
Cancel
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="remove-device-200-content" class="hide">
|
|
||||||
<div class="content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-5 col-md-6 col-centered">
|
|
||||||
<h3>Device was successfully removed.</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="edit-device-modal-content" class="hide">
|
|
||||||
<div class="content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-5 col-md-6 col-centered">
|
|
||||||
<h3>Please enter new name for the device?</h3>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<input id="edit-device-name" style="color:#3f3f3f;padding:5px" type="text"
|
|
||||||
value=""
|
|
||||||
placeholder="Type here" size="60">
|
|
||||||
</div>
|
|
||||||
<div class="buttons">
|
|
||||||
<a href="#" id="edit-device-yes-link" class="btn-operations">
|
|
||||||
Rename
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="#" id="edit-device-cancel-link" class="btn-operations">
|
|
||||||
Cancel
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="edit-device-200-content" class="hide">
|
|
||||||
<div class="content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-5 col-md-6 col-centered">
|
|
||||||
<h3>Device was successfully updated.</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="device-400-content" class="hide">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-7 col-centered center-container">
|
|
||||||
<h3>Exception at backend. Try Later.</h3>
|
|
||||||
<br/>
|
|
||||||
<div class="buttons">
|
|
||||||
<a href="#" id="device-400-link" class="btn-operations">
|
|
||||||
Ok
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="device-403-content" class="hide">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-7 col-centered center-container">
|
|
||||||
<h3>Operation not permitted.</h3>
|
|
||||||
<br/>
|
|
||||||
<div class="buttons">
|
|
||||||
<a href="#" id="device-403-link" class="btn-operations">
|
|
||||||
Ok
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="device-409-content" class="hide">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-7 col-centered center-container">
|
|
||||||
<h3>Device does not exist.</h3>
|
|
||||||
<br/>
|
|
||||||
<div class="buttons">
|
|
||||||
<a href="#" id="remove-device-409-link" class="btn-operations">
|
|
||||||
Ok
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{#zone "bottomJs"}}
|
|
||||||
<script id="device-listing" data-current-user="{{currentUser.username}}"
|
|
||||||
data-image-resource="{{@app.context}}/public/cdmf.unit.device.type."
|
|
||||||
src="{{@unit.publicUri}}/templates/listing.hbs"
|
|
||||||
type="text/x-handlebars-template"></script>
|
|
||||||
{{js "js/listing.js"}}
|
|
||||||
{{/zone}}
|
|
||||||
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function onRequest(context) {
|
|
||||||
var page = {};
|
|
||||||
var groupId = request.getParameter("groupId");
|
|
||||||
var userModule = require("/app/modules/user.js").userModule;
|
|
||||||
var constants = require("/app/modules/constants.js");
|
|
||||||
var permissions = [];
|
|
||||||
var currentUser = session.get(constants.USER_SESSION_KEY);
|
|
||||||
if (currentUser) {
|
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) {
|
|
||||||
permissions.push("LIST_DEVICES");
|
|
||||||
} else if (userModule.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
|
||||||
permissions.push("LIST_OWN_DEVICES");
|
|
||||||
}
|
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/add")) {
|
|
||||||
permissions.push("ADD_DEVICE");
|
|
||||||
}
|
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/edit")) {
|
|
||||||
permissions.push("EDIT_DEVICE");
|
|
||||||
}
|
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/remove")) {
|
|
||||||
permissions.push("REMOVE_DEVICE");
|
|
||||||
}
|
|
||||||
page.permissions = stringify(permissions);
|
|
||||||
page.currentUser = currentUser;
|
|
||||||
}
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.0",
|
|
||||||
"index": 30
|
|
||||||
}
|
|
||||||
@ -63,6 +63,7 @@ var operationModule = function () {
|
|||||||
"AIRPLAY_OPERATION_CODE": "AIR_PLAY",
|
"AIRPLAY_OPERATION_CODE": "AIR_PLAY",
|
||||||
"LDAP_OPERATION_CODE": "LDAP",
|
"LDAP_OPERATION_CODE": "LDAP",
|
||||||
"CALENDAR_OPERATION_CODE": "CALDAV",
|
"CALENDAR_OPERATION_CODE": "CALDAV",
|
||||||
|
"NOTIFICATION_OPERATION_CODE": "NOTIFICATION",
|
||||||
"CALENDAR_SUBSCRIPTION_OPERATION_CODE": "CALENDAR_SUBSCRIPTION",
|
"CALENDAR_SUBSCRIPTION_OPERATION_CODE": "CALENDAR_SUBSCRIPTION",
|
||||||
"APN_OPERATION_CODE": "APN",
|
"APN_OPERATION_CODE": "APN",
|
||||||
"CELLULAR_OPERATION_CODE": "CELLULAR"
|
"CELLULAR_OPERATION_CODE": "CELLULAR"
|
||||||
@ -71,8 +72,9 @@ var operationModule = function () {
|
|||||||
publicMethods.getIOSServiceEndpoint = function (operationCode) {
|
publicMethods.getIOSServiceEndpoint = function (operationCode) {
|
||||||
var featureMap = {
|
var featureMap = {
|
||||||
"DEVICE_LOCK": "lock",
|
"DEVICE_LOCK": "lock",
|
||||||
"ALARM": "alarm",
|
"RING": "ring",
|
||||||
"LOCATION": "location",
|
"LOCATION": "location",
|
||||||
|
"NOTIFICATION": "notification",
|
||||||
"AIR_PLAY": "airplay",
|
"AIR_PLAY": "airplay",
|
||||||
"RESTRICTION": "restriction",
|
"RESTRICTION": "restriction",
|
||||||
"CELLULAR": "cellular",
|
"CELLULAR": "cellular",
|
||||||
@ -538,6 +540,14 @@ var operationModule = function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
case iosOperationConstants["NOTIFICATION_OPERATION_CODE"]:
|
||||||
|
operationType = operationTypeConstants["PROFILE"];
|
||||||
|
payload = {
|
||||||
|
"operation": {
|
||||||
|
"message" : operationData["message"]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// If the operation is neither of above, it is a command operation
|
// If the operation is neither of above, it is a command operation
|
||||||
operationType = operationTypeConstants["COMMAND"];
|
operationType = operationTypeConstants["COMMAND"];
|
||||||
@ -683,6 +693,8 @@ var operationModule = function () {
|
|||||||
"CLEAR_PASSWORD": "clear-password",
|
"CLEAR_PASSWORD": "clear-password",
|
||||||
"APPLICATION_LIST": "get-application-list",
|
"APPLICATION_LIST": "get-application-list",
|
||||||
"DEVICE_RING": "ring-device",
|
"DEVICE_RING": "ring-device",
|
||||||
|
"DEVICE_REBOOT": "reboot-device",
|
||||||
|
"UPGRADE_FIRMWARE": "upgrade-firmware",
|
||||||
"DEVICE_MUTE": "mute",
|
"DEVICE_MUTE": "mute",
|
||||||
"NOTIFICATION": "notification",
|
"NOTIFICATION": "notification",
|
||||||
"ENCRYPT_STORAGE": "encrypt",
|
"ENCRYPT_STORAGE": "encrypt",
|
||||||
@ -802,13 +814,15 @@ var operationModule = function () {
|
|||||||
publicMethods.getWindowsServiceEndpoint = function (operationCode) {
|
publicMethods.getWindowsServiceEndpoint = function (operationCode) {
|
||||||
var featureMap = {
|
var featureMap = {
|
||||||
"CAMERA": "camera",
|
"CAMERA": "camera",
|
||||||
"DEVICE_LOCK": "devicelock",
|
"DEVICE_LOCK": "lock",
|
||||||
"DEVICE_LOCATION": "location",
|
"DEVICE_LOCATION": "location",
|
||||||
"CLEAR_PASSWORD": "clear-password",
|
"CLEAR_PASSWORD": "clear-password",
|
||||||
"APPLICATION_LIST": "get-application-list",
|
"APPLICATION_LIST": "get-application-list",
|
||||||
"DEVICE_RING": "devicering",
|
"DEVICE_RING": "ring-device",
|
||||||
|
"DEVICE_REBOOT": "reboot-device",
|
||||||
|
"UPGRADE_FIRMWARE": "upgrade-firmware",
|
||||||
"DEVICE_MUTE": "mute",
|
"DEVICE_MUTE": "mute",
|
||||||
"LOCK_RESET": "lockreset",
|
"LOCK_RESET": "lock-reset",
|
||||||
"NOTIFICATION": "notification",
|
"NOTIFICATION": "notification",
|
||||||
"ENCRYPT_STORAGE": "encrypt",
|
"ENCRYPT_STORAGE": "encrypt",
|
||||||
"CHANGE_LOCK_CODE": "change-lock-code",
|
"CHANGE_LOCK_CODE": "change-lock-code",
|
||||||
@ -818,8 +832,8 @@ var operationModule = function () {
|
|||||||
"BLACKLIST_APPLICATIONS": "blacklist-applications",
|
"BLACKLIST_APPLICATIONS": "blacklist-applications",
|
||||||
"PASSCODE_POLICY": "password-policy",
|
"PASSCODE_POLICY": "password-policy",
|
||||||
"ENTERPRISE_WIPE": "enterprise-wipe",
|
"ENTERPRISE_WIPE": "enterprise-wipe",
|
||||||
"WIPE_DATA": "devicewipe",
|
"WIPE_DATA": "wipe-data",
|
||||||
"DISENROLL": "devicedisenroll"
|
"DISENROLL": "disenroll"
|
||||||
};
|
};
|
||||||
return "/mdm-windows-agent/services/windows/operation/" + featureMap[operationCode];
|
return "/mdm-windows-agent/services/windows/operation/" + featureMap[operationCode];
|
||||||
};
|
};
|
||||||
@ -836,6 +850,8 @@ var operationModule = function () {
|
|||||||
"ENTERPRISE_WIPE": "fw-clear",
|
"ENTERPRISE_WIPE": "fw-clear",
|
||||||
"WIPE_DATA": "fw-database",
|
"WIPE_DATA": "fw-database",
|
||||||
"DEVICE_RING": "fw-dial-up",
|
"DEVICE_RING": "fw-dial-up",
|
||||||
|
"DEVICE_REBOOT": "fw-refresh",
|
||||||
|
"UPGRADE_FIRMWARE": "fw-up-arrow",
|
||||||
"DEVICE_MUTE": "fw-incoming-call",
|
"DEVICE_MUTE": "fw-incoming-call",
|
||||||
"NOTIFICATION": "fw-message",
|
"NOTIFICATION": "fw-message",
|
||||||
"CHANGE_LOCK_CODE": "fw-security"
|
"CHANGE_LOCK_CODE": "fw-security"
|
||||||
@ -855,6 +871,8 @@ var operationModule = function () {
|
|||||||
"DISENROLL": "fw-delete",
|
"DISENROLL": "fw-delete",
|
||||||
"WIPE_DATA": "fw-clear",
|
"WIPE_DATA": "fw-clear",
|
||||||
"DEVICE_RING": "fw-dial-up",
|
"DEVICE_RING": "fw-dial-up",
|
||||||
|
"DEVICE_REBOOT": "fw-refresh",
|
||||||
|
"UPGRADE_FIRMWARE": "fw-up-arrow",
|
||||||
"DEVICE_MUTE": "fw-incoming-call",
|
"DEVICE_MUTE": "fw-incoming-call",
|
||||||
"NOTIFICATION": "fw-message",
|
"NOTIFICATION": "fw-message",
|
||||||
"LOCK_RESET": "fw-key"
|
"LOCK_RESET": "fw-key"
|
||||||
@ -872,7 +890,8 @@ var operationModule = function () {
|
|||||||
"DEVICE_LOCK": "fw-lock",
|
"DEVICE_LOCK": "fw-lock",
|
||||||
"LOCATION": "fw-map-location",
|
"LOCATION": "fw-map-location",
|
||||||
"ENTERPRISE_WIPE": "fw-clear",
|
"ENTERPRISE_WIPE": "fw-clear",
|
||||||
"ALARM": "fw-dial-up"
|
"NOTIFICATION": "fw-message",
|
||||||
|
"RING": "fw-dial-up"
|
||||||
};
|
};
|
||||||
return featureMap[operationCode];
|
return featureMap[operationCode];
|
||||||
};
|
};
|
||||||
@ -1059,7 +1078,7 @@ var operationModule = function () {
|
|||||||
} else if (operationDataObj.is("select")) {
|
} else if (operationDataObj.is("select")) {
|
||||||
operationDataObj.val(value);
|
operationDataObj.val(value);
|
||||||
/* trigger a change of value, so that if slidable panes exist,
|
/* trigger a change of value, so that if slidable panes exist,
|
||||||
make them slide-down or slide-up accordingly */
|
make them slide-down or slide-up accordingly */
|
||||||
operationDataObj.trigger("change");
|
operationDataObj.trigger("change");
|
||||||
} else if (operationDataObj.hasClass("grouped-array-input")) {
|
} else if (operationDataObj.hasClass("grouped-array-input")) {
|
||||||
// then value is complex
|
// then value is complex
|
||||||
|
|||||||
@ -52,7 +52,9 @@ var invokerUtil = function () {
|
|||||||
data.data = JSON.stringify(paramValue);
|
data.data = JSON.stringify(paramValue);
|
||||||
$.ajax(data).fail(function (jqXHR) {
|
$.ajax(data).fail(function (jqXHR) {
|
||||||
if (jqXHR.status == "401") {
|
if (jqXHR.status == "401") {
|
||||||
window.location.replace("/devicemgt");
|
console.log("Unauthorized access attempt!");
|
||||||
|
$(modalPopupContent).html($('#error-msg').html());
|
||||||
|
showPopup();
|
||||||
} else {
|
} else {
|
||||||
errorCallback(jqXHR);
|
errorCallback(jqXHR);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,20 @@
|
|||||||
{{#zone "bottomJs"}}
|
{{#zone "bottomJs"}}
|
||||||
{{js "js/js.cookie.js"}}
|
{{js "js/js.cookie.js"}}
|
||||||
{{js "js/invoker-lib.js"}}
|
{{js "js/invoker-lib.js"}}
|
||||||
|
|
||||||
|
<div id="error-msg" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-error fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
Unauthorized action!
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
@ -13,7 +13,16 @@
|
|||||||
Loading policies . . .
|
Loading policies . . .
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
<span id="policy-listing-status-msg" class="hidden">{{policyListingStatusMsg}}</span>
|
<div id="policy-listing-status" class="raw hidden">
|
||||||
|
<ul style="list-style-type: none;">
|
||||||
|
<li class="message message-info" >
|
||||||
|
<h4>
|
||||||
|
<i class="icon fw fw-info"></i>
|
||||||
|
<a id="policy-listing-status-msg">{{policyListingStatusMsg}}</a>
|
||||||
|
</h4>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
{{#equal noPolicy false}}
|
{{#equal noPolicy false}}
|
||||||
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
|
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
|
||||||
id="policy-grid">
|
id="policy-grid">
|
||||||
|
|||||||
@ -49,6 +49,12 @@ function onRequest(context) {
|
|||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/delete")) {
|
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/delete")) {
|
||||||
context["removePermitted"] = true;
|
context["removePermitted"] = true;
|
||||||
}
|
}
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/remove")) {
|
||||||
|
context["removePermitted"] = true;
|
||||||
|
}
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/update")) {
|
||||||
|
context["editPermitted"] = true;
|
||||||
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -137,7 +137,10 @@ $(document).ready(function () {
|
|||||||
$("#policy-users").hide();
|
$("#policy-users").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#policy-listing-status-msg").removeClass("hidden");
|
if ($("#policy-listing-status-msg").text()) {
|
||||||
|
$("#policy-listing-status").removeClass("hidden");
|
||||||
|
}
|
||||||
|
|
||||||
// Click functions related to Policy Listing
|
// Click functions related to Policy Listing
|
||||||
var isUpdated = $('#is-updated').val();
|
var isUpdated = $('#is-updated').val();
|
||||||
if (!isUpdated) {
|
if (!isUpdated) {
|
||||||
@ -218,7 +221,7 @@ $(document).ready(function () {
|
|||||||
$(".policy-unpublish-link").click(function () {
|
$(".policy-unpublish-link").click(function () {
|
||||||
var policyList = getSelectedPolicies();
|
var policyList = getSelectedPolicies();
|
||||||
var statusList = getSelectedPolicyStates();
|
var statusList = getSelectedPolicyStates();
|
||||||
if (($.inArray('Inactive/Updated', statusList) > -1) || ($.inArray('Inactive', statusList) > -1)) {
|
if ( ($.inArray( 'Inactive/Updated', statusList ) > -1) || ($.inArray( 'Inactive', statusList ) > -1) ) {
|
||||||
$(modalPopupContent).html($("#errorPolicyUnPublishSelection").html());
|
$(modalPopupContent).html($("#errorPolicyUnPublishSelection").html());
|
||||||
showPopup();
|
showPopup();
|
||||||
} else {
|
} else {
|
||||||
@ -262,7 +265,7 @@ $(document).ready(function () {
|
|||||||
$(".policy-publish-link").click(function () {
|
$(".policy-publish-link").click(function () {
|
||||||
var policyList = getSelectedPolicies();
|
var policyList = getSelectedPolicies();
|
||||||
var statusList = getSelectedPolicyStates();
|
var statusList = getSelectedPolicyStates();
|
||||||
if (($.inArray('Active/Updated', statusList) > -1) || ($.inArray('Active', statusList) > -1)) {
|
if ( ($.inArray( 'Active/Updated', statusList ) > -1) || ($.inArray( 'Active', statusList ) > -1) ) {
|
||||||
$(modalPopupContent).html($("#errorPolicyPublishSelection").html());
|
$(modalPopupContent).html($("#errorPolicyPublishSelection").html());
|
||||||
showPopup();
|
showPopup();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,15 +1,31 @@
|
|||||||
<!-- content/body -->
|
<!-- content/body -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
|
|
||||||
<!-- content -->
|
<!-- content -->
|
||||||
<div id="role-create-form" class="container col-centered wr-content">
|
<div id="role-create-form" class="container col-centered wr-content">
|
||||||
<div class="wr-form">
|
<div class="wr-form">
|
||||||
<p class="page-sub-title">Add Role</p>
|
<p class="page-sub-title">Add Role</p>
|
||||||
|
|
||||||
<p>Please note that * sign represents required fields of data.</p>
|
|
||||||
<hr/>
|
<hr/>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8">
|
<div class="col-lg-8">
|
||||||
|
<div class="wr-steps">
|
||||||
|
<div class="col-md-6 col-xs-6">
|
||||||
|
<div class="itm-wiz itm-wiz-current" data-step="policy-platform">
|
||||||
|
<div class="wiz-no">1</div>
|
||||||
|
<div class="wiz-lbl hidden-xs"><span>Add a role</span></div>
|
||||||
|
</div>
|
||||||
|
<br class="c-both"/>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 col-xs-6">
|
||||||
|
<div class="itm-wiz" data-step="policy-profile">
|
||||||
|
<div class="wiz-no">2</div>
|
||||||
|
<div class="wiz-lbl hidden-xs"><span>Assign permissions</span></div>
|
||||||
|
</div>
|
||||||
|
<br class="c-both"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br/><br/><hr/>
|
||||||
<div id="role-create-error-msg" class="alert alert-danger hidden" role="alert">
|
<div id="role-create-error-msg" class="alert alert-danger hidden" role="alert">
|
||||||
<i class="icon fw fw-error"></i><span></span>
|
<i class="icon fw fw-error"></i><span></span>
|
||||||
</div>
|
</div>
|
||||||
@ -27,13 +43,15 @@
|
|||||||
Role Name *
|
Role Name *
|
||||||
</label>
|
</label>
|
||||||
<br>
|
<br>
|
||||||
<label class="wr-input-label" id="roleNameValidationText">
|
<label class="wr-input-label">
|
||||||
( {{roleNameHelpText}} )
|
( {{roleNameHelpText}} )
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div class="wr-input-control">
|
<div id="roleNameField" class="form-group wr-input-control">
|
||||||
<input type="text" id="rolename" data-regex="{{roleNameJSRegEx}}"
|
<input type="text" id="rolename" data-regex="{{roleNameJSRegEx}}"
|
||||||
data-errormsg="{{roleNameRegExViolationErrorMsg}}" class="form-control"/>
|
data-errormsg="{{roleNameRegExViolationErrorMsg}}" class="form-control"/>
|
||||||
|
<span class=" rolenameError hidden glyphicon glyphicon-remove form-control-feedback"></span>
|
||||||
|
<label class="error rolenameEmpty hidden" for="summary">Role name is required & Should be in minimum 3 characters long and do not include any whitespaces. </label>
|
||||||
</div>
|
</div>
|
||||||
<label class="wr-input-label">
|
<label class="wr-input-label">
|
||||||
User list
|
User list
|
||||||
|
|||||||
@ -29,16 +29,61 @@ function inputIsValid(regExp, inputString) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var validateInline = {};
|
var validateInline = {};
|
||||||
|
var clearInline = {};
|
||||||
|
|
||||||
|
var enableInlineError = function (inputField, errorMsg, errorSign) {
|
||||||
|
var fieldIdentifier = "#" + inputField;
|
||||||
|
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||||
|
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||||
|
|
||||||
|
if (inputField) {
|
||||||
|
$(fieldIdentifier).addClass(" has-error has-feedback");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMsg) {
|
||||||
|
$(errorMsgIdentifier).removeClass(" hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorSign) {
|
||||||
|
$(errorSignIdentifier).removeClass(" hidden");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var disableInlineError = function (inputField, errorMsg, errorSign) {
|
||||||
|
var fieldIdentifier = "#" + inputField;
|
||||||
|
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||||
|
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||||
|
|
||||||
|
if (inputField) {
|
||||||
|
$(fieldIdentifier).removeClass(" has-error has-feedback");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMsg) {
|
||||||
|
$(errorMsgIdentifier).addClass(" hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorSign) {
|
||||||
|
$(errorSignIdentifier).addClass(" hidden");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate if provided username is valid against RegEx configures.
|
*clear inline validation messages.
|
||||||
|
*/
|
||||||
|
clearInline["role-name"] = function () {
|
||||||
|
disableInlineError("roleNameField", "rolenameEmpty", "rolenameError");
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate if provided rolename is valid against RegEx configures.
|
||||||
*/
|
*/
|
||||||
validateInline["role-name"] = function () {
|
validateInline["role-name"] = function () {
|
||||||
var rolenameinput = $("input#rolename");
|
var rolenameinput = $("input#rolename");
|
||||||
if (inputIsValid( rolenameinput.data("regex"), rolenameinput.val())) {
|
if (inputIsValid( rolenameinput.data("regex"), rolenameinput.val())) {
|
||||||
$("#roleNameValidationText").removeClass("inline-warning");
|
disableInlineError("roleNameField", "rolenameEmpty", "rolenameError");
|
||||||
} else {
|
} else {
|
||||||
$("#roleNameValidationText").addClass("inline-warning");
|
enableInlineError("roleNameField", "rolenameEmpty", "rolenameError");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -155,11 +200,12 @@ $(document).ready(function () {
|
|||||||
$(errorMsgWrapper).removeClass("hidden");
|
$(errorMsgWrapper).removeClass("hidden");
|
||||||
} else {
|
} else {
|
||||||
// Clearing user input fields.
|
// Clearing user input fields.
|
||||||
$("input#rolename").val("");
|
//$("input#rolename").val("");
|
||||||
$("#domain").val("");
|
//$("#domain").val("");
|
||||||
// Refreshing with success message
|
//// Refreshing with success message
|
||||||
$("#role-create-form").addClass("hidden");
|
//$("#role-create-form").addClass("hidden");
|
||||||
$("#role-created-msg").removeClass("hidden");
|
//$("#role-created-msg").removeClass("hidden");
|
||||||
|
window.location.href = '/devicemgt/role/edit-permission/' + roleName + '?wizard=true';
|
||||||
}
|
}
|
||||||
}, function (data) {
|
}, function (data) {
|
||||||
if (JSON.parse(data.responseText).errorMessage.indexOf("RoleExisting") > -1) {
|
if (JSON.parse(data.responseText).errorMessage.indexOf("RoleExisting") > -1) {
|
||||||
@ -174,7 +220,7 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#rolename").focus(function() {
|
$("#rolename").focus(function() {
|
||||||
$("#roleNameValidationText").removeClass("inline-warning");
|
clearInline["role-name"]();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#rolename").blur(function() {
|
$("#rolename").blur(function() {
|
||||||
|
|||||||
@ -6,6 +6,24 @@
|
|||||||
<div class="wr-form">
|
<div class="wr-form">
|
||||||
<p class="page-sub-title">Change Role permissions</p>
|
<p class="page-sub-title">Change Role permissions</p>
|
||||||
<p>Please note that * sign represents required fields of data.</p>
|
<p>Please note that * sign represents required fields of data.</p>
|
||||||
|
<div class="wr-steps hidden" id="role_wizard_header">
|
||||||
|
<hr/>
|
||||||
|
<div class="col-md-4 col-xs-6">
|
||||||
|
<div class="itm-wiz" data-step="policy-platform">
|
||||||
|
<div class="wiz-no">1</div>
|
||||||
|
<div class="wiz-lbl hidden-xs"><span>Add a role</span></div>
|
||||||
|
</div>
|
||||||
|
<br class="c-both"/>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 col-xs-6">
|
||||||
|
<div class="itm-wiz itm-wiz-current" data-step="policy-profile">
|
||||||
|
<div class="wiz-no">2</div>
|
||||||
|
<div class="wiz-lbl hidden-xs"><span>Assign permissions</span></div>
|
||||||
|
</div>
|
||||||
|
<br class="c-both"/>
|
||||||
|
</div>
|
||||||
|
<br/><br/>
|
||||||
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8">
|
<div class="col-lg-8">
|
||||||
|
|||||||
@ -88,6 +88,11 @@ $.fn.toggleAttr = function (attr, val, val2) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
|
if(get('wizard') == 'true') {
|
||||||
|
$("#role_wizard_header").removeClass("hidden");
|
||||||
|
}
|
||||||
|
|
||||||
var listPartialSrc = $("#list-partial").attr("src");
|
var listPartialSrc = $("#list-partial").attr("src");
|
||||||
var treeTemplateSrc = $("#tree-template").attr("src");
|
var treeTemplateSrc = $("#tree-template").attr("src");
|
||||||
var roleName = $("#permissionList").data("currentrole");
|
var roleName = $("#permissionList").data("currentrole");
|
||||||
@ -156,4 +161,9 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function get(name){
|
||||||
|
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
|
||||||
|
return decodeURIComponent(name[1]);
|
||||||
|
}
|
||||||
@ -24,9 +24,11 @@
|
|||||||
<label class="wr-input-label" id="roleNameValidationText">
|
<label class="wr-input-label" id="roleNameValidationText">
|
||||||
( {{roleNameHelpText}} )
|
( {{roleNameHelpText}} )
|
||||||
</label>
|
</label>
|
||||||
<div class="wr-input-control">
|
<div id="roleNameField" class="form-group wr-input-control">
|
||||||
<input type="text" id="rolename" data-regex="{{roleNameJSRegEx}}" data-errormsg="{{roleNameRegExViolationErrorMsg}}" class="form-control" data-currentrole="{{role.roleName}}"
|
<input type="text" id="rolename" data-regex="{{roleNameJSRegEx}}" data-errormsg="{{roleNameRegExViolationErrorMsg}}" class="form-control" data-currentrole="{{role.roleName}}"
|
||||||
value="{{role.roleName}}"/>
|
value="{{role.roleName}}"/>
|
||||||
|
<span class=" rolenameError hidden glyphicon glyphicon-remove form-control-feedback"></span>
|
||||||
|
<label class="error rolenameEmpty hidden" for="summary">Role name is required & Should be in minimum 3 characters long and do not include any whitespaces. </label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -29,16 +29,61 @@ function inputIsValid(regExp, inputString) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var validateInline = {};
|
var validateInline = {};
|
||||||
|
var clearInline = {};
|
||||||
|
|
||||||
|
var enableInlineError = function (inputField, errorMsg, errorSign) {
|
||||||
|
var fieldIdentifier = "#" + inputField;
|
||||||
|
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||||
|
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||||
|
|
||||||
|
if (inputField) {
|
||||||
|
$(fieldIdentifier).addClass(" has-error has-feedback");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMsg) {
|
||||||
|
$(errorMsgIdentifier).removeClass(" hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorSign) {
|
||||||
|
$(errorSignIdentifier).removeClass(" hidden");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var disableInlineError = function (inputField, errorMsg, errorSign) {
|
||||||
|
var fieldIdentifier = "#" + inputField;
|
||||||
|
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||||
|
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||||
|
|
||||||
|
if (inputField) {
|
||||||
|
$(fieldIdentifier).removeClass(" has-error has-feedback");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMsg) {
|
||||||
|
$(errorMsgIdentifier).addClass(" hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorSign) {
|
||||||
|
$(errorSignIdentifier).addClass(" hidden");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate if provided username is valid against RegEx configures.
|
*clear inline validation messages.
|
||||||
|
*/
|
||||||
|
clearInline["role-name"] = function () {
|
||||||
|
disableInlineError("roleNameField", "rolenameEmpty", "rolenameError");
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate if provided rolename is valid against RegEx configures.
|
||||||
*/
|
*/
|
||||||
validateInline["role-name"] = function () {
|
validateInline["role-name"] = function () {
|
||||||
var rolenameinput = $("input#rolename");
|
var rolenameinput = $("input#rolename");
|
||||||
if (inputIsValid( rolenameinput.data("regex"), rolenameinput.val())) {
|
if (inputIsValid( rolenameinput.data("regex"), rolenameinput.val())) {
|
||||||
$("#roleNameValidationText").removeClass("inline-warning");
|
disableInlineError("roleNameField", "rolenameEmpty", "rolenameError");
|
||||||
} else {
|
} else {
|
||||||
$("#roleNameValidationText").addClass("inline-warning");
|
enableInlineError("roleNameField", "rolenameEmpty", "rolenameError");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -160,7 +205,7 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#rolename").focus(function() {
|
$("#rolename").focus(function() {
|
||||||
$("#roleNameValidationText").removeClass("inline-warning");
|
clearInline["role-name"]();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#rolename").blur(function() {
|
$("#rolename").blur(function() {
|
||||||
|
|||||||
@ -9,7 +9,17 @@
|
|||||||
Loading roles . . .
|
Loading roles . . .
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
<span id="role-listing-status-msg"></span>
|
|
||||||
|
<div id="role-listing-status" class="raw">
|
||||||
|
<ul style="list-style-type: none;">
|
||||||
|
<li class="message message-info" >
|
||||||
|
<h4>
|
||||||
|
<i class="icon fw fw-info"></i>
|
||||||
|
<a id="role-listing-status-msg"></a>
|
||||||
|
</h4>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="role-table" data-role={{adminRole}}>
|
<div id="role-table" data-role={{adminRole}}>
|
||||||
<table class="table table-striped table-hover list-table display responsive nowrap data-table row-view"
|
<table class="table table-striped table-hover list-table display responsive nowrap data-table row-view"
|
||||||
|
|||||||
@ -27,6 +27,9 @@ function onRequest(context) {
|
|||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/roles/update")) {
|
if (userModule.isAuthorized("/permission/admin/device-mgt/roles/update")) {
|
||||||
context["editPermitted"] = true;
|
context["editPermitted"] = true;
|
||||||
}
|
}
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/roles/remove")) {
|
||||||
|
context["removePermitted"] = true;
|
||||||
|
}
|
||||||
var deviceMgtProps = require("/app/conf/devicemgt-props.js").config();
|
var deviceMgtProps = require("/app/conf/devicemgt-props.js").config();
|
||||||
context["appContext"] = deviceMgtProps.appContext;
|
context["appContext"] = deviceMgtProps.appContext;
|
||||||
context["adminRole"] = deviceMgtProps.adminRole;
|
context["adminRole"] = deviceMgtProps.adminRole;
|
||||||
|
|||||||
@ -42,7 +42,7 @@ var loadPaginatedObjects = function (objectGridId, objectGridContainer, objectGr
|
|||||||
data = callback(data);
|
data = callback(data);
|
||||||
if (data.length > 0 && data != null) {
|
if (data.length > 0 && data != null) {
|
||||||
$('#ast-container').removeClass('hidden');
|
$('#ast-container').removeClass('hidden');
|
||||||
$('#role-listing-status-msg').text('');
|
$('#role-listing-status').hide();
|
||||||
for (var i = 0; i < data.viewModel.roles.length; i++) {
|
for (var i = 0; i < data.viewModel.roles.length; i++) {
|
||||||
data.viewModel.roles[i].adminRole = $("#role-table").data("role");
|
data.viewModel.roles[i].adminRole = $("#role-table").data("role");
|
||||||
}
|
}
|
||||||
@ -57,12 +57,15 @@ var loadPaginatedObjects = function (objectGridId, objectGridContainer, objectGr
|
|||||||
} else {
|
} else {
|
||||||
$('#ast-container').addClass('hidden');
|
$('#ast-container').addClass('hidden');
|
||||||
$('#role-listing-status-msg').text('No roles are available to be displayed.');
|
$('#role-listing-status-msg').text('No roles are available to be displayed.');
|
||||||
|
$('#role-listing-status').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
//$(objectGridId).datatables_extended();
|
//$(objectGridId).datatables_extended();
|
||||||
}, function (message) {
|
}, function (message) {
|
||||||
$('#ast-container').addClass('hidden');
|
$('#ast-container').addClass('hidden');
|
||||||
$('#role-listing-status-msg').text('Invalid search query. Try again with a valid search query');
|
$('#role-listing-status-msg').text('Invalid search query. Try again with a valid search ' +
|
||||||
|
'query');
|
||||||
|
$('#role-listing-status').show();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -80,7 +83,7 @@ function loadRoles(searchQuery) {
|
|||||||
var canRemove = $("#can-remove").val();
|
var canRemove = $("#can-remove").val();
|
||||||
var canEdit = $("#can-edit").val();
|
var canEdit = $("#can-edit").val();
|
||||||
var roles = [];
|
var roles = [];
|
||||||
for(var i=0; i<data.responseContent.length; i++) {
|
for(var i=0; i<data.responseContent.length; i++){
|
||||||
roles.push({"roleName":data.responseContent[i]});
|
roles.push({"roleName":data.responseContent[i]});
|
||||||
if(canRemove != null && canRemove != undefined) {
|
if(canRemove != null && canRemove != undefined) {
|
||||||
roles[i].canRemove = true;
|
roles[i].canRemove = true;
|
||||||
@ -189,6 +192,7 @@ $("#search-btn").click(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
$('#role-listing-status').hide();
|
||||||
loadRoles();
|
loadRoles();
|
||||||
isInit = true;
|
isInit = true;
|
||||||
});
|
});
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user