diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml
index 546fdd32b5..a36f912d2a 100644
--- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml
@@ -31,7 +31,7 @@
4.0.0
org.wso2.carbon.certificate.mgt.api
war
- WSO2 Carbon - Mobile Device Management API
+ WSO2 Carbon - Certificate Management API
WSO2 Carbon - Certificate Management API
http://wso2.org
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/CertificateMgtService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/CertificateMgtService.java
index c0ba1d929a..6c9abc27b6 100644
--- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/CertificateMgtService.java
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/CertificateMgtService.java
@@ -13,7 +13,7 @@ public interface CertificateMgtService {
* @return X509Certificate type sign certificate.
*/
@POST
- @Path("csr-sign")
+ @Path("signcsr")
@Produces({MediaType.TEXT_PLAIN, MediaType.TEXT_PLAIN})
@Consumes({MediaType.TEXT_PLAIN, MediaType.TEXT_PLAIN})
Response getSignedCertFromCSR(String binarySecurityToken);
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/impl/CertificateMgtServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/impl/CertificateMgtServiceImpl.java
index 082f203bf2..e0ca24de02 100644
--- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/impl/CertificateMgtServiceImpl.java
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/impl/CertificateMgtServiceImpl.java
@@ -8,10 +8,7 @@ import org.wso2.carbon.certificate.mgt.core.impl.CertificateGenerator;
import org.wso2.carbon.certificate.mgt.jaxrs.api.CertificateMgtService;
import org.wso2.carbon.certificate.mgt.jaxrs.exception.Message;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
+import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.security.cert.CertificateEncodingException;
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/pom.xml
new file mode 100644
index 0000000000..3528287e95
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/pom.xml
@@ -0,0 +1,209 @@
+
+
+
+
+
+
+ certificate-mgt
+ org.wso2.carbon.devicemgt
+ 1.1.1-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.certificate.mgt.cert.adminapi
+ war
+ WSO2 Carbon - Admin Certificate Management API
+ WSO2 Carbon - Admin Certificate Management API
+ http://wso2.org
+
+
+
+
+ maven-compiler-plugin
+
+
+ 1.7
+
+
+
+ maven-war-plugin
+
+ WEB-INF/lib/*cxf*.jar
+ admin-certificate
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+
+
+
+
+
+
+ deploy
+
+ compile
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 1.7
+
+
+ compile
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ client
+
+ test
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.2.1
+
+
+ test
+
+ java
+
+
+
+
+
+
+
+
+
+
+
+ org.apache.cxf
+ cxf-rt-frontend-jaxws
+
+
+ commons-codec.wso2
+ commons-codec
+
+
+ commons-codec
+ commons-codec
+
+
+
+
+ org.apache.cxf
+ cxf-rt-frontend-jaxrs
+
+
+ org.apache.cxf
+ cxf-rt-transports-http
+
+
+ junit
+ junit
+ test
+
+
+ javax.ws.rs
+ jsr311-api
+ provided
+
+
+ org.wso2.carbon
+ org.wso2.carbon.logging
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+ provided
+
+
+ org.apache.axis2.wso2
+ axis2-client
+
+
+ org.apache.neethi.wso2
+ neethi
+
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.certificate.mgt.core
+ provided
+
+
+ io.swagger
+ swagger-annotations
+
+
+ io.swagger
+ swagger-core
+
+
+ org.slf4j
+ slf4j-api
+
+
+
+
+ io.swagger
+ swagger-jaxrs
+
+
+ javax.servlet
+ servlet-api
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.apimgt.annotations
+ provided
+
+
+
+
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/Certificate.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/Certificate.java
new file mode 100644
index 0000000000..1192cdfa13
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/Certificate.java
@@ -0,0 +1,123 @@
+package org.wso2.carbon.certificate.mgt.cert.jaxrs.api;
+
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.wso2.carbon.apimgt.annotations.api.Permission;
+import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.EnrollmentCertificate;
+import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.common.MDMAPIException;
+import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
+import org.wso2.carbon.device.mgt.common.PaginationResult;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+public interface Certificate {
+
+ /**
+ * 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.
+ */
+ @POST
+ @ApiOperation(
+ consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
+ produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
+ httpMethod = "POST",
+ value = "Adding an SSL Certificate",
+ notes = "Add a new SSL certificate to the client end database")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Added successfully"),
+ @ApiResponse(code = 500, message = "Error occurred while saving the certificate")
+ })
+ @Permission(scope = "certificate-modify", permissions = {"/permission/admin/device-mgt/certificate/save"})
+ Response saveCertificate(@HeaderParam("Accept") String acceptHeader,
+ @ApiParam(name = "enrollmentCertificates", value = "certificate with serial, "
+ + "pem and tenant id", required = true) EnrollmentCertificate[]
+ enrollmentCertificates);
+
+ /**
+ * Get a certificate when the serial number is given.
+ *
+ * @param serialNumber serial of the certificate needed.
+ * @return certificate response.
+ */
+ @GET
+ @Path("{serialNumber}")
+ @ApiOperation(
+ consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
+ produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
+ httpMethod = "GET",
+ value = "Getting Details of an SSL Certificate",
+ notes = "Get the client side SSL certificate details",
+ response = CertificateResponse.class)
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK", response = CertificateResponse.class),
+ @ApiResponse(code = 400, message = "Notification status updated successfully"),
+ @ApiResponse(code = 500, message = "Error occurred while converting PEM file to X509Certificate")
+ })
+ @Permission(scope = "certificate-view", permissions = {"/permission/admin/device-mgt/certificate/view"})
+ Response getCertificate(@HeaderParam("Accept") String acceptHeader,
+ @ApiParam(name = "serialNumber", value = "Provide the serial number of the "
+ + "certificate that you wish to get the details of", required = true)
+ @PathParam("serialNumber") String serialNumber);
+
+ /**
+ * 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")
+ @ApiOperation(
+ consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
+ produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
+ httpMethod = "GET",
+ value = "Getting the Certificate Details in a Paginated Manner",
+ notes = "You will have many certificates used for mutual SSL. In a situation where you wish to "
+ + "view all the certificate details, it is not feasible to show all the details on one "
+ + "page therefore the details are paginated",
+ response = PaginationResult.class)
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK", response = PaginationResult.class),
+ @ApiResponse(code = 400, message = "Invalid start index"),
+ @ApiResponse(code = 400, message = "Invalid length value"),
+ @ApiResponse(code = 500, message = "Error occurred while fetching all certificates")
+ })
+ @Permission(scope = "certificate-view", permissions = {"/permission/admin/device-mgt/certificate/view"})
+ Response getAllCertificates(@HeaderParam("Accept") String acceptHeader,
+ @ApiParam(name = "start",
+ value = "Provide the starting pagination index as the value", required = true)
+ @QueryParam("start") int startIndex,
+ @ApiParam(name = "length", value = "Provide how many certificate details you"
+ + " require from the starting pagination index as the value",
+ required = true) @QueryParam("length") int length) throws MDMAPIException;
+
+ @DELETE
+ @Path("{serialNumber}")
+ @ApiOperation(
+ consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
+ produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
+ httpMethod = "DELETE",
+ value = "Deleting an SSL Certificate",
+ notes = "Delete an SSL certificate that's on the client end",
+ response = boolean.class)
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK"),
+ @ApiResponse(code = 400, message = "Invalid start index"),
+ @ApiResponse(code = 500, message = "Error when deleting the certificate"
+ ) })
+ @Permission(scope = "certificate-modify", permissions = {"/permission/admin/device-mgt/certificate/remove"})
+ Response removeCertificate(@HeaderParam("Accept") String acceptHeader,
+ @ApiParam(name = "serialNumber", value = "Provide the serial number of the "
+ + "certificate that you wish to delete", required = true)
+ @PathParam("serialNumber") String serialNumber) throws MDMAPIException;
+
+}
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java
new file mode 100644
index 0000000000..a687a259bb
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java
@@ -0,0 +1,34 @@
+package org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans;
+
+/**
+ * Created by hasunie on 5/26/16.
+ */
+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;
+ }
+}
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/ErrorHandler.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/ErrorHandler.java
new file mode 100644
index 0000000000..25d9e4ad79
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/ErrorHandler.java
@@ -0,0 +1,33 @@
+/*
+ * 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.certificate.mgt.cert.jaxrs.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 {
+
+ public Response toResponse(MDMAPIException exception) {
+ ErrorMessage errorMessage = new ErrorMessage();
+ errorMessage.setErrorMessage(exception.getErrorMessage());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
+ }
+}
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/ErrorMessage.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/ErrorMessage.java
new file mode 100644
index 0000000000..3bbb36969d
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/ErrorMessage.java
@@ -0,0 +1,42 @@
+/*
+ * 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.certificate.mgt.cert.jaxrs.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;
+ }
+}
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java
new file mode 100644
index 0000000000..6abb296c17
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.adminapi/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java
@@ -0,0 +1,95 @@
+/*
+ * 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.certificate.mgt.cert.jaxrs.api.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