Restructured CEA mgt admin api

fix-access-authorization
Rajitha Kumara 10 months ago
parent 53c6fa86bc
commit d1e72cdf7a

@ -0,0 +1,195 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. 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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>cea-mgt</artifactId>
<version>5.0.40-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.cea.mgt.admin.api</artifactId>
<packaging>war</packaging>
<name>Entgra IoT - CEA Management Admin API</name>
<description>Entgra IoT - Conditional Email Access Management Admin API</description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
<warName>api#cea-mgt#v1.0</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
<outputDirectory>${basedir}/target/coverage-reports/site</outputDirectory>
</configuration>
</execution>
</executions>
</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="api#cea-mgt#v1.0.war" />
</fileset>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.apimgt.annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.cea.mgt.common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

@ -1,4 +1,23 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.cea.mgt.admin.api.bean;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;

@ -1,12 +1,12 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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
* 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
@ -14,9 +14,10 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
package io.entgra.device.mgt.core.cea.mgt.admin.api.bean;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServer;

@ -1,11 +1,28 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.cea.mgt.admin.api.bean;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Set;
@ApiModel(value = "GracePeriodWrapper", description = "GracePeriod transferring DTO")
public class GracePeriodWrapper {

@ -0,0 +1,96 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.cea.mgt.admin.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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
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 {
getGson().toJson(object, type, writer);
} finally {
writer.close();
}
}
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.cea.mgt.admin.api.exception;
import javax.ws.rs.WebApplicationException;
public class BadRequestException extends WebApplicationException {
private String message;
private static final long serialVersionUID = -24991345567891192L;
public BadRequestException(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -17,11 +17,16 @@
*
*/
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.admin;
package io.entgra.device.mgt.core.cea.mgt.admin.api.impl;
import io.entgra.device.mgt.core.cea.mgt.admin.api.bean.AccessPolicyWrapper;
import io.entgra.device.mgt.core.cea.mgt.admin.api.bean.CEAPolicyWrapper;
import io.entgra.device.mgt.core.cea.mgt.admin.api.bean.GracePeriodWrapper;
import io.entgra.device.mgt.core.cea.mgt.admin.api.service.CEAManagementAdminService;
import io.entgra.device.mgt.core.cea.mgt.admin.api.util.CEAManagementApiUtil;
import io.entgra.device.mgt.core.cea.mgt.admin.api.util.RequestValidationUtil;
import io.entgra.device.mgt.core.cea.mgt.common.bean.AccessPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServer;
import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServerUIConfiguration;
import io.entgra.device.mgt.core.cea.mgt.common.bean.CEAPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.GracePeriod;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.DefaultAccessPolicy;
@ -29,21 +34,14 @@ import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.EmailOutlookAccessPol
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.GraceAllowedPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.POPIMAPAccessPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.WebOutlookAccessPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.ui.CEAPolicyUIConfiguration;
import io.entgra.device.mgt.core.cea.mgt.common.bean.ui.ServerUIConfiguration;
import io.entgra.device.mgt.core.cea.mgt.common.exception.CEAManagementException;
import io.entgra.device.mgt.core.cea.mgt.common.exception.CEAPolicyAlreadyExistsException;
import io.entgra.device.mgt.core.cea.mgt.common.exception.CEAPolicyNotFoundException;
import io.entgra.device.mgt.core.cea.mgt.common.service.CEAManagementService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.AccessPolicyWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.CEAPolicyWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.GracePeriodWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.admin.CEAManagementAdminService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.RequestValidationUtil;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import io.entgra.device.mgt.core.cea.mgt.common.bean.ui.CEAPolicyUIConfiguration;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpStatus;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@ -52,9 +50,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Path("/admin/cea-policies")
@ -67,7 +63,7 @@ public class CEAManagementAdminServiceImpl implements CEAManagementAdminService
@Path("/ui")
@Override
public Response getCEAPolicyUI() {
CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
CEAManagementService ceaManagementService = CEAManagementApiUtil.getCEAManagementService();
try {
CEAPolicyUIConfiguration ceaPolicyUIConfiguration = ceaManagementService.getCEAPolicyUIConfiguration();
if (ceaPolicyUIConfiguration == null) {
@ -86,7 +82,7 @@ public class CEAManagementAdminServiceImpl implements CEAManagementAdminService
public Response createCEAPolicy(CEAPolicyWrapper ceaPolicyWrapper) {
try {
RequestValidationUtil.validateCEAPolicy(ceaPolicyWrapper);
CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
CEAManagementService ceaManagementService = CEAManagementApiUtil.getCEAManagementService();
CEAPolicy ceaPolicy = constructCEAPolicy(ceaPolicyWrapper);
ceaPolicy = ceaManagementService.createCEAPolicy(ceaPolicy);
return Response.status(HttpStatus.SC_CREATED).entity(ceaPolicy).build();
@ -104,7 +100,7 @@ public class CEAManagementAdminServiceImpl implements CEAManagementAdminService
@Override
public Response retrieveCEAPolicy() {
try {
CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
CEAManagementService ceaManagementService = CEAManagementApiUtil.getCEAManagementService();
CEAPolicy ceaPolicy = ceaManagementService.retrieveCEAPolicy();
if (ceaPolicy == null) {
return Response.status(HttpStatus.SC_NOT_FOUND).entity("CEA policy isn't exists in the tenant").build();
@ -120,7 +116,7 @@ public class CEAManagementAdminServiceImpl implements CEAManagementAdminService
@Override
public Response deleteCEAPolicy() {
try {
CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
CEAManagementService ceaManagementService = CEAManagementApiUtil.getCEAManagementService();
ceaManagementService.deleteCEAPolicy();
return Response.status(HttpStatus.SC_OK).build();
} catch (CEAPolicyNotFoundException e) {
@ -138,7 +134,7 @@ public class CEAManagementAdminServiceImpl implements CEAManagementAdminService
public Response updateCEAPolicy(CEAPolicyWrapper ceaPolicyWrapper) {
try {
RequestValidationUtil.validateCEAPolicy(ceaPolicyWrapper);
CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
CEAManagementService ceaManagementService = CEAManagementApiUtil.getCEAManagementService();
CEAPolicy ceaPolicy = constructCEAPolicy(ceaPolicyWrapper);
ceaPolicy = ceaManagementService.updateCEAPolicy(ceaPolicy);
return Response.status(HttpStatus.SC_CREATED).entity(ceaPolicy).build();
@ -157,7 +153,7 @@ public class CEAManagementAdminServiceImpl implements CEAManagementAdminService
@Path("/sync-now")
@Override
public Response sync() {
CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
CEAManagementService ceaManagementService = CEAManagementApiUtil.getCEAManagementService();
try {
ceaManagementService.syncNow();
return Response.status(HttpStatus.SC_OK).build();

@ -1,12 +1,12 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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
* 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
@ -14,18 +14,33 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.admin;
package io.entgra.device.mgt.core.cea.mgt.admin.api.service;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.CEAPolicyWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
import io.swagger.annotations.*;
import io.entgra.device.mgt.core.cea.mgt.admin.api.bean.CEAPolicyWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import javax.ws.rs.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@ -38,7 +53,7 @@ import javax.ws.rs.core.Response;
title = "CEAManagementAdminService API",
extensions = @Extension(properties = {
@ExtensionProperty(name = "name", value = "CEAManagementAdminService"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/admin/cea-policies"),
@ExtensionProperty(name = "context", value = "/api/cea-mgt/v1.0/admin/cea-policies"),
})
),
consumes = {MediaType.APPLICATION_JSON},
@ -91,6 +106,8 @@ import javax.ws.rs.core.Response;
}
)
public interface CEAManagementAdminService {
String SCOPE = "scope";
@GET
@Path("/ui")
@ApiOperation(
@ -101,7 +118,7 @@ public interface CEAManagementAdminService {
tags = {"conditional_email_access", "device_management"},
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:view")
@ExtensionProperty(name = SCOPE, value = "dm:admin:cea:view")
})
}
)
@ -113,18 +130,20 @@ public interface CEAManagementAdminService {
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
"the requested resource.",
response = Response.class),
@ApiResponse(
code = 404,
message = "Configurations not found",
response = ErrorResponse.class),
response = Response.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
message = "Not Acceptable.\n The requested media type is not supported.",
response = Response.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the group count.",
response = ErrorResponse.class)
response = Response.class)
}
)
Response getCEAPolicyUI();
@ -139,7 +158,7 @@ public interface CEAManagementAdminService {
tags = {"conditional_email_access", "device_management"},
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:add")
@ExtensionProperty(name = SCOPE, value = "dm:admin:cea:add")
})
}
)
@ -152,21 +171,23 @@ public interface CEAManagementAdminService {
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
response = Response.class),
@ApiResponse(
code = 404,
message = "Not Found. \n The specified resource does not exist."),
message = "Not Found. \n The specified resource does not exist.",
response = Response.class),
@ApiResponse(
code = 409,
message = "Conflict. \n CEA policy already exists.",
response = Response.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
message = "Unsupported media type. \n The entity of the request was in a not supported format.",
response = Response.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while creating the resource.",
response = ErrorResponse.class)
response = Response.class)
}
)
Response createCEAPolicy(
@ -186,7 +207,7 @@ public interface CEAManagementAdminService {
tags = {"conditional_email_access", "device_management"},
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:view")
@ExtensionProperty(name = SCOPE, value = "dm:admin:cea:view")
})
}
)
@ -199,21 +220,23 @@ public interface CEAManagementAdminService {
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
response = Response.class),
@ApiResponse(
code = 404,
message = "Not Found. \n The specified resource does not exist."),
message = "Not Found. \n The specified resource does not exist.",
response = Response.class),
@ApiResponse(
code = 409,
message = "Conflict. \n CEA policy already exists.",
response = Response.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
message = "Unsupported media type. \n The entity of the request was in a not supported format.",
response = Response.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while creating the resource.",
response = ErrorResponse.class)
response = Response.class)
}
)
Response retrieveCEAPolicy();
@ -227,7 +250,7 @@ public interface CEAManagementAdminService {
tags = {"conditional_email_access", "device_management"},
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:delete")
@ExtensionProperty(name = SCOPE, value = "dm:admin:cea:delete")
})
}
)
@ -240,17 +263,19 @@ public interface CEAManagementAdminService {
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
response = Response.class),
@ApiResponse(
code = 404,
message = "Not Found. \n The specified resource does not exist."),
message = "Not Found. \n The specified resource does not exist.",
response = Response.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
message = "Unsupported media type. \n The entity of the request was in a not supported format.",
response = Response.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while creating the resource.",
response = ErrorResponse.class)
response = Response.class)
}
)
Response deleteCEAPolicy();
@ -264,7 +289,7 @@ public interface CEAManagementAdminService {
tags = {"conditional_email_access", "device_management"},
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:update")
@ExtensionProperty(name = SCOPE, value = "dm:admin:cea:update")
})
}
)
@ -277,17 +302,19 @@ public interface CEAManagementAdminService {
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
response = Response.class),
@ApiResponse(
code = 404,
message = "Not Found. \n The specified resource does not exist."),
message = "Not Found. \n The specified resource does not exist.",
response = Response.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
message = "Unsupported media type. \n The entity of the request was in a not supported format.",
response = Response.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while creating the resource.",
response = ErrorResponse.class)
response = Response.class)
}
)
Response updateCEAPolicy(@ApiParam(
@ -306,7 +333,7 @@ public interface CEAManagementAdminService {
tags = {"conditional_email_access", "device_management"},
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:sync")
@ExtensionProperty(name = SCOPE, value = "dm:admin:cea:sync")
})
}
)
@ -319,17 +346,19 @@ public interface CEAManagementAdminService {
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
response = Response.class),
@ApiResponse(
code = 404,
message = "Not Found. \n The specified resource does not exist."),
message = "Not Found. \n The specified resource does not exist.",
response = Response.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
message = "Unsupported media type. \n The entity of the request was in a not supported format.",
response = Response.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while creating the resource.",
response = ErrorResponse.class)
response = Response.class)
}
)
Response sync();

@ -0,0 +1,43 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.cea.mgt.admin.api.util;
import io.entgra.device.mgt.core.cea.mgt.common.service.CEAManagementService;
import org.wso2.carbon.context.PrivilegedCarbonContext;
public class CEAManagementApiUtil {
private static volatile CEAManagementService ceaManagementService;
public static CEAManagementService getCEAManagementService() {
if (ceaManagementService == null) {
synchronized (CEAManagementApiUtil.class) {
if (ceaManagementService == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ceaManagementService = (CEAManagementService)
ctx.getOSGiService(CEAManagementService.class, null);
if (ceaManagementService == null) {
throw new IllegalStateException("Conditional Email Access Management Service is not initialize");
}
}
}
}
return ceaManagementService;
}
}

@ -0,0 +1,133 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.cea.mgt.admin.api.util;
import io.entgra.device.mgt.core.cea.mgt.admin.api.bean.AccessPolicyWrapper;
import io.entgra.device.mgt.core.cea.mgt.admin.api.bean.CEAPolicyWrapper;
import io.entgra.device.mgt.core.cea.mgt.admin.api.bean.GracePeriodWrapper;
import io.entgra.device.mgt.core.cea.mgt.admin.api.exception.BadRequestException;
import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServer;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.DefaultAccessPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.EmailOutlookAccessPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.GraceAllowedPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.POPIMAPAccessPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.WebOutlookAccessPolicy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class RequestValidationUtil {
private static final Log log = LogFactory.getLog(RequestValidationUtil.class);
/**
* Validate conditional access policy
* @param ceaPolicyWrapper {@link CEAPolicyWrapper}
*/
public static void validateCEAPolicy(CEAPolicyWrapper ceaPolicyWrapper) {
if (ceaPolicyWrapper == null) {
String msg = "CEA policy should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
validateActiveSyncServer(ceaPolicyWrapper.getActiveSyncServerEntries());
validateCEAAccessPolicy(ceaPolicyWrapper.getConditionalAccessPolicyEntries());
validateCEAGracePeriod(ceaPolicyWrapper.getGracePeriodEntries());
}
/**
* Validate active sync server configurations
* @param activeSyncServer {@link ActiveSyncServer}
*/
public static void validateActiveSyncServer(ActiveSyncServer activeSyncServer) {
if (activeSyncServer == null) {
String msg = "Active sync server should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
if (activeSyncServer.getGatewayUrl() == null) {
String msg = "Active sync server url should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
if (activeSyncServer.getKey() == null) {
String msg = "Active sync server type should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
if (activeSyncServer.getClient() == null) {
String msg = "Active sync server username should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
if (activeSyncServer.getSecret() == null) {
String msg = "Active sync server secret should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
}
/**
* Validate conditional access policy configurations
* @param accessPolicyWrapper {@link AccessPolicyWrapper}
*/
public static void validateCEAAccessPolicy(AccessPolicyWrapper accessPolicyWrapper) {
if (accessPolicyWrapper == null) {
String msg = "Access policy should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
try {
Enum.valueOf(DefaultAccessPolicy.class, accessPolicyWrapper.getDefaultAccessPolicy());
Enum.valueOf(WebOutlookAccessPolicy.class, accessPolicyWrapper.getWebOutlookAccessPolicy());
Enum.valueOf(POPIMAPAccessPolicy.class, accessPolicyWrapper.getPOPIMAPAccessPolicy());
for(String value : accessPolicyWrapper.getEmailOutlookAccessPolicy()) {
Enum.valueOf(EmailOutlookAccessPolicy.class, value);
}
} catch (IllegalArgumentException | NullPointerException e) {
String msg = "Access policy contains illegal arguments";
log.error(msg);
throw new BadRequestException(msg);
}
}
/**
* Validate grace period configurations
* @param gracePeriodWrapper {@link GracePeriodWrapper}
*/
public static void validateCEAGracePeriod(GracePeriodWrapper gracePeriodWrapper) {
if (gracePeriodWrapper == null) {
String msg = "Grace period should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
if (gracePeriodWrapper.getGracePeriod() < 0 || gracePeriodWrapper.getGracePeriod() >
io.entgra.device.mgt.core.cea.mgt.common.util.Constants.MAX_GRACE_PERIOD_IN_DAYS) {
String msg = "Grace period should in range of 0-30 days";
log.error(msg);
throw new BadRequestException(msg);
}
try {
Enum.valueOf(GraceAllowedPolicy.class, gracePeriodWrapper.getGraceAllowedPolicy());
} catch (IllegalArgumentException | NullPointerException e) {
String msg = "Grace allowed policy contains illegal arguments";
log.error(msg);
throw new BadRequestException(msg);
}
}
}

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. 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>CXF3,Carbon</Environments>
</Classloading>

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. 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" xmlns:cxf="http://cxf.apache.org/core"
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 http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<jaxrs:server id="services" address="/">
<jaxrs:serviceBeans>
<ref bean="swaggerResource"/>
<ref bean="ceaManagementAdminService"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="swaggerWriter"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers"/>
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource"/>
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="io.entgra.device.mgt.core.cea.mgt.admin.api"/>
<property name="version" value="1.0"/>
<property name="host" value="localhost:9443"/>
<property name="schemes" value="https"/>
<property name="basePath" value="/api/cea-mgt/v1.0"/>
<property name="title" value="CEA Management Admin Service API Definitions"/>
<property name="contact" value="dev@entgra.io"/>
<property name="license" value="Apache 2.0"/>
<property name="licenseUrl" value="http://www.apache.org/licenses/LICENSE-2.0.html"/>
<property name="scan" value="true"/>
</bean>
<bean id="ceaManagementAdminService" class="io.entgra.device.mgt.core.cea.mgt.admin.api.impl.CEAManagementAdminServiceImpl"/>
<bean id="jsonProvider" class="io.entgra.device.mgt.core.cea.mgt.admin.api.common.GsonMessageBodyHandler"/>
</beans>

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. 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>CEA-Management-Webapp</display-name>
<servlet>
<description>JAX-WS/JAX-RS Conditional Email Access Management 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>
</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>doAuthentication</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>basicAuth</param-name>
<param-value>true</param-value>
</context-param>
<!--publish to apim-->
<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>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<security-constraint>
<web-resource-collection>
<web-resource-name>CEAMgt-Admin</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<filter>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<init-param>
<param-name>hstsEnabled</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<filter-class>org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter</filter-class>
<init-param>
<param-name>patterns</param-name>
<param-value>text/html" ,application/json" ,text/plain</param-value>
</init-param>
<init-param>
<param-name>filterAction</param-name>
<param-value>enforce</param-value>
</init-param>
<init-param>
<param-name>httpHeaders</param-name>
<param-value>Cache-Control: no-store, no-cache, must-revalidate, private</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~ Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. 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
~ 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
@ -15,6 +15,7 @@
~ 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/xsd/maven-4.0.0.xsd">
@ -35,5 +36,6 @@
<module>io.entgra.device.mgt.core.cea.mgt.core</module>
<module>io.entgra.device.mgt.core.cea.mgt.common</module>
<module>io.entgra.device.mgt.core.cea.mgt.enforce</module>
<module>io.entgra.device.mgt.core.cea.mgt.admin.api</module>
</modules>
</project>

@ -460,10 +460,5 @@
<artifactId>io.entgra.device.mgt.core.apimgt.webapp.publisher</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.cea.mgt.common</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

@ -19,15 +19,6 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServer;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.AccessPolicyWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.CEAPolicyWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.GracePeriodWrapper;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.DefaultAccessPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.EmailOutlookAccessPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.GraceAllowedPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.POPIMAPAccessPolicy;
import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.WebOutlookAccessPolicy;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -922,100 +913,4 @@ public class RequestValidationUtil {
"a higher value than endTimestamp").build());
}
}
/**
* Validate conditional access policy
* @param ceaPolicyWrapper {@link CEAPolicyWrapper}
*/
public static void validateCEAPolicy(CEAPolicyWrapper ceaPolicyWrapper) {
if (ceaPolicyWrapper == null) {
String msg = "CEA policy should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
validateActiveSyncServer(ceaPolicyWrapper.getActiveSyncServerEntries());
validateCEAAccessPolicy(ceaPolicyWrapper.getConditionalAccessPolicyEntries());
validateCEAGracePeriod(ceaPolicyWrapper.getGracePeriodEntries());
}
/**
* Validate active sync server configurations
* @param activeSyncServer {@link ActiveSyncServer}
*/
public static void validateActiveSyncServer(ActiveSyncServer activeSyncServer) {
if (activeSyncServer == null) {
String msg = "Active sync server should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
if (activeSyncServer.getGatewayUrl() == null) {
String msg = "Active sync server url should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
if (activeSyncServer.getKey() == null) {
String msg = "Active sync server type should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
if (activeSyncServer.getClient() == null) {
String msg = "Active sync server username should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
if (activeSyncServer.getSecret() == null) {
String msg = "Active sync server secret should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
}
/**
* Validate conditional access policy configurations
* @param accessPolicyWrapper {@link AccessPolicyWrapper}
*/
public static void validateCEAAccessPolicy(AccessPolicyWrapper accessPolicyWrapper) {
if (accessPolicyWrapper == null) {
String msg = "Access policy should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
try {
Enum.valueOf(DefaultAccessPolicy.class, accessPolicyWrapper.getDefaultAccessPolicy());
Enum.valueOf(WebOutlookAccessPolicy.class, accessPolicyWrapper.getWebOutlookAccessPolicy());
Enum.valueOf(POPIMAPAccessPolicy.class, accessPolicyWrapper.getPOPIMAPAccessPolicy());
for(String value : accessPolicyWrapper.getEmailOutlookAccessPolicy()) {
Enum.valueOf(EmailOutlookAccessPolicy.class, value);
}
} catch (IllegalArgumentException | NullPointerException e) {
String msg = "Access policy contains illegal arguments";
log.error(msg);
throw new BadRequestException(msg);
}
}
/**
* Validate grace period configurations
* @param gracePeriodWrapper {@link GracePeriodWrapper}
*/
public static void validateCEAGracePeriod(GracePeriodWrapper gracePeriodWrapper) {
if (gracePeriodWrapper == null) {
String msg = "Grace period should not be null";
log.error(msg);
throw new BadRequestException(msg);
}
if (gracePeriodWrapper.getGracePeriod() < 0 || gracePeriodWrapper.getGracePeriod() >
io.entgra.device.mgt.core.cea.mgt.common.util.Constants.MAX_GRACE_PERIOD_IN_DAYS) {
String msg = "Grace period should in range of 0-30 days";
log.error(msg);
throw new BadRequestException(msg);
}
try {
Enum.valueOf(GraceAllowedPolicy.class, gracePeriodWrapper.getGraceAllowedPolicy());
} catch (IllegalArgumentException | NullPointerException e) {
String msg = "Grace allowed policy contains illegal arguments";
log.error(msg);
throw new BadRequestException(msg);
}
}
}

@ -22,7 +22,6 @@ import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherService;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.cea.mgt.common.service.CEAManagementService;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.java.security.SSLProtocolSocketFactory;
@ -162,7 +161,6 @@ public class DeviceMgtAPIUtils {
private static volatile ApplicationManager applicationManager;
private static volatile APIPublisherService apiPublisher;
private static volatile CEAManagementService ceaManagementService;
static {
String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password");
@ -1230,20 +1228,4 @@ public class DeviceMgtAPIUtils {
}
return isPermitted;
}
public static CEAManagementService getCEAManagementService() {
if (ceaManagementService == null) {
synchronized (DeviceMgtAPIUtils.class) {
if (ceaManagementService == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ceaManagementService = (CEAManagementService)
ctx.getOSGiService(CEAManagementService.class, null);
if (ceaManagementService == null) {
throw new IllegalStateException("Conditional Email Access Management Service is not initialize");
}
}
}
}
return ceaManagementService;
}
}

@ -51,7 +51,6 @@
<ref bean="metadataService"/>
<ref bean="whitelabelService"/>
<ref bean="deviceStatusFilterService"/>
<ref bean="ceaManagementAdminService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
@ -104,7 +103,6 @@
<bean id="metadataService" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.MetadataServiceImpl"/>
<bean id="whitelabelService" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.WhiteLabelServiceImpl"/>
<bean id="deviceStatusFilterService" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.DeviceStatusFilterServiceImpl"/>
<bean id="ceaManagementAdminService" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.admin.CEAManagementAdminServiceImpl"/>
<!--<bean id="errorHandler" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.common.ErrorHandler"/>-->
<cxf:bus>

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. 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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.40-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.cea.mgt.admin.api.feature</artifactId>
<name>Entgra IoT - CEA Management Admin API Feature</name>
<description>Entgra IoT - Conditional Email Access Management Admin API Feature</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.cea.mgt.admin.api</artifactId>
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>
${project.build.directory}/maven-shared-archive-resources/webapps
</outputDirectory>
<destFileName>api#cea-mgt#v1.0.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/resources</outputDirectory>
<resources>
<resource>
<directory>resources</directory>
<includes>
<include>build.properties</include>
<include>p2.inf</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId>
<executions>
<execution>
<id>p2-feature-generation</id>
<phase>package</phase>
<goals>
<goal>p2-feature-gen</goal>
</goals>
<configuration>
<id>io.entgra.device.mgt.core.cea.mgt.admin.api</id>
<propertiesFile>../../../features/etc/feature.properties
</propertiesFile>
<adviceFile>
<properties>
<propertyDef>org.wso2.carbon.p2.category.type:server
</propertyDef>
<propertyDef>org.eclipse.equinox.p2.type.group:false
</propertyDef>
</properties>
</adviceFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,2 @@
instructions.configure = \
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.device.mgt.core.cea.mgt.admin.api_${feature.version}/webapps/api#cea-mgt#v1.0.war,target:${installFolder}/../../deployment/server/webapps/api#cea-mgt#v1.0.war,overwrite:true);\

@ -23,12 +23,13 @@
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>cea-mgt-feature</artifactId>
<version>5.0.40-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.cea.mgt.server.feature</artifactId>
<name>Entgra IoT - CEA Management Server Feature</name>
<description>Entgra IoT - CEA Management Server Feature</description>
<description>Entgra IoT - Conditional Email Access Management Server Feature</description>
<dependencies>
<dependency>

@ -33,5 +33,6 @@
<modules>
<module>io.entgra.device.mgt.core.cea.mgt.server.feature</module>
<module>io.entgra.device.mgt.core.cea.mgt.admin.api.feature</module>
</modules>
</project>
Loading…
Cancel
Save