diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/pom.xml b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/pom.xml
new file mode 100644
index 0000000000..4f6fcd9a54
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/pom.xml
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+ io.entgra.device.mgt.core
+ cea-mgt
+ 5.0.38-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ io.entgra.device.mgt.core.cea.mgt.common
+ bundle
+ Entgra IoT - CEA Management Common
+ Entgra IoT - Conditional Email Access Management Common
+
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${io.entgra.device.mgt.core.version}
+ CEA Management Common Bundle
+
+ org.apache.commons.logging,
+ io.entgra.device.mgt.core.device.mgt.common.*
+
+
+ io.entgra.device.mgt.core.cea.mgt.common.*
+
+
+
+
+
+
+
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.device.mgt.common
+
+
+ io.swagger
+ swagger-annotations
+
+
+
\ No newline at end of file
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/AccessPolicy.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/AccessPolicy.java
new file mode 100644
index 0000000000..a874557092
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/AccessPolicy.java
@@ -0,0 +1,66 @@
+/*
+ * 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.common.bean;
+
+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.POPIMAPAccessPolicy;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.WebOutlookAccessPolicy;
+
+import java.util.Set;
+
+public class AccessPolicy {
+ private DefaultAccessPolicy defaultAccessPolicy;
+ private Set emailOutlookAccessPolicy;
+ private POPIMAPAccessPolicy POPIMAPAccessPolicy;
+ private WebOutlookAccessPolicy webOutlookAccessPolicy;
+
+ public DefaultAccessPolicy getDefaultAccessPolicy() {
+ return defaultAccessPolicy;
+ }
+
+ public void setDefaultAccessPolicy(DefaultAccessPolicy defaultAccessPolicy) {
+ this.defaultAccessPolicy = defaultAccessPolicy;
+ }
+
+ public Set getEmailOutlookAccessPolicy() {
+ return emailOutlookAccessPolicy;
+ }
+
+ public void setEmailOutlookAccessPolicy(Set emailOutlookAccessPolicy) {
+ this.emailOutlookAccessPolicy = emailOutlookAccessPolicy;
+ }
+
+ public POPIMAPAccessPolicy getPOPIMAPAccessPolicy() {
+ return POPIMAPAccessPolicy;
+ }
+
+ public void setPOPIMAPAccessPolicy(POPIMAPAccessPolicy POPIMAPAccessPolicy) {
+ this.POPIMAPAccessPolicy = POPIMAPAccessPolicy;
+ }
+
+ public WebOutlookAccessPolicy getWebOutlookAccessPolicy() {
+ return webOutlookAccessPolicy;
+ }
+
+ public void setWebOutlookAccessPolicy(WebOutlookAccessPolicy webOutlookAccessPolicy) {
+ this.webOutlookAccessPolicy = webOutlookAccessPolicy;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ActiveSyncDevice.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ActiveSyncDevice.java
new file mode 100644
index 0000000000..12c8987e09
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ActiveSyncDevice.java
@@ -0,0 +1,84 @@
+/*
+ * 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.common.bean;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Date;
+import java.util.Objects;
+
+public class ActiveSyncDevice {
+ @JsonProperty(value = "DeviceID", required = true)
+ private String deviceId;
+ @JsonProperty(value = "FirstSyncTime", required = true)
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
+ private Date firstSyncTime;
+ @JsonProperty(value = "UserPrincipalName", required = true)
+ private String userPrincipalName;
+ @JsonProperty(value = "Identity", required = true)
+ private String identity;
+
+ public String getDeviceId() {
+ return deviceId;
+ }
+
+ public void setDeviceId(String deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ public Date getFirstSyncTime() {
+ return firstSyncTime;
+ }
+
+ public void setFirstSyncTime(Date firstSyncTime) {
+ this.firstSyncTime = firstSyncTime;
+ }
+
+ public String getIdentity() {
+ return identity;
+ }
+
+ public void setIdentity(String identity) {
+ this.identity = identity;
+ }
+
+ public String getUserPrincipalName() {
+ return userPrincipalName;
+ }
+
+ public void setUserPrincipalName(String userPrincipalName) {
+ this.userPrincipalName = userPrincipalName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ActiveSyncDevice)) return false;
+ ActiveSyncDevice that = (ActiveSyncDevice) o;
+ return Objects.equals(deviceId, that.deviceId)
+ && Objects.equals(userPrincipalName, that.userPrincipalName);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(deviceId, userPrincipalName, identity);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ActiveSyncServer.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ActiveSyncServer.java
new file mode 100644
index 0000000000..b4045b4f02
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ActiveSyncServer.java
@@ -0,0 +1,74 @@
+/*
+ * 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.common.bean;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(value = "ActiveSyncServer", description = "Active sync server properties")
+public class ActiveSyncServer {
+ @JsonProperty(value = "key", required = true)
+ @ApiModelProperty(name = "key", value = "Key describing the server type according to cea-config.xml", required = true)
+ private String key;
+
+ @JsonProperty(value = "gatewayUrl", required = true)
+ @ApiModelProperty(name = "gatewayUrl", value = "Gateway URL of the active sync server", required = true)
+ private String gatewayUrl;
+
+ @JsonProperty(value = "client", required = true)
+ @ApiModelProperty(name = "client", value = "Client identifier", required = true)
+ private String client;
+ @JsonProperty(value = "secret", required = true)
+ @ApiModelProperty(name = "secret", value = "Client secret", required = true)
+ private String secret;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getGatewayUrl() {
+ return gatewayUrl;
+ }
+
+ public void setGatewayUrl(String gatewayUrl) {
+ this.gatewayUrl = gatewayUrl;
+ }
+
+ public String getClient() {
+ return client;
+ }
+
+ public void setClient(String client) {
+ this.client = client;
+ }
+
+ public String getSecret() {
+ return secret;
+ }
+
+ public void setSecret(String secret) {
+ this.secret = secret;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ActiveSyncServerUIConfiguration.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ActiveSyncServerUIConfiguration.java
new file mode 100644
index 0000000000..7db46e5d28
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ActiveSyncServerUIConfiguration.java
@@ -0,0 +1,50 @@
+/*
+ * 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.common.bean;
+
+public class ActiveSyncServerUIConfiguration {
+ private String name;
+ private String description;
+ private String key;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/AndroidEASIdentifier.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/AndroidEASIdentifier.java
new file mode 100644
index 0000000000..e38b43cbf9
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/AndroidEASIdentifier.java
@@ -0,0 +1,32 @@
+/*
+ * 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.common.bean;
+
+public class AndroidEASIdentifier {
+ private String identifier;
+
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/CEAPolicy.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/CEAPolicy.java
new file mode 100644
index 0000000000..33ed04f2c5
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/CEAPolicy.java
@@ -0,0 +1,99 @@
+/*
+ * 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.common.bean;
+
+import java.io.Serializable;
+import java.util.Date;
+
+public class CEAPolicy implements Serializable {
+ private static final long serialVersionUID = -4578284769501447L;
+ private ActiveSyncServer activeSyncServer;
+ private AccessPolicy accessPolicy;
+ private GracePeriod gracePeriod;
+ private Date created;
+ private Date lastUpdated;
+ private Date lastSynced;
+ private boolean isSynced;
+ private int tenantId;
+
+ public boolean isSynced() {
+ return isSynced;
+ }
+
+ public void setSynced(boolean synced) {
+ isSynced = synced;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public void setCreated(Date created) {
+ this.created = created;
+ }
+
+ public Date getLastUpdated() {
+ return lastUpdated;
+ }
+
+ public void setLastUpdated(Date lastUpdated) {
+ this.lastUpdated = lastUpdated;
+ }
+
+ public Date getLastSynced() {
+ return lastSynced;
+ }
+
+ public void setLastSynced(Date lastSynced) {
+ this.lastSynced = lastSynced;
+ }
+
+ public AccessPolicy getAccessPolicy() {
+ return accessPolicy;
+ }
+
+ public void setAccessPolicy(AccessPolicy accessPolicy) {
+ this.accessPolicy = accessPolicy;
+ }
+
+ public GracePeriod getGracePeriod() {
+ return gracePeriod;
+ }
+
+ public void setGracePeriod(GracePeriod gracePeriod) {
+ this.gracePeriod = gracePeriod;
+ }
+
+ public ActiveSyncServer getActiveSyncServer() {
+ return activeSyncServer;
+ }
+
+ public void setActiveSyncServer(ActiveSyncServer activeSyncServer) {
+ this.activeSyncServer = activeSyncServer;
+ }
+
+ public int getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(int tenantId) {
+ this.tenantId = tenantId;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/CEAPolicyEASWrapper.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/CEAPolicyEASWrapper.java
new file mode 100644
index 0000000000..b898ac6cbc
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/CEAPolicyEASWrapper.java
@@ -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.common.bean;
+
+import java.util.List;
+
+public class CEAPolicyEASWrapper {
+ private List activeSyncDevices;
+ private CEAPolicy ceaPolicy;
+
+ public List getActiveSyncDevices() {
+ return activeSyncDevices;
+ }
+
+ public void setActiveSyncDevices(List activeSyncDevices) {
+ this.activeSyncDevices = activeSyncDevices;
+ }
+
+ public CEAPolicy getCeaPolicy() {
+ return ceaPolicy;
+ }
+
+ public void setCeaPolicy(CEAPolicy ceaPolicy) {
+ this.ceaPolicy = ceaPolicy;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/GracePeriod.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/GracePeriod.java
new file mode 100644
index 0000000000..51f44fff74
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/GracePeriod.java
@@ -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.common.bean;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.enums.GraceAllowedPolicy;
+
+public class GracePeriod {
+ private int gracePeriod;
+ private GraceAllowedPolicy graceAllowedPolicy;
+
+ public int getGracePeriod() {
+ return gracePeriod;
+ }
+
+ public void setGracePeriod(int gracePeriod) {
+ this.gracePeriod = gracePeriod;
+ }
+
+ public GraceAllowedPolicy getGraceAllowedPolicy() {
+ return graceAllowedPolicy;
+ }
+
+ public void setGraceAllowedPolicy(GraceAllowedPolicy graceAllowedPolicy) {
+ this.graceAllowedPolicy = graceAllowedPolicy;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/MailboxProfile.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/MailboxProfile.java
new file mode 100644
index 0000000000..e172009ea1
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/MailboxProfile.java
@@ -0,0 +1,123 @@
+/*
+ * 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.common.bean;
+
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+
+public class MailboxProfile {
+ private final Set activeSyncAllowedEASIdentifiers = new HashSet<>();
+ private final Set activeSyncBlockedEASIdentifiers = new HashSet<>();
+ private String identity;
+
+ public Set getActiveSyncAllowedEASIdentifiers() {
+ return activeSyncAllowedEASIdentifiers;
+ }
+
+ public Set getActiveSyncBlockedEASIdentifiers() {
+ return activeSyncBlockedEASIdentifiers;
+ }
+
+ public void addActiveSyncAllowedEASIdentifier(String EASIdentifier) {
+ activeSyncAllowedEASIdentifiers.add(EASIdentifier);
+ }
+
+ public void addActiveSyncBlockEASIdentifier(String EASIdentifier) {
+ activeSyncBlockedEASIdentifiers.add(EASIdentifier);
+ }
+
+ public String getIdentity() {
+ return identity;
+ }
+
+ public void setIdentity(String identity) {
+ this.identity = identity;
+ }
+
+ public String getAllowedEASIdentifierString() {
+ String add = "", remove = "";
+ if (!activeSyncAllowedEASIdentifiers.isEmpty()) {
+ Set processedEASIdentifiers = new HashSet<>();
+ for (String activeSyncAllowedEASIdentifier : activeSyncAllowedEASIdentifiers) {
+ processedEASIdentifiers.add("'" + activeSyncAllowedEASIdentifier + "'");
+ }
+ add = String.join(",", processedEASIdentifiers);
+ }
+
+ if (!activeSyncBlockedEASIdentifiers.isEmpty()) {
+ Set processedEASIdentifiers = new HashSet<>();
+ for (String activeSyncBlockedEASIdentifier : activeSyncBlockedEASIdentifiers) {
+ processedEASIdentifiers.add("'" + activeSyncBlockedEASIdentifier + "'");
+ }
+ remove = String.join(",", processedEASIdentifiers);
+ }
+
+ String begin = "@{", end = "}";
+ if (!add.isEmpty()) {
+ begin = begin + "Add=" + add + ";";
+ }
+ if (!remove.isEmpty()) {
+ begin = begin + "Remove=" + remove + ";";
+ }
+ return begin + end;
+ }
+
+ public String getBlockedEASIdentifierString() {
+ String add = "", remove = "";
+ if (!activeSyncAllowedEASIdentifiers.isEmpty()) {
+ Set processedEASIdentifiers = new HashSet<>();
+ for (String activeSyncAllowedEASIdentifier : activeSyncAllowedEASIdentifiers) {
+ processedEASIdentifiers.add("'" + activeSyncAllowedEASIdentifier + "'");
+ }
+ remove = String.join(",", processedEASIdentifiers);
+ }
+
+ if (!activeSyncBlockedEASIdentifiers.isEmpty()) {
+ Set processedEASIdentifiers = new HashSet<>();
+ for (String activeSyncBlockedEASIdentifier : activeSyncBlockedEASIdentifiers) {
+ processedEASIdentifiers.add("'" + activeSyncBlockedEASIdentifier + "'");
+ }
+ add = String.join(",", processedEASIdentifiers);
+ }
+
+ String begin = "@{", end = "}";
+ if (!add.isEmpty()) {
+ begin = begin + "Add=" + add + ";";
+ }
+ if (!remove.isEmpty()) {
+ begin = begin + "Remove=" + remove + ";";
+ }
+ return begin + end;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof MailboxProfile)) return false;
+ MailboxProfile that = (MailboxProfile) o;
+ return Objects.equals(identity, that.identity);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(identity);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/DefaultAccessPolicy.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/DefaultAccessPolicy.java
new file mode 100644
index 0000000000..d3a6f8a9f6
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/DefaultAccessPolicy.java
@@ -0,0 +1,40 @@
+/*
+ * 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.common.bean.enums;
+
+public enum DefaultAccessPolicy {
+ ALLOW("ALLOW"),
+ QUARANTINE("QUARANTINE"),
+ BLOCK("BLOCK");
+
+ private final String name;
+
+ DefaultAccessPolicy(String name) {
+ this.name = name;
+ }
+
+ public boolean equalsName(String thatName) {
+ return name.equals(thatName);
+ }
+
+ public String toString() {
+ return name;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/EmailOutlookAccessPolicy.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/EmailOutlookAccessPolicy.java
new file mode 100644
index 0000000000..a9ffb1c88e
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/EmailOutlookAccessPolicy.java
@@ -0,0 +1,42 @@
+/*
+ * 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.common.bean.enums;
+
+public enum EmailOutlookAccessPolicy {
+ MOBILE_OUTLOOK_BLOCK("MOBILE_OUTLOOK_BLOCK"),
+ WINDOWS_OUTLOOK_BLOCK("WINDOWS_OUTLOOK_BLOCK"),
+ MAC_OUTLOOK_BLOCK("MAC_OUTLOOK_BLOCK"),
+ MAC_OLD_OUTLOOK_BLOCK("MAC_OLD_OUTLOOK_BLOCK"),
+ NOT_CONFIGURED("NOT_CONFIGURED");
+
+ private final String name;
+
+ EmailOutlookAccessPolicy(String name) {
+ this.name = name;
+ }
+
+ public boolean equalsName(String thatName) {
+ return name.equals(thatName);
+ }
+
+ public String toString() {
+ return name;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/GraceAllowedPolicy.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/GraceAllowedPolicy.java
new file mode 100644
index 0000000000..dbcb9668df
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/GraceAllowedPolicy.java
@@ -0,0 +1,41 @@
+/*
+ * 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.common.bean.enums;
+
+public enum GraceAllowedPolicy {
+ NEW_AND_EXISTING("NEW_AND_EXISTING"),
+ EXISTING_ONLY("EXISTING_ONLY"),
+ NEW_ONLY("NEW_ONLY"),
+ NOT_ALLOWED("NOT_ALLOWED");
+
+ private final String name;
+
+ GraceAllowedPolicy(String name) {
+ this.name = name;
+ }
+
+ public boolean equalsName(String thatName) {
+ return name.equals(thatName);
+ }
+
+ public String toString() {
+ return name;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/POPIMAPAccessPolicy.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/POPIMAPAccessPolicy.java
new file mode 100644
index 0000000000..9847c1155a
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/POPIMAPAccessPolicy.java
@@ -0,0 +1,40 @@
+/*
+ * 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.common.bean.enums;
+
+public enum POPIMAPAccessPolicy {
+ ALLOW("ALLOW"),
+ BLOCK("BLOCK"),
+ NOT_CONFIGURED("NOT_CONFIGURED");
+
+ private final String name;
+
+ POPIMAPAccessPolicy(String name) {
+ this.name = name;
+ }
+
+ public boolean equalsName(String thatName) {
+ return name.equals(thatName);
+ }
+
+ public String toString() {
+ return name;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/WebOutlookAccessPolicy.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/WebOutlookAccessPolicy.java
new file mode 100644
index 0000000000..660afe6d0d
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/enums/WebOutlookAccessPolicy.java
@@ -0,0 +1,40 @@
+/*
+ * 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.common.bean.enums;
+
+public enum WebOutlookAccessPolicy {
+ ALLOW("ALLOW"),
+ BLOCK("BLOCK"),
+ NOT_CONFIGURED("NOT_CONFIGURED");
+
+ private final String name;
+
+ WebOutlookAccessPolicy(String name) {
+ this.name = name;
+ }
+
+ public boolean equalsName(String thatName) {
+ return name.equals(thatName);
+ }
+
+ public String toString() {
+ return name;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/CEAPolicyUIConfiguration.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/CEAPolicyUIConfiguration.java
new file mode 100644
index 0000000000..84f35b1fdf
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/CEAPolicyUIConfiguration.java
@@ -0,0 +1,40 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+@XmlRootElement(name = "CEAPolicyUIConfiguration")
+public class CEAPolicyUIConfiguration {
+ private List serverUIConfigurations;
+
+ public List getServerConfigurations() {
+ return serverUIConfigurations;
+ }
+
+ @XmlElementWrapper(name = "ServerUIConfigurations", required = true)
+ @XmlElement(name = "ServerUIConfiguration")
+ public void setServerConfigurations(List serverUIConfigurations) {
+ this.serverUIConfigurations = serverUIConfigurations;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Checkbox.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Checkbox.java
new file mode 100644
index 0000000000..111fbd9427
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Checkbox.java
@@ -0,0 +1,47 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Checkbox")
+public class Checkbox {
+ private String label;
+ private String value;
+
+ public String getLabel() {
+ return label;
+ }
+
+ @XmlElement(name = "Label", required = true)
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ @XmlElement(name = "Value", required = true)
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/CheckboxGroup.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/CheckboxGroup.java
new file mode 100644
index 0000000000..478ccc6f01
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/CheckboxGroup.java
@@ -0,0 +1,50 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+@XmlRootElement(name = "CheckboxGroup")
+public class CheckboxGroup {
+ private String name;
+ private List checkboxes;
+
+ public String getName() {
+ return name;
+ }
+
+ @XmlElement(name = "Name", required = true)
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List getCheckboxes() {
+ return checkboxes;
+ }
+
+ @XmlElementWrapper(name = "Checkboxes", required = true)
+ @XmlElement(name = "Checkbox")
+ public void setCheckboxes(List checkboxes) {
+ this.checkboxes = checkboxes;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Entry.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Entry.java
new file mode 100644
index 0000000000..d9ef169086
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Entry.java
@@ -0,0 +1,137 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Entry")
+public class Entry {
+ private String code;
+ private boolean required;
+ private String label;
+ private String tooltip;
+ private boolean hidden;
+ private Supportability supportability;
+ private String docLink;
+ private Input input;
+ private Select select;
+ private CheckboxGroup checkboxGroup;
+ private Switch inputSwitch;
+
+ public String getCode() {
+ return code;
+ }
+
+ @XmlElement(name = "Code", required = true)
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ @XmlElement(name = "Required", defaultValue = "false")
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ @XmlElement(name = "Label", required = true)
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getTooltip() {
+ return tooltip;
+ }
+
+ @XmlElement(name = "Tooltip")
+ public void setTooltip(String tooltip) {
+ this.tooltip = tooltip;
+ }
+
+ public boolean isHidden() {
+ return hidden;
+ }
+
+ @XmlElement(name = "Hidden", defaultValue = "false")
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+
+ public Supportability getSupportability() {
+ return supportability;
+ }
+
+ @XmlElement(name = "Supportability")
+ public void setSupportability(Supportability supportability) {
+ this.supportability = supportability;
+ }
+
+ public String getDocLink() {
+ return docLink;
+ }
+
+ @XmlElement(name = "DocLink")
+ public void setDocLink(String docLink) {
+ this.docLink = docLink;
+ }
+
+ public Input getInput() {
+ return input;
+ }
+
+ @XmlElement(name = "Input", nillable = true)
+ public void setInput(Input input) {
+ this.input = input;
+ }
+
+ public Select getSelect() {
+ return select;
+ }
+
+ @XmlElement(name = "Select", nillable = true)
+ public void setSelect(Select select) {
+ this.select = select;
+ }
+
+ public CheckboxGroup getCheckboxGroup() {
+ return checkboxGroup;
+ }
+
+ @XmlElement(name = "CheckboxGroup", nillable = true)
+ public void setCheckboxGroup(CheckboxGroup checkboxGroup) {
+ this.checkboxGroup = checkboxGroup;
+ }
+
+ public Switch getInputSwitch() {
+ return inputSwitch;
+ }
+
+ @XmlElement(name = "Switch", nillable = true)
+ public void setInputSwitch(Switch inputSwitch) {
+ this.inputSwitch = inputSwitch;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Input.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Input.java
new file mode 100644
index 0000000000..52c6b30d75
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Input.java
@@ -0,0 +1,57 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Input")
+public class Input {
+ private String name;
+ private String placeholder;
+ private String type;
+
+ public String getName() {
+ return name;
+ }
+
+ @XmlElement(name = "Name", required = true)
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPlaceholder() {
+ return placeholder;
+ }
+
+ @XmlElement(name = "Placeholder", required = true)
+ public void setPlaceholder(String placeholder) {
+ this.placeholder = placeholder;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ @XmlElement(name = "Type", required = true)
+ public void setType(String type) {
+ this.type = type;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Option.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Option.java
new file mode 100644
index 0000000000..41e5b14a27
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Option.java
@@ -0,0 +1,47 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Option")
+public class Option {
+ private String value;
+ private String label;
+
+ public String getValue() {
+ return value;
+ }
+
+ @XmlElement(name = "Value", required = true)
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ @XmlElement(name = "Label", required = true)
+ public void setLabel(String label) {
+ this.label = label;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/PolicyEntries.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/PolicyEntries.java
new file mode 100644
index 0000000000..a631559ee4
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/PolicyEntries.java
@@ -0,0 +1,62 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+@XmlRootElement(name = "PolicyEntries")
+public class PolicyEntries {
+ private List activeSyncServerEntries;
+ private List conditionalAccessPolicyEntries;
+ private List gracePeriodEntries;
+
+ public List getActiveSyncServerEntries() {
+ return activeSyncServerEntries;
+ }
+
+ @XmlElementWrapper(name = "ActiveSyncServerEntries", required = true)
+ @XmlElement(name = "Entry", required = true)
+ public void setActiveSyncServerEntries(List activeSyncServerEntries) {
+ this.activeSyncServerEntries = activeSyncServerEntries;
+ }
+
+ public List getConditionalAccessPolicyEntries() {
+ return conditionalAccessPolicyEntries;
+ }
+
+ @XmlElementWrapper(name = "ConditionalAccessPolicyEntries", required = true)
+ @XmlElement(name = "Entry", required = true)
+ public void setConditionalAccessPolicyEntries(List conditionalAccessPolicyEntries) {
+ this.conditionalAccessPolicyEntries = conditionalAccessPolicyEntries;
+ }
+
+ public List getGracePeriodEntries() {
+ return gracePeriodEntries;
+ }
+
+ @XmlElementWrapper(name = "GracePeriodEntries", required = true)
+ @XmlElement(name = "Entry", required = true)
+ public void setGracePeriodEntries(List gracePeriodEntries) {
+ this.gracePeriodEntries = gracePeriodEntries;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Select.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Select.java
new file mode 100644
index 0000000000..e51bc4202a
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Select.java
@@ -0,0 +1,60 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+@XmlRootElement(name = "Select")
+public class Select {
+ private String name;
+ private String placeholder;
+ private List options;
+
+ public String getPlaceholder() {
+ return placeholder;
+ }
+
+ @XmlElement(name = "Placeholder", required = true)
+ public void setPlaceholder(String placeholder) {
+ this.placeholder = placeholder;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @XmlElement(name = "Name", required = true)
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List getOptions() {
+ return options;
+ }
+
+ @XmlElementWrapper(name = "Options", required = true)
+ @XmlElement(name = "Option")
+ public void setOptions(List options) {
+ this.options = options;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/ServerUIConfiguration.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/ServerUIConfiguration.java
new file mode 100644
index 0000000000..5b8e83c5dd
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/ServerUIConfiguration.java
@@ -0,0 +1,67 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "ServerUIConfiguration")
+public class ServerUIConfiguration {
+ private String name;
+ private String key;
+ private String description;
+ private PolicyEntries policyEntries;
+
+ public String getName() {
+ return name;
+ }
+
+ @XmlElement(name = "Name", required = true)
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ @XmlElement(name = "Key", required = true)
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ @XmlElement(name = "Description")
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public PolicyEntries getPolicyEntries() {
+ return policyEntries;
+ }
+
+ @XmlElement(name = "PolicyEntries")
+ public void setPolicyEntries(PolicyEntries policyEntries) {
+ this.policyEntries = policyEntries;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Supportability.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Supportability.java
new file mode 100644
index 0000000000..04ec3a0350
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Supportability.java
@@ -0,0 +1,57 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Supportability")
+public class Supportability {
+ private boolean support;
+ private String infoText;
+ private String defaultValue;
+
+ public boolean isSupport() {
+ return support;
+ }
+
+ @XmlElement(name = "Support", defaultValue = "true")
+ public void setSupport(boolean support) {
+ this.support = support;
+ }
+
+ public String getInfoText() {
+ return infoText;
+ }
+
+ @XmlElement(name = "InfoText")
+ public void setInfoText(String infoText) {
+ this.infoText = infoText;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ @XmlElement(name = "DefaultValue")
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Switch.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Switch.java
new file mode 100644
index 0000000000..bf9396c3ae
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Switch.java
@@ -0,0 +1,47 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Switch")
+public class Switch {
+ private String name;
+ private Toggle toggle;
+
+ public String getName() {
+ return name;
+ }
+
+ @XmlElement(name = "Name", required = true)
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Toggle getToggle() {
+ return toggle;
+ }
+
+ @XmlElement(name = "Toggle", required = true)
+ public void setToggle(Toggle toggle) {
+ this.toggle = toggle;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Toggle.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Toggle.java
new file mode 100644
index 0000000000..4d5e7d85ff
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/bean/ui/Toggle.java
@@ -0,0 +1,67 @@
+/*
+ * 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.common.bean.ui;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Toggle")
+public class Toggle {
+ private String toggleOnValue;
+ private String toggleOffValue;
+ private String toggleOnLabel;
+ private String toggleOffLabel;
+
+ public String getToggleOnValue() {
+ return toggleOnValue;
+ }
+
+ @XmlElement(name = "ToggleOnValue", required = true)
+ public void setToggleOnValue(String toggleOnValue) {
+ this.toggleOnValue = toggleOnValue;
+ }
+
+ public String getToggleOffValue() {
+ return toggleOffValue;
+ }
+
+ @XmlElement(name = "ToggleOffValue", required = true)
+ public void setToggleOffValue(String toggleOffValue) {
+ this.toggleOffValue = toggleOffValue;
+ }
+
+ public String getToggleOnLabel() {
+ return toggleOnLabel;
+ }
+
+ @XmlElement(name = "ToggleOnLabel", required = true)
+ public void setToggleOnLabel(String toggleOnLabel) {
+ this.toggleOnLabel = toggleOnLabel;
+ }
+
+ public String getToggleOffLabel() {
+ return toggleOffLabel;
+ }
+
+ @XmlElement(name = "ToggleOffLabel", required = true)
+ public void setToggleOffLabel(String toggleOffLabel) {
+ this.toggleOffLabel = toggleOffLabel;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAConfigManagerException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAConfigManagerException.java
new file mode 100644
index 0000000000..1e008ae31f
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAConfigManagerException.java
@@ -0,0 +1,31 @@
+/*
+ * 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.common.exception;
+
+public class CEAConfigManagerException extends Exception {
+ public CEAConfigManagerException(String msg) {
+ super(msg);
+ }
+
+ public CEAConfigManagerException(String msg, Throwable t) {
+ super(msg, t);
+ }
+
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAEnforcementException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAEnforcementException.java
new file mode 100644
index 0000000000..3e8de12339
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAEnforcementException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.common.exception;
+
+public class CEAEnforcementException extends Exception {
+ public CEAEnforcementException(String msg) {
+ super(msg);
+ }
+
+ public CEAEnforcementException(String msg, Throwable t) {
+ super(msg, t);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAManagementException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAManagementException.java
new file mode 100644
index 0000000000..69e0a14501
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAManagementException.java
@@ -0,0 +1,34 @@
+/*
+ * 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.common.exception;
+
+public class CEAManagementException extends Exception {
+ public CEAManagementException(String msg) {
+ super(msg);
+ }
+
+ public CEAManagementException(String msg, Throwable t) {
+ super(msg, t);
+ }
+
+ public CEAManagementException() {
+ super();
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAPolicyAlreadyExistsException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAPolicyAlreadyExistsException.java
new file mode 100644
index 0000000000..15dcc7b827
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAPolicyAlreadyExistsException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.common.exception;
+
+public class CEAPolicyAlreadyExistsException extends Exception {
+ public CEAPolicyAlreadyExistsException(String msg) {
+ super(msg);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAPolicyNotFoundException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAPolicyNotFoundException.java
new file mode 100644
index 0000000000..ce605c0d7e
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/CEAPolicyNotFoundException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.common.exception;
+
+public class CEAPolicyNotFoundException extends Exception {
+ public CEAPolicyNotFoundException(String msg) {
+ super(msg);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/EnforcementServiceManagerException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/EnforcementServiceManagerException.java
new file mode 100644
index 0000000000..3524578536
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/exception/EnforcementServiceManagerException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.common.exception;
+
+public class EnforcementServiceManagerException extends Exception {
+ public EnforcementServiceManagerException(String msg) {
+ super(msg);
+ }
+
+ public EnforcementServiceManagerException(String msg, Throwable t) {
+ super(msg, t);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/service/CEAEnforcementService.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/service/CEAEnforcementService.java
new file mode 100644
index 0000000000..45fd55789d
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/service/CEAEnforcementService.java
@@ -0,0 +1,65 @@
+/*
+ * 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.common.service;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.CEAPolicy;
+import io.entgra.device.mgt.core.cea.mgt.common.exception.CEAEnforcementException;
+
+public interface CEAEnforcementService {
+ /**
+ * Sync default access policy with active sync server
+ *
+ * @param ceaPolicy {@link CEAPolicy}
+ * @throws CEAEnforcementException Throws when error occurred while enforcing the policy
+ */
+ void enforceDefaultAccessPolicy(CEAPolicy ceaPolicy) throws CEAEnforcementException;
+
+ /**
+ * Enforce email outlook access policy
+ *
+ * @param ceaPolicy {@link CEAPolicy}
+ * @throws CEAEnforcementException Throws when error occurred while enforcing the policy
+ */
+ void enforceEmailOutlookAccessPolicy(CEAPolicy ceaPolicy) throws CEAEnforcementException;
+
+ /**
+ * Enforce POP/IMAP access policy
+ *
+ * @param ceaPolicy {@link CEAPolicy}
+ * @throws CEAEnforcementException Throws when error occurred while enforcing the policy
+ */
+ void enforcePOPIMAPAccessPolicy(CEAPolicy ceaPolicy) throws CEAEnforcementException;
+
+ /**
+ * Enforce web outlook access policy
+ *
+ * @param ceaPolicy {@link CEAPolicy}
+ * @throws CEAEnforcementException Throws when error occurred while enforcing the policy
+ */
+ void enforceWebOutlookAccessPolicy(CEAPolicy ceaPolicy) throws CEAEnforcementException;
+
+ /**
+ * Enforce conditional email access policy honoring to the grace period
+ *
+ * @param ceaPolicy {@link CEAPolicy}
+ * @throws CEAEnforcementException Throws when error occurred while enforcing the policy
+ */
+ void enforceConditionalAccessPolicy(CEAPolicy ceaPolicy) throws CEAEnforcementException;
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/service/CEAManagementService.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/service/CEAManagementService.java
new file mode 100644
index 0000000000..8f599de1be
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/service/CEAManagementService.java
@@ -0,0 +1,79 @@
+/*
+ * 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.common.service;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.CEAPolicy;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ui.CEAPolicyUIConfiguration;
+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;
+
+public interface CEAManagementService {
+ /**
+ * Retrieve conditional access policy UI configuration
+ *
+ * @return {@link CEAPolicyUIConfiguration}
+ * @throws CEAManagementException Throws when retrieving UI configurations
+ */
+ CEAPolicyUIConfiguration getCEAPolicyUIConfiguration() throws CEAManagementException;
+
+ /**
+ * Create conditional access policy
+ *
+ * @param ceaPolicy {@link CEAPolicy}
+ * @return {@link CEAPolicy} Created conditional access policy
+ * @throws CEAManagementException Throws when error occurred while creating the policy
+ * @throws CEAPolicyAlreadyExistsException Throws when conflict occurs
+ */
+ CEAPolicy createCEAPolicy(CEAPolicy ceaPolicy) throws CEAManagementException, CEAPolicyAlreadyExistsException;
+
+ /**
+ * Retrieve conditional access policy for the tenant
+ *
+ * @return {@link CEAPolicy}
+ * @throws CEAManagementException Throws when error occurred while retrieving the policy
+ */
+ CEAPolicy retrieveCEAPolicy() throws CEAManagementException;
+
+ /**
+ * Update conditional access policy
+ *
+ * @param ceaPolicy {@link CEAPolicy}
+ * @return {@link CEAPolicy} Returns update conditional access policy
+ * @throws CEAManagementException Throws when error occurred while updating the policy
+ * @throws CEAPolicyNotFoundException Throws when policy doesn't exist
+ */
+ CEAPolicy updateCEAPolicy(CEAPolicy ceaPolicy) throws CEAManagementException, CEAPolicyNotFoundException;
+
+ /**
+ * Delete the conditional access policy
+ *
+ * @throws CEAManagementException Throws when error occurred while deleting the policy
+ * @throws CEAPolicyNotFoundException Throws when a conditional access policy doesn't exist
+ */
+ void deleteCEAPolicy() throws CEAManagementException, CEAPolicyNotFoundException;
+
+ /**
+ * Trigger sync task with active sync server
+ *
+ * @throws CEAManagementException Throws when error occurred while triggering the sync operation
+ */
+ void syncNow() throws CEAManagementException;
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/service/EnforcementServiceManager.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/service/EnforcementServiceManager.java
new file mode 100644
index 0000000000..f8df784517
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/service/EnforcementServiceManager.java
@@ -0,0 +1,34 @@
+/*
+ * 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.common.service;
+
+import io.entgra.device.mgt.core.cea.mgt.common.exception.EnforcementServiceManagerException;
+
+public interface EnforcementServiceManager {
+ /**
+ * Return enforcement service implementation for the specified enforcement service class name
+ *
+ * @param enforcementServiceClassName Enforcement service class name
+ * @return Return enforcement service implementation
+ * @throws EnforcementServiceManagerException Throws when error occurred while generating enforcement service
+ */
+ CEAEnforcementService getEnforcementService(String enforcementServiceClassName)
+ throws EnforcementServiceManagerException;
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/util/Constants.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/util/Constants.java
new file mode 100644
index 0000000000..8f427bb561
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/util/Constants.java
@@ -0,0 +1,25 @@
+/*
+ * 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.common.util;
+
+public class Constants {
+ public static final String EAS_KEY = "ENTGRA";
+ public static final int MAX_GRACE_PERIOD_IN_DAYS = 30;
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/util/EASMgtUtil.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/util/EASMgtUtil.java
new file mode 100644
index 0000000000..5778fbd1b0
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/src/main/java/io/entgra/device/mgt/core/cea/mgt/common/util/EASMgtUtil.java
@@ -0,0 +1,42 @@
+/*
+ * 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.common.util;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.AndroidEASIdentifier;
+
+public class EASMgtUtil {
+ public static AndroidEASIdentifier generateAndroidEASIdentifier(String androidId) {
+ AndroidEASIdentifier androidEASIdentifier = new AndroidEASIdentifier();
+ androidEASIdentifier.setIdentifier((Constants.EAS_KEY + androidId).toUpperCase());
+ return androidEASIdentifier;
+ }
+
+ public static boolean isManageByUEM(AndroidEASIdentifier androidEASIdentifier) {
+ if (androidEASIdentifier == null)
+ throw new IllegalArgumentException("Null retrieved for Android EAS Identifier");
+ return androidEASIdentifier.getIdentifier().startsWith(Constants.EAS_KEY);
+ }
+
+ public static boolean isManageByUEM(String androidEASIdentifier) {
+ if (androidEASIdentifier == null)
+ throw new IllegalArgumentException("Null retrieved for Android EAS Identifier");
+ return androidEASIdentifier.startsWith(Constants.EAS_KEY);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/pom.xml b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/pom.xml
new file mode 100644
index 0000000000..1e92faa7b2
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/pom.xml
@@ -0,0 +1,115 @@
+
+
+
+
+
+ io.entgra.device.mgt.core
+ cea-mgt
+ 5.0.38-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ io.entgra.device.mgt.core.cea.mgt.core
+ bundle
+ Entgra IoT - CEA Management Core
+ Entgra IoT - Conditional Email Access Management Core
+
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${io.entgra.device.mgt.core.version}
+ CEA Management Core Bundle
+ io.entgra.device.mgt.core.cea.mgt.core.internal
+
+ org.osgi.framework.*;version="${imp.package.version.osgi.framework}",
+ org.osgi.service.*;version="${imp.package.version.osgi.service}",
+ org.apache.commons.logging,
+ org.wso2.carbon.utils,
+ org.wso2.carbon.context.*,
+ org.wso2.carbon.ndatasource.core,
+ io.entgra.device.mgt.core.cea.mgt.enforce.*,
+ io.entgra.device.mgt.core.cea.mgt.common.*,
+ io.entgra.device.mgt.core.device.mgt.common.*,
+ io.entgra.device.mgt.core.device.mgt.core.*,
+ org.wso2.carbon.ntask.*
+
+
+ !io.entgra.device.mgt.core.cea.mgt.core.internal,
+ io.entgra.device.mgt.core.cea.mgt.core.*
+
+
+
+
+
+
+
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.common
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.enforce
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.device.mgt.common
+
+
+ org.wso2.carbon
+ org.wso2.carbon.ndatasource.core
+
+
+ org.wso2.carbon.commons
+ org.wso2.carbon.ntask.core
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.device.mgt.core
+
+
+
\ No newline at end of file
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/bean/ActiveSyncServerConfiguration.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/bean/ActiveSyncServerConfiguration.java
new file mode 100644
index 0000000000..171d0f0d2b
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/bean/ActiveSyncServerConfiguration.java
@@ -0,0 +1,57 @@
+/*
+ * 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.core.bean;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "ActiveSyncServerConfiguration")
+public class ActiveSyncServerConfiguration {
+ private String key;
+ private String gatewayService;
+ private String enforcementService;
+
+ public String getKey() {
+ return key;
+ }
+
+ @XmlElement(name = "Key", required = true)
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getGatewayService() {
+ return gatewayService;
+ }
+
+ @XmlElement(name = "GatewayService", required = true)
+ public void setGatewayService(String gatewayService) {
+ this.gatewayService = gatewayService;
+ }
+
+ public String getEnforcementService() {
+ return enforcementService;
+ }
+
+ @XmlElement(name = "EnforcementService", required = true)
+ public void setEnforcementService(String enforcementService) {
+ this.enforcementService = enforcementService;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/bean/CEAConfiguration.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/bean/CEAConfiguration.java
new file mode 100644
index 0000000000..a7b36bf8d9
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/bean/CEAConfiguration.java
@@ -0,0 +1,72 @@
+/*
+ * 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.core.bean;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServer;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+import java.util.Objects;
+
+@XmlRootElement(name = "CEAConfiguration")
+public class CEAConfiguration {
+ private List activeSyncServerConfigurations;
+ private MonitoringConfiguration monitoringConfiguration;
+
+ public List getActiveSyncServerConfigurations() {
+ return activeSyncServerConfigurations;
+ }
+
+ @XmlElementWrapper(name = "ActiveSyncServerConfigurations", required = true)
+ @XmlElement(name = "ActiveSyncServerConfiguration", required = true)
+ public void setActiveSyncServerConfigurations(List activeSyncServerConfigurations) {
+ this.activeSyncServerConfigurations = activeSyncServerConfigurations;
+ }
+
+ public ActiveSyncServerConfiguration getActiveSyncServerConfiguration(ActiveSyncServer activeSyncServer) {
+ ActiveSyncServerConfiguration activeSyncServerConfiguration = null;
+ for (ActiveSyncServerConfiguration config : activeSyncServerConfigurations) {
+ if (Objects.equals(config.getKey(), activeSyncServer.getKey())) {
+ activeSyncServerConfiguration = config;
+ }
+ }
+ return activeSyncServerConfiguration;
+ }
+
+ public boolean isServerSupport(ActiveSyncServer activeSyncServer) {
+ for (ActiveSyncServerConfiguration config : activeSyncServerConfigurations) {
+ if (Objects.equals(config.getKey(), activeSyncServer.getKey())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public MonitoringConfiguration getMonitoringConfiguration() {
+ return monitoringConfiguration;
+ }
+
+ @XmlElement(name = "MonitoringConfiguration", required = true)
+ public void setMonitoringConfiguration(MonitoringConfiguration monitoringConfiguration) {
+ this.monitoringConfiguration = monitoringConfiguration;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/bean/MonitoringConfiguration.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/bean/MonitoringConfiguration.java
new file mode 100644
index 0000000000..8f72ad6fc1
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/bean/MonitoringConfiguration.java
@@ -0,0 +1,57 @@
+/*
+ * 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.core.bean;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "MonitoringConfiguration")
+public class MonitoringConfiguration {
+ private boolean monitoringEnable;
+ private long monitoringFrequency;
+ private String monitoringClazz;
+
+ public boolean isMonitoringEnable() {
+ return monitoringEnable;
+ }
+
+ @XmlElement(name = "MonitoringEnable", required = true)
+ public void setMonitoringEnable(boolean monitoringEnable) {
+ this.monitoringEnable = monitoringEnable;
+ }
+
+ public long getMonitoringFrequency() {
+ return monitoringFrequency;
+ }
+
+ @XmlElement(name = "MonitoringFrequency", required = true)
+ public void setMonitoringFrequency(long monitoringFrequency) {
+ this.monitoringFrequency = monitoringFrequency;
+ }
+
+ public String getMonitoringClazz() {
+ return monitoringClazz;
+ }
+
+ @XmlElement(name = "MonitoringClazz", required = true)
+ public void setMonitoringClazz(String monitoringClazz) {
+ this.monitoringClazz = monitoringClazz;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/CEAConfigManager.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/CEAConfigManager.java
new file mode 100644
index 0000000000..13dbd2201b
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/CEAConfigManager.java
@@ -0,0 +1,116 @@
+/*
+ * 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.core.config;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ui.CEAPolicyUIConfiguration;
+import io.entgra.device.mgt.core.cea.mgt.common.exception.CEAConfigManagerException;
+import io.entgra.device.mgt.core.cea.mgt.core.bean.CEAConfiguration;
+import io.entgra.device.mgt.core.cea.mgt.core.config.datasource.CEADeviceMgtConfiguration;
+import io.entgra.device.mgt.core.cea.mgt.core.config.datasource.CEAPolicyManagementRepository;
+import io.entgra.device.mgt.core.cea.mgt.core.util.Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.File;
+
+public class CEAConfigManager {
+ private static final Log log = LogFactory.getLog(CEAConfigManager.class);
+
+ private static final String CDM_CONFIG_PATH = CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ Constants.CDM_CONFIG_FILE_NAME;
+ private static final String CEA_UI_CONFIG_PATH = CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ Constants.CEA_POLICY_UI_FILE_NAME;
+ private static final String CEA_CONFIG_PATH = CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ Constants.CEA_CONFIG_FILE_NAME;
+ private CEAPolicyManagementRepository ceaPolicyManagementRepository;
+ private CEAConfiguration ceaConfiguration;
+ private CEAPolicyUIConfiguration ceaPolicyUIConfiguration;
+
+ CEAConfigManager() {
+ }
+
+ public static CEAConfigManager getInstance() {
+ return CEAConfigManagerHolder.INSTANCE;
+ }
+
+ private T initConfig(String docPath, Class configClass) throws JAXBException {
+ File doc = new File(docPath);
+ JAXBContext jaxbContext = JAXBContext.newInstance(configClass);
+ Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
+ return configClass.cast(jaxbUnmarshaller.unmarshal(doc));
+ }
+
+ private void initDatasourceConfig() throws JAXBException {
+ ceaPolicyManagementRepository = initConfig(CDM_CONFIG_PATH, CEADeviceMgtConfiguration.class)
+ .getCeaPolicyManagementRepository();
+ }
+
+ private void initCEAPConfig() throws JAXBException {
+ ceaConfiguration = initConfig(CEA_CONFIG_PATH, CEAConfiguration.class);
+ }
+
+ private void initCEAPolicyUIConfig() throws JAXBException {
+ ceaPolicyUIConfiguration = initConfig(CEA_UI_CONFIG_PATH, CEAPolicyUIConfiguration.class);
+ }
+
+ public CEAPolicyManagementRepository getCeaPolicyManagementRepository() throws CEAConfigManagerException {
+ try {
+ if (ceaPolicyManagementRepository == null) {
+ initDatasourceConfig();
+ }
+ return ceaPolicyManagementRepository;
+ } catch (JAXBException e) {
+ String msg = "Error occurred while initializing datasource configuration";
+ throw new CEAConfigManagerException(msg, e);
+ }
+ }
+
+ public CEAConfiguration getCeaConfiguration() throws CEAConfigManagerException {
+ try {
+ if (ceaConfiguration == null) {
+ initCEAPConfig();
+ }
+ return ceaConfiguration;
+ } catch (JAXBException e) {
+ String msg = "Error occurred while initializing CEA configuration";
+ throw new CEAConfigManagerException(msg, e);
+ }
+ }
+
+ public CEAPolicyUIConfiguration getCeaPolicyUIConfiguration() throws CEAConfigManagerException {
+ try {
+ if (ceaPolicyUIConfiguration == null) {
+ initCEAPolicyUIConfig();
+ }
+ return ceaPolicyUIConfiguration;
+ } catch (JAXBException e) {
+ String msg = "Error occurred while initializing policy UI configuration";
+ throw new CEAConfigManagerException(msg, e);
+ }
+ }
+
+ private static class CEAConfigManagerHolder {
+ public static final CEAConfigManager INSTANCE = new CEAConfigManager();
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/CEADatasourceConfiguration.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/CEADatasourceConfiguration.java
new file mode 100644
index 0000000000..fe8c12e47b
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/CEADatasourceConfiguration.java
@@ -0,0 +1,37 @@
+/*
+ * 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.core.config.datasource;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "DataSourceConfiguration")
+public class CEADatasourceConfiguration {
+ private JNDILookupDefinition jndiLookupDefinition;
+
+ public JNDILookupDefinition getJndiLookupDefinition() {
+ return jndiLookupDefinition;
+ }
+
+ @XmlElement(name = "JndiLookupDefinition", nillable = true)
+ public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
+ this.jndiLookupDefinition = jndiLookupDefinition;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/CEADeviceMgtConfiguration.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/CEADeviceMgtConfiguration.java
new file mode 100644
index 0000000000..4e748f55b7
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/CEADeviceMgtConfiguration.java
@@ -0,0 +1,37 @@
+/*
+ * 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.core.config.datasource;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "DeviceMgtConfiguration")
+public class CEADeviceMgtConfiguration {
+ private CEAPolicyManagementRepository ceaPolicyManagementRepository;
+
+ public CEAPolicyManagementRepository getCeaPolicyManagementRepository() {
+ return ceaPolicyManagementRepository;
+ }
+
+ @XmlElement(name = "ManagementRepository", nillable = false)
+ public void setCeaPolicyManagementRepository(CEAPolicyManagementRepository ceaPolicyManagementRepository) {
+ this.ceaPolicyManagementRepository = ceaPolicyManagementRepository;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/CEAPolicyManagementRepository.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/CEAPolicyManagementRepository.java
new file mode 100644
index 0000000000..b4bbabf555
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/CEAPolicyManagementRepository.java
@@ -0,0 +1,37 @@
+/*
+ * 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.core.config.datasource;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "ManagementRepository")
+public class CEAPolicyManagementRepository {
+ private CEADatasourceConfiguration ceaDatasourceConfiguration;
+
+ @XmlElement(name = "DataSourceConfiguration", nillable = false)
+ public CEADatasourceConfiguration getDataSourceConfig() {
+ return ceaDatasourceConfiguration;
+ }
+
+ public void setDataSourceConfig(CEADatasourceConfiguration ceaDatasourceConfiguration) {
+ this.ceaDatasourceConfiguration = ceaDatasourceConfiguration;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/JNDILookupDefinition.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/JNDILookupDefinition.java
new file mode 100644
index 0000000000..a2aaca760d
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/config/datasource/JNDILookupDefinition.java
@@ -0,0 +1,74 @@
+/*
+ * 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.core.config.datasource;
+
+import javax.xml.bind.annotation.*;
+import java.util.List;
+
+@XmlRootElement(name = "JndiLookupDefinition")
+public class JNDILookupDefinition {
+ private String jndiName;
+ private List jndiProperties;
+
+ @XmlElement(name = "Name", nillable = false)
+ public String getJndiName() {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName) {
+ this.jndiName = jndiName;
+ }
+
+ @XmlElementWrapper(name = "Environment", nillable = false)
+ @XmlElement(name = "Property", nillable = false)
+ public List getJndiProperties() {
+ return jndiProperties;
+ }
+
+ public void setJndiProperties(List jndiProperties) {
+ this.jndiProperties = jndiProperties;
+ }
+
+ @XmlRootElement(name = "Property")
+ public static class JNDIProperty {
+
+ private String name;
+
+ private String value;
+
+ @XmlAttribute(name = "Name")
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlValue
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/CEAPolicyDAO.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/CEAPolicyDAO.java
new file mode 100644
index 0000000000..2f83e4b587
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/CEAPolicyDAO.java
@@ -0,0 +1,76 @@
+/*
+ * 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.core.dao;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.CEAPolicy;
+import io.entgra.device.mgt.core.cea.mgt.core.exception.CEAPolicyManagementDAOException;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * DAO class for Conditional Email Access management
+ */
+public interface CEAPolicyDAO {
+ /**
+ * Create CEA policy for a tenant if a CEA policy not already exists
+ * @param ceaPolicy {@link CEAPolicy}
+ * @return Created CEA policy
+ * @throws CEAPolicyManagementDAOException Throws when error occurred while creating CEA policy
+ */
+ CEAPolicy createCEAPolicy(CEAPolicy ceaPolicy) throws CEAPolicyManagementDAOException;
+
+ /**
+ * Retrieve CEA policy
+ * @return {@link CEAPolicy}
+ * @throws CEAPolicyManagementDAOException Throws when error occurred while retrieving CEA policy
+ */
+ CEAPolicy retrieveCEAPolicy() throws CEAPolicyManagementDAOException;
+
+ /**
+ * Retrieve all available CEA policies
+ * @return List of CEA policies
+ * @throws CEAPolicyManagementDAOException Throws when error occurred while retrieving CEA policies
+ */
+ List retrieveAllCEAPolicies() throws CEAPolicyManagementDAOException;
+
+ /**
+ * Update CEA policy
+ * @param existingCEAPolicy Existing CEA policy
+ * @param ceaPolicy Updated CEA policy
+ * @return Updated CEA policy
+ * @throws CEAPolicyManagementDAOException Throws when error occurred while updating CEA policy
+ */
+ CEAPolicy updateCEAPolicy(CEAPolicy existingCEAPolicy, CEAPolicy ceaPolicy) throws CEAPolicyManagementDAOException;
+
+ /**
+ * Update last sync time with the active sync server
+ * @param status True on a successful sync, otherwise false
+ * @param syncedTime Synced time stamp
+ * @throws CEAPolicyManagementDAOException Throws when error occurred while updating sync time
+ */
+ void updateLastSyncedTime(boolean status, Date syncedTime) throws CEAPolicyManagementDAOException;
+
+ /**
+ * Delete CEA policy
+ * @throws CEAPolicyManagementDAOException Throws when error occurred while deleting CEA policy
+ */
+ void deleteCEAPolicy() throws CEAPolicyManagementDAOException;
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/factory/CEAPolicyManagementDAOFactory.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/factory/CEAPolicyManagementDAOFactory.java
new file mode 100644
index 0000000000..62ef5f6f8b
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/factory/CEAPolicyManagementDAOFactory.java
@@ -0,0 +1,204 @@
+/*
+ * 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.core.dao.factory;
+
+import io.entgra.device.mgt.core.cea.mgt.core.config.datasource.CEADatasourceConfiguration;
+import io.entgra.device.mgt.core.cea.mgt.core.config.datasource.JNDILookupDefinition;
+import io.entgra.device.mgt.core.cea.mgt.core.dao.CEAPolicyDAO;
+import io.entgra.device.mgt.core.cea.mgt.core.dao.impl.GenericCEAPolicyDAO;
+import io.entgra.device.mgt.core.cea.mgt.core.exception.CEAPolicyManagementDAOException;
+import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.IllegalTransactionStateException;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.UnsupportedDatabaseEngineException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Hashtable;
+import java.util.List;
+
+public class CEAPolicyManagementDAOFactory {
+ private static final Log log = LogFactory.getLog(CEAPolicyManagementDAOFactory.class);
+ private static final ThreadLocal currentConnection = new ThreadLocal<>();
+ private static DataSource dataSource;
+ private static String productName;
+
+ public static void init(CEADatasourceConfiguration ceaDatasourceConfiguration) {
+ dataSource = resolveDatasource(ceaDatasourceConfiguration);
+ if (dataSource == null) {
+ throw new IllegalStateException("Datasource is not initialized properly");
+ }
+ try {
+ productName = dataSource.getConnection().getMetaData().getDatabaseProductName();
+ } catch (SQLException e) {
+ log.error("Error occurred while initializing database product name");
+ }
+ }
+
+ private static DataSource resolveDatasource(CEADatasourceConfiguration ceaDatasourceConfiguration) {
+ if (ceaDatasourceConfiguration == null) {
+ throw new IllegalArgumentException("Null is retrieved for Datasource configuration");
+ }
+ JNDILookupDefinition jndiLookupDefinition = ceaDatasourceConfiguration.getJndiLookupDefinition();
+ if (jndiLookupDefinition == null) {
+ throw new IllegalArgumentException("Null is retrieved for JNDI lookup definition");
+ }
+ String datasourceName = jndiLookupDefinition.getJndiName();
+ List jndiProperties = ceaDatasourceConfiguration.getJndiLookupDefinition().getJndiProperties();
+
+ if (jndiProperties == null || jndiProperties.isEmpty()) {
+ return lookupDatasource(datasourceName);
+ }
+ Hashtable jndiPropertiesTable = new Hashtable<>();
+ for (JNDILookupDefinition.JNDIProperty property : jndiProperties) {
+ jndiPropertiesTable.put(property.getName(), property.getValue());
+ }
+ return lookupDatasource(datasourceName, jndiPropertiesTable);
+ }
+
+ private static DataSource lookupDatasource(String datasourceName) {
+ try {
+ return InitialContext.doLookup(datasourceName);
+ } catch (NamingException e) {
+ String msg = "Error occurred while JNDI lookup for the datasource";
+ throw new IllegalStateException(msg, e);
+ }
+ }
+
+ private static DataSource lookupDatasource(String datasourceName, Hashtable jndiProperties) {
+ try {
+ InitialContext initialContext = new InitialContext(jndiProperties);
+ return (DataSource) initialContext.lookup(datasourceName);
+ } catch (NamingException e) {
+ String msg = "Error occurred while JNDI lookup for the datasource";
+ throw new IllegalStateException(msg, e);
+ }
+ }
+
+ public static CEAPolicyDAO getCEAPolicyDAO() {
+ if (productName == null) {
+ throw new IllegalStateException("Database is not initialized properly");
+ }
+
+ switch (productName) {
+ case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL:
+ case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL:
+ case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
+ case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE:
+ case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
+ case DeviceManagementConstants.DataBaseTypes.DB_TYPE_DB2:
+ return new GenericCEAPolicyDAO();
+ default:
+ throw new UnsupportedDatabaseEngineException("Unsupported database product " + productName);
+ }
+ }
+
+ public static void openConnection() throws CEAPolicyManagementDAOException {
+ Connection connection = currentConnection.get();
+ if (connection != null) {
+ throw new IllegalTransactionStateException("A transaction is already active within the context of " +
+ "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " +
+ "transaction is already active is a sign of improper transaction handling");
+ }
+ try {
+ connection = dataSource.getConnection();
+ currentConnection.set(connection);
+ } catch (SQLException e) {
+ String msg = "Error encountered while acquiring connection from the datasource";
+ log.error(msg, e);
+ throw new CEAPolicyManagementDAOException(msg, e);
+ }
+ }
+
+ public static Connection getConnection() {
+ Connection connection = currentConnection.get();
+ if (connection == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ return connection;
+ }
+
+ public static void closeConnection() {
+ Connection connection = currentConnection.get();
+ if (connection == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ log.warn("Error encountered while closing the connection", e);
+ }
+ currentConnection.remove();
+ }
+
+ public static void beginTransaction() throws CEAPolicyManagementDAOException {
+ Connection connection = currentConnection.get();
+ if (connection == null) {
+ throw new IllegalTransactionStateException("A transaction is already active within the context of " +
+ "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " +
+ "transaction is already active is a sign of improper transaction handling");
+ }
+ try {
+ connection = dataSource.getConnection();
+ connection.setAutoCommit(false);
+ currentConnection.set(connection);
+ } catch (SQLException e) {
+ String msg = "Error encountered while acquiring connection from the datasource";
+ log.error(msg, e);
+ throw new CEAPolicyManagementDAOException(msg, e);
+ }
+ }
+
+ public static void rollbackTransaction() {
+ Connection connection = currentConnection.get();
+ if (connection == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ try {
+ connection.rollback();
+ } catch (SQLException e) {
+ log.error("Error encountered while performing rollback operation on transaction", e);
+ }
+ }
+
+ public static void commitTransaction() {
+ Connection connection = currentConnection.get();
+ if (connection == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ try {
+ connection.commit();
+ } catch (SQLException e) {
+ log.error("Error encountered while committing the transaction", e);
+ }
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/impl/AbstractCEAPolicyDAO.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/impl/AbstractCEAPolicyDAO.java
new file mode 100644
index 0000000000..9556296386
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/impl/AbstractCEAPolicyDAO.java
@@ -0,0 +1,249 @@
+/*
+ * 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.core.dao.impl;
+
+import com.google.gson.Gson;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServer;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.CEAPolicy;
+import io.entgra.device.mgt.core.cea.mgt.core.dao.CEAPolicyDAO;
+import io.entgra.device.mgt.core.cea.mgt.core.dao.factory.CEAPolicyManagementDAOFactory;
+import io.entgra.device.mgt.core.cea.mgt.core.dto.CEAPolicyContent;
+import io.entgra.device.mgt.core.cea.mgt.core.dto.CEAPolicyDTO;
+import io.entgra.device.mgt.core.cea.mgt.core.exception.CEAPolicyManagementDAOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+
+import java.nio.charset.StandardCharsets;
+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.Base64;
+import java.util.Date;
+import java.util.List;
+
+public class AbstractCEAPolicyDAO implements CEAPolicyDAO {
+ private static final Log log = LogFactory.getLog(AbstractCEAPolicyDAO.class);
+ private static final Gson gson = new Gson();
+
+ @Override
+ public CEAPolicy createCEAPolicy(CEAPolicy ceaPolicy) throws CEAPolicyManagementDAOException {
+ ceaPolicy.setCreated(new Date());
+ ceaPolicy.setLastUpdated(new Date());
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ ceaPolicy.setTenantId(tenantId);
+ CEAPolicyDTO ceaPolicyDTO = toCEAPolicyDTO(ceaPolicy);
+ String query = "INSERT INTO DM_CEA_POLICIES " +
+ "(POLICY_CONTENT, " +
+ "CREATED_TIMESTAMP, " +
+ "UPDATED_TIMESTAMP, " +
+ "TENANT_ID) VALUES (?, ?, ?, ?)";
+ Connection connection = CEAPolicyManagementDAOFactory.getConnection();
+ try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+ preparedStatement.setString(1, ceaPolicyDTO.getPolicyContent());
+ preparedStatement.setTimestamp(2, ceaPolicyDTO.getCreatedTimestamp());
+ preparedStatement.setTimestamp(3, ceaPolicyDTO.getUpdatedTimestamp());
+ preparedStatement.setInt(4, tenantId);
+ preparedStatement.execute();
+ } catch (SQLException e) {
+ String msg = "Error occurred while creating CEA policy for tenant id : " + tenantId;
+ log.error(msg, e);
+ throw new CEAPolicyManagementDAOException(msg, e);
+ }
+ return ceaPolicy;
+ }
+
+ @Override
+ public CEAPolicy retrieveCEAPolicy() throws CEAPolicyManagementDAOException {
+ CEAPolicy ceaPolicy = null;
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ String query = "SELECT POLICY_CONTENT, " +
+ "CREATED_TIMESTAMP, " +
+ "UPDATED_TIMESTAMP, " +
+ "LAST_SYNCED_TIMESTAMP, " +
+ "IS_SYNCED " +
+ "FROM DM_CEA_POLICIES WHERE TENANT_ID = ?";
+ Connection connection = CEAPolicyManagementDAOFactory.getConnection();
+ try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+ preparedStatement.setInt(1, tenantId);
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ CEAPolicyDTO ceaPolicyDTO;
+ while (resultSet.next()) {
+ ceaPolicyDTO = new CEAPolicyDTO();
+ ceaPolicyDTO.setPolicyContent(resultSet.getString("POLICY_CONTENT"));
+ ceaPolicyDTO.setCreatedTimestamp(resultSet.getTimestamp("CREATED_TIMESTAMP"));
+ ceaPolicyDTO.setUpdatedTimestamp(resultSet.getTimestamp("UPDATED_TIMESTAMP"));
+ ceaPolicyDTO.setLastSyncedTimestamp(resultSet.getTimestamp("LAST_SYNCED_TIMESTAMP"));
+ ceaPolicyDTO.setSynced(resultSet.getBoolean("IS_SYNCED"));
+ ceaPolicyDTO.setTenantId(tenantId);
+ ceaPolicy = toCEAPolicy(ceaPolicyDTO);
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving CEA policy for tenant id : " + tenantId;
+ log.error(msg, e);
+ throw new CEAPolicyManagementDAOException(msg, e);
+ }
+ return ceaPolicy;
+ }
+
+ @Override
+ public List retrieveAllCEAPolicies() throws CEAPolicyManagementDAOException {
+ List ceaPolicies = new ArrayList<>();
+ String query = "SELECT POLICY_CONTENT, " +
+ "CREATED_TIMESTAMP, " +
+ "UPDATED_TIMESTAMP, " +
+ "LAST_SYNCED_TIMESTAMP, " +
+ "IS_SYNCED, " +
+ "TENANT_ID FROM DM_CEA_POLICIES";
+ Connection connection = CEAPolicyManagementDAOFactory.getConnection();
+ try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ CEAPolicyDTO ceaPolicyDTO;
+ while (resultSet.next()) {
+ ceaPolicyDTO = new CEAPolicyDTO();
+ ceaPolicyDTO.setPolicyContent(resultSet.getString("POLICY_CONTENT"));
+ ceaPolicyDTO.setCreatedTimestamp(resultSet.getTimestamp("CREATED_TIMESTAMP"));
+ ceaPolicyDTO.setUpdatedTimestamp(resultSet.getTimestamp("UPDATED_TIMESTAMP"));
+ ceaPolicyDTO.setLastSyncedTimestamp(resultSet.getTimestamp("LAST_SYNCED_TIMESTAMP"));
+ ceaPolicyDTO.setSynced(resultSet.getBoolean("IS_SYNCED"));
+ ceaPolicyDTO.setTenantId(resultSet.getInt("TENANT_ID"));
+ ceaPolicies.add(toCEAPolicy(ceaPolicyDTO));
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving All CEA policies";
+ log.error(msg, e);
+ throw new CEAPolicyManagementDAOException(msg, e);
+ }
+ return ceaPolicies;
+ }
+
+ @Override
+ public CEAPolicy updateCEAPolicy(CEAPolicy existingCEAPolicy, CEAPolicy ceaPolicy) throws CEAPolicyManagementDAOException {
+ ceaPolicy.setCreated(existingCEAPolicy.getCreated());
+ ceaPolicy.setSynced(existingCEAPolicy.isSynced());
+ ceaPolicy.setLastSynced(existingCEAPolicy.getLastSynced());
+ ceaPolicy.setLastUpdated(new Date());
+ CEAPolicyDTO ceaPolicyDTO = toCEAPolicyDTO(ceaPolicy);
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ String query = "UPDATE DM_CEA_POLICIES " +
+ "SET POLICY_CONTENT = ?, " +
+ "UPDATED_TIMESTAMP = ? " +
+ "WHERE TENANT_ID = ?";
+ Connection connection = CEAPolicyManagementDAOFactory.getConnection();
+ try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+ preparedStatement.setString(1, ceaPolicyDTO.getPolicyContent());
+ preparedStatement.setTimestamp(2, ceaPolicyDTO.getUpdatedTimestamp());
+ preparedStatement.setInt(3, tenantId);
+ preparedStatement.executeUpdate();
+ } catch (SQLException e) {
+ String msg = "Error occurred while updating CEA policy for tenant id : " + tenantId;
+ log.error(msg, e);
+ throw new CEAPolicyManagementDAOException(msg, e);
+ }
+ return ceaPolicy;
+ }
+
+ @Override
+ public void updateLastSyncedTime(boolean status, Date syncedTime) throws CEAPolicyManagementDAOException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ String query = "UPDATE DM_CEA_POLICIES " +
+ "SET LAST_SYNCED_TIMESTAMP = ?, " +
+ "IS_SYNCED = ? " +
+ "WHERE TENANT_ID = ?";
+ Connection connection = CEAPolicyManagementDAOFactory.getConnection();
+ try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+ preparedStatement.setTimestamp(1, new Timestamp(syncedTime.getTime()));
+ preparedStatement.setBoolean(2, status);
+ preparedStatement.setInt(3, tenantId);
+ preparedStatement.executeUpdate();
+ } catch (SQLException e) {
+ String msg = "Error occurred while updating CEA policy last sync timestamp for tenant id : " + tenantId;
+ log.error(msg, e);
+ throw new CEAPolicyManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public void deleteCEAPolicy() throws CEAPolicyManagementDAOException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ String query = "DELETE FROM DM_CEA_POLICIES WHERE TENANT_ID = ?";
+ Connection connection = CEAPolicyManagementDAOFactory.getConnection();
+ try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+ preparedStatement.setInt(1, tenantId);
+ preparedStatement.execute();
+ } catch (SQLException e) {
+ String msg = "Error occurred while deleting CEA policy for tenant id : " + tenantId;
+ log.error(msg, e);
+ throw new CEAPolicyManagementDAOException(msg, e);
+ }
+ }
+
+ private CEAPolicyDTO toCEAPolicyDTO(CEAPolicy ceaPolicy) throws CEAPolicyManagementDAOException {
+ if (ceaPolicy == null) {
+ throw new CEAPolicyManagementDAOException("CEAPolicy can't be null");
+ }
+ CEAPolicyDTO ceaPolicyDTO = new CEAPolicyDTO();
+ CEAPolicyContent ceaPolicyContent = new CEAPolicyContent();
+ ActiveSyncServer activeSyncServer = new ActiveSyncServer();
+ activeSyncServer.setSecret(Base64.getEncoder().
+ encodeToString(ceaPolicy.getActiveSyncServer().getSecret().getBytes(StandardCharsets.UTF_8)));
+ activeSyncServer.setClient(ceaPolicy.getActiveSyncServer().getClient());
+ activeSyncServer.setKey(ceaPolicy.getActiveSyncServer().getKey());
+ activeSyncServer.setGatewayUrl(ceaPolicy.getActiveSyncServer().getGatewayUrl());
+ ceaPolicyContent.setAccessPolicy(ceaPolicy.getAccessPolicy());
+ ceaPolicyContent.setGracePeriod(ceaPolicy.getGracePeriod());
+ ceaPolicyContent.setActiveSyncServer(activeSyncServer);
+ ceaPolicyDTO.setPolicyContent(gson.toJson(ceaPolicyContent));
+ ceaPolicyDTO.setSynced(ceaPolicy.isSynced());
+ ceaPolicyDTO.setCreatedTimestamp(new Timestamp(ceaPolicy.getCreated().getTime()));
+ ceaPolicyDTO.setUpdatedTimestamp(new Timestamp(ceaPolicy.getLastUpdated().getTime()));
+ ceaPolicyDTO.setTenantId(ceaPolicy.getTenantId());
+ if (ceaPolicy.getLastSynced() != null) {
+ ceaPolicyDTO.setLastSyncedTimestamp(new Timestamp(ceaPolicy.getLastSynced().getTime()));
+ }
+ return ceaPolicyDTO;
+ }
+
+ private CEAPolicy toCEAPolicy(CEAPolicyDTO ceaPolicyDTO) throws CEAPolicyManagementDAOException{
+ if (ceaPolicyDTO == null) {
+ throw new CEAPolicyManagementDAOException("CEAPolicyDTO can't be null");
+ }
+ CEAPolicy ceaPolicy = new CEAPolicy();
+ CEAPolicyContent ceaPolicyContent = gson.fromJson(ceaPolicyDTO.getPolicyContent(), CEAPolicyContent.class);
+ ActiveSyncServer activeSyncServer = ceaPolicyContent.getActiveSyncServer();
+ activeSyncServer.setSecret(new String(Base64.getDecoder().decode(activeSyncServer.getSecret())));
+ ceaPolicy.setActiveSyncServer(activeSyncServer);
+ ceaPolicy.setAccessPolicy(ceaPolicyContent.getAccessPolicy());
+ ceaPolicy.setGracePeriod(ceaPolicyContent.getGracePeriod());
+ ceaPolicy.setLastUpdated(new Date(ceaPolicyDTO.getUpdatedTimestamp().getTime()));
+ ceaPolicy.setSynced(ceaPolicyDTO.isSynced());
+ ceaPolicy.setTenantId(ceaPolicyDTO.getTenantId());
+ if (ceaPolicyDTO.getLastSyncedTimestamp() != null) {
+ ceaPolicy.setLastSynced(new Date(ceaPolicyDTO.getLastSyncedTimestamp().getTime()));
+ }
+ ceaPolicy.setCreated(new Date(ceaPolicyDTO.getCreatedTimestamp().getTime()));
+ return ceaPolicy;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/impl/GenericCEAPolicyDAO.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/impl/GenericCEAPolicyDAO.java
new file mode 100644
index 0000000000..056d05c0bd
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dao/impl/GenericCEAPolicyDAO.java
@@ -0,0 +1,26 @@
+/*
+ * 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.core.dao.impl;
+
+public class GenericCEAPolicyDAO extends AbstractCEAPolicyDAO {
+ public GenericCEAPolicyDAO() {
+ super();
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dto/CEAPolicyContent.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dto/CEAPolicyContent.java
new file mode 100644
index 0000000000..9bd94a8eeb
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dto/CEAPolicyContent.java
@@ -0,0 +1,54 @@
+/*
+ * 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.core.dto;
+
+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.GracePeriod;
+
+public class CEAPolicyContent {
+ private ActiveSyncServer activeSyncServer;
+ private GracePeriod gracePeriod;
+ private AccessPolicy accessPolicy;
+
+ public ActiveSyncServer getActiveSyncServer() {
+ return activeSyncServer;
+ }
+
+ public void setActiveSyncServer(ActiveSyncServer activeSyncServer) {
+ this.activeSyncServer = activeSyncServer;
+ }
+
+ public GracePeriod getGracePeriod() {
+ return gracePeriod;
+ }
+
+ public void setGracePeriod(GracePeriod gracePeriod) {
+ this.gracePeriod = gracePeriod;
+ }
+
+ public AccessPolicy getAccessPolicy() {
+ return accessPolicy;
+ }
+
+ public void setAccessPolicy(AccessPolicy accessPolicy) {
+ this.accessPolicy = accessPolicy;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dto/CEAPolicyDTO.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dto/CEAPolicyDTO.java
new file mode 100644
index 0000000000..60fb02c88d
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/dto/CEAPolicyDTO.java
@@ -0,0 +1,79 @@
+/*
+ * 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.core.dto;
+
+import java.sql.Timestamp;
+
+public class CEAPolicyDTO {
+ private String policyContent;
+ private Timestamp createdTimestamp;
+ private Timestamp updatedTimestamp;
+ private Timestamp lastSyncedTimestamp;
+ private boolean isSynced;
+ private int tenantId;
+
+ public String getPolicyContent() {
+ return policyContent;
+ }
+
+ public void setPolicyContent(String policyContent) {
+ this.policyContent = policyContent;
+ }
+
+ public Timestamp getCreatedTimestamp() {
+ return createdTimestamp;
+ }
+
+ public void setCreatedTimestamp(Timestamp createdTimestamp) {
+ this.createdTimestamp = createdTimestamp;
+ }
+
+ public Timestamp getUpdatedTimestamp() {
+ return updatedTimestamp;
+ }
+
+ public void setUpdatedTimestamp(Timestamp updatedTimestamp) {
+ this.updatedTimestamp = updatedTimestamp;
+ }
+
+ public Timestamp getLastSyncedTimestamp() {
+ return lastSyncedTimestamp;
+ }
+
+ public void setLastSyncedTimestamp(Timestamp lastSyncedTimestamp) {
+ this.lastSyncedTimestamp = lastSyncedTimestamp;
+ }
+
+ public boolean isSynced() {
+ return isSynced;
+ }
+
+ public void setSynced(boolean synced) {
+ isSynced = synced;
+ }
+
+ public int getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(int tenantId) {
+ this.tenantId = tenantId;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/exception/CEAPolicyManagementDAOException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/exception/CEAPolicyManagementDAOException.java
new file mode 100644
index 0000000000..f001ef64a7
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/exception/CEAPolicyManagementDAOException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.core.exception;
+
+public class CEAPolicyManagementDAOException extends Exception {
+ public CEAPolicyManagementDAOException(String msg) {
+ super(msg);
+ }
+
+ public CEAPolicyManagementDAOException(String msg, Throwable t) {
+ super(msg, t);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/exception/CEAPolicyMonitoringTaskManagerException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/exception/CEAPolicyMonitoringTaskManagerException.java
new file mode 100644
index 0000000000..ce1390b6a6
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/exception/CEAPolicyMonitoringTaskManagerException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.core.exception;
+
+public class CEAPolicyMonitoringTaskManagerException extends Exception {
+ public CEAPolicyMonitoringTaskManagerException(String msg) {
+ super(msg);
+ }
+
+ public CEAPolicyMonitoringTaskManagerException(String msg, Throwable t) {
+ super(msg, t);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/impl/CEAManagementServiceImpl.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/impl/CEAManagementServiceImpl.java
new file mode 100644
index 0000000000..f46c6f55dc
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/impl/CEAManagementServiceImpl.java
@@ -0,0 +1,72 @@
+/*
+ * 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.core.impl;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.CEAPolicy;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ui.CEAPolicyUIConfiguration;
+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.cea.mgt.core.mgt.CEAManager;
+import io.entgra.device.mgt.core.cea.mgt.core.mgt.impl.CEAManagerImpl;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CEAManagementServiceImpl implements CEAManagementService {
+ private static final Log log = LogFactory.getLog(CEAManagementServiceImpl.class);
+
+ private final CEAManager ceaManager;
+
+ public CEAManagementServiceImpl() {
+ ceaManager = CEAManagerImpl.getInstance();
+ }
+
+ @Override
+ public CEAPolicyUIConfiguration getCEAPolicyUIConfiguration() throws CEAManagementException {
+ return ceaManager.getCEAPolicyUIConfiguration();
+ }
+
+ @Override
+ public CEAPolicy createCEAPolicy(CEAPolicy ceaPolicy) throws CEAManagementException,
+ CEAPolicyAlreadyExistsException {
+ return ceaManager.createCEAPolicy(ceaPolicy);
+ }
+
+ @Override
+ public CEAPolicy retrieveCEAPolicy() throws CEAManagementException {
+ return ceaManager.retrieveCEAPolicy();
+ }
+
+ @Override
+ public CEAPolicy updateCEAPolicy(CEAPolicy ceaPolicy) throws CEAManagementException, CEAPolicyNotFoundException {
+ return ceaManager.updateCEAPolicy(ceaPolicy);
+ }
+
+ @Override
+ public void deleteCEAPolicy() throws CEAManagementException, CEAPolicyNotFoundException {
+ ceaManager.deleteCEAPolicy();
+ }
+
+ @Override
+ public void syncNow() throws CEAManagementException {
+ ceaManager.syncNow();
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/internal/CEAManagementDataHolder.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/internal/CEAManagementDataHolder.java
new file mode 100644
index 0000000000..71f1583155
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/internal/CEAManagementDataHolder.java
@@ -0,0 +1,64 @@
+/*
+ * 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.core.internal;
+
+import io.entgra.device.mgt.core.cea.mgt.common.service.EnforcementServiceManager;
+import io.entgra.device.mgt.core.cea.mgt.core.task.CEAPolicyMonitoringTaskManager;
+import org.wso2.carbon.ntask.core.service.TaskService;
+
+public class CEAManagementDataHolder {
+ private EnforcementServiceManager enforcementServiceManager;
+ private TaskService taskService;
+ private CEAPolicyMonitoringTaskManager ceaPolicyMonitoringTaskManager;
+
+ private CEAManagementDataHolder() {}
+
+ public static CEAManagementDataHolder getInstance() {
+ return CEAManagementDataHolderRegistry.INSTANCE;
+ }
+
+ public EnforcementServiceManager getEnforcementServiceManager() {
+ return enforcementServiceManager;
+ }
+
+ public void setEnforcementServiceManager(EnforcementServiceManager enforcementServiceManager) {
+ this.enforcementServiceManager = enforcementServiceManager;
+ }
+
+ public TaskService getTaskService() {
+ return taskService;
+ }
+
+ public void setTaskService(TaskService taskService) {
+ this.taskService = taskService;
+ }
+
+ public CEAPolicyMonitoringTaskManager getCeaPolicyMonitoringTaskManager() {
+ return ceaPolicyMonitoringTaskManager;
+ }
+
+ public void setCeaPolicyMonitoringTaskManager(CEAPolicyMonitoringTaskManager ceaPolicyMonitoringTaskManager) {
+ this.ceaPolicyMonitoringTaskManager = ceaPolicyMonitoringTaskManager;
+ }
+
+ private static class CEAManagementDataHolderRegistry {
+ public static final CEAManagementDataHolder INSTANCE = new CEAManagementDataHolder();
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/internal/CEAManagementServiceComponent.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/internal/CEAManagementServiceComponent.java
new file mode 100644
index 0000000000..624391eb7c
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/internal/CEAManagementServiceComponent.java
@@ -0,0 +1,110 @@
+/*
+ * 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.core.internal;
+
+import io.entgra.device.mgt.core.cea.mgt.common.service.CEAManagementService;
+import io.entgra.device.mgt.core.cea.mgt.common.service.EnforcementServiceManager;
+import io.entgra.device.mgt.core.cea.mgt.core.config.CEAConfigManager;
+import io.entgra.device.mgt.core.cea.mgt.core.dao.factory.CEAPolicyManagementDAOFactory;
+import io.entgra.device.mgt.core.cea.mgt.core.impl.CEAManagementServiceImpl;
+import io.entgra.device.mgt.core.cea.mgt.core.task.CEAPolicyMonitoringTaskManager;
+import io.entgra.device.mgt.core.cea.mgt.core.task.CEAPolicyMonitoringTaskManagerImpl;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.ndatasource.core.DataSourceService;
+import org.wso2.carbon.ntask.core.service.TaskService;
+
+/**
+ * @scr.component name="io.entgra.device.mgt.core.cea.mgt.core.CEAManagementServiceComponent" immediate="true"
+ * @scr.reference name="org.wso2.carbon.ndatasource"
+ * interface="org.wso2.carbon.ndatasource.core.DataSourceService"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setDataSourceService"
+ * unbind="unsetDataSourceService"
+ * @scr.reference name="io.entgra.device.mgt.core.cea.mgt.enforcementServiceManager"
+ * interface="io.entgra.device.mgt.core.cea.mgt.common.service.EnforcementServiceManager"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setEnforcementServiceManager"
+ * unbind="unsetEnforcementServiceManager"
+ * @scr.reference name="ntask.component"
+ * interface="org.wso2.carbon.ntask.core.service.TaskService"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setTaskService"
+ * unbind="unsetTaskService"
+ */
+
+public class CEAManagementServiceComponent {
+ private static final Log log = LogFactory.getLog(CEAManagementServiceComponent.class);
+
+ protected void activate(ComponentContext componentContext) {
+ try {
+ CEAConfigManager ceaConfigManager = CEAConfigManager.getInstance();
+ CEAPolicyManagementDAOFactory.init(ceaConfigManager.getCeaPolicyManagementRepository().getDataSourceConfig());
+ CEAManagementService ceaManagementService = new CEAManagementServiceImpl();
+ componentContext.getBundleContext().registerService(CEAManagementService.class.getName(),
+ ceaManagementService, null);
+ CEAPolicyMonitoringTaskManager ceaPolicyMonitoringTaskManager = new CEAPolicyMonitoringTaskManagerImpl();
+ CEAManagementDataHolder.getInstance().setCeaPolicyMonitoringTaskManager(ceaPolicyMonitoringTaskManager);
+ } catch (Throwable t) {
+ String msg = "Error occurred while activating " + CEAManagementServiceComponent.class.getName();
+ log.error(msg, t);
+ }
+ }
+
+ protected void setDataSourceService(DataSourceService dataSourceService) {
+ // This is to avoid cea management component getting initialized before the underlying datasource registered
+ }
+
+ protected void unsetDataSourceService(DataSourceService dataSourceService) {
+ // Do nothing
+ }
+
+ protected void setEnforcementServiceManager(EnforcementServiceManager enforcementServiceManager) {
+ CEAManagementDataHolder.getInstance().setEnforcementServiceManager(enforcementServiceManager);
+ if (log.isDebugEnabled()) {
+ log.debug("Enforcement service manager is set successfully");
+ }
+ }
+
+ protected void unsetEnforcementServiceManager(EnforcementServiceManager enforcementServiceManager) {
+ CEAManagementDataHolder.getInstance().setEnforcementServiceManager(null);
+ if (log.isDebugEnabled()) {
+ log.debug("Enforcement service manager is unset successfully");
+ }
+ }
+
+ protected void setTaskService(TaskService taskService) {
+ CEAManagementDataHolder.getInstance().setTaskService(taskService);
+ if (log.isDebugEnabled()) {
+ log.debug("Task service is set successfully");
+ }
+ }
+
+ protected void unsetTaskService(TaskService taskService) {
+ CEAManagementDataHolder.getInstance().setTaskService(null);
+ if (log.isDebugEnabled()) {
+ log.debug("Task service is unset successfully");
+ }
+ }
+}
\ No newline at end of file
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/mgt/CEAManager.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/mgt/CEAManager.java
new file mode 100644
index 0000000000..abe1acfab4
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/mgt/CEAManager.java
@@ -0,0 +1,99 @@
+/*
+ * 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.core.mgt;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.CEAPolicy;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ui.CEAPolicyUIConfiguration;
+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 java.util.Date;
+import java.util.List;
+
+public interface CEAManager {
+ /**
+ * Retrieve conditional access policy UI configuration
+ *
+ * @return {@link CEAPolicyUIConfiguration}
+ * @throws CEAManagementException Throws when retrieving UI configurations
+ */
+ CEAPolicyUIConfiguration getCEAPolicyUIConfiguration() throws CEAManagementException;
+
+ /**
+ * Trigger sync task with active sync server
+ *
+ * @throws CEAManagementException Throws when error occurred while triggering the sync operation
+ */
+ void syncNow() throws CEAManagementException;
+
+ /**
+ * Create conditional access policy
+ *
+ * @param ceaPolicy {@link CEAPolicy}
+ * @return {@link CEAPolicy} Created conditional access policy
+ * @throws CEAManagementException Throws when error occurred while creating the policy
+ * @throws CEAPolicyAlreadyExistsException Throws when conflict occurs
+ */
+ CEAPolicy createCEAPolicy(CEAPolicy ceaPolicy) throws CEAManagementException, CEAPolicyAlreadyExistsException;
+
+ /**
+ * Retrieve conditional access policy for the tenant
+ *
+ * @return {@link CEAPolicy}
+ * @throws CEAManagementException Throws when error occurred while retrieving the policy
+ */
+ CEAPolicy retrieveCEAPolicy() throws CEAManagementException;
+
+ /**
+ * Retrieve all conditional access policies
+ *
+ * @return List of conditional access policies
+ * @throws CEAManagementException Throws when error occurred while retrieving policies
+ */
+ List retrieveAllCEAPolicies() throws CEAManagementException;
+
+ /**
+ * Update conditional access policy
+ *
+ * @param ceaPolicy {@link CEAPolicy}
+ * @return {@link CEAPolicy} Returns update conditional access policy
+ * @throws CEAManagementException Throws when error occurred while updating the policy
+ * @throws CEAPolicyNotFoundException Throws when policy doesn't exist
+ */
+ CEAPolicy updateCEAPolicy(CEAPolicy ceaPolicy) throws CEAManagementException, CEAPolicyNotFoundException;
+
+ /**
+ * Delete the conditional access policy
+ *
+ * @throws CEAManagementException Throws when error occurred while deleting the policy
+ * @throws CEAPolicyNotFoundException Throws when a conditional access policy doesn't exist
+ */
+ void deleteCEAPolicy() throws CEAManagementException, CEAPolicyNotFoundException;
+
+ /**
+ * Update sync status of the conditional access policy
+ *
+ * @param status Whether the sync success or not
+ * @param syncedTime Synced timestamp
+ * @throws CEAManagementException Throws when error occurred while updating the status
+ */
+ void updateSyncStatus(boolean status, Date syncedTime) throws CEAManagementException;
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/mgt/impl/CEAManagerImpl.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/mgt/impl/CEAManagerImpl.java
new file mode 100644
index 0000000000..13f64be4d0
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/mgt/impl/CEAManagerImpl.java
@@ -0,0 +1,199 @@
+/*
+ * 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.core.mgt.impl;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.CEAPolicy;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ui.CEAPolicyUIConfiguration;
+import io.entgra.device.mgt.core.cea.mgt.common.exception.CEAConfigManagerException;
+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.core.bean.CEAConfiguration;
+import io.entgra.device.mgt.core.cea.mgt.core.config.CEAConfigManager;
+import io.entgra.device.mgt.core.cea.mgt.core.dao.CEAPolicyDAO;
+import io.entgra.device.mgt.core.cea.mgt.core.dao.factory.CEAPolicyManagementDAOFactory;
+import io.entgra.device.mgt.core.cea.mgt.core.exception.CEAPolicyManagementDAOException;
+import io.entgra.device.mgt.core.cea.mgt.core.exception.CEAPolicyMonitoringTaskManagerException;
+import io.entgra.device.mgt.core.cea.mgt.core.internal.CEAManagementDataHolder;
+import io.entgra.device.mgt.core.cea.mgt.core.mgt.CEAManager;
+import io.entgra.device.mgt.core.cea.mgt.core.task.CEAPolicyMonitoringTaskManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Date;
+import java.util.List;
+
+public class CEAManagerImpl implements CEAManager {
+ private static final Log log = LogFactory.getLog(CEAManagerImpl.class);
+ private final CEAPolicyDAO ceaPolicyDAO;
+
+ private CEAManagerImpl() {
+ ceaPolicyDAO = CEAPolicyManagementDAOFactory.getCEAPolicyDAO();
+ }
+
+ public static CEAManagerImpl getInstance() {
+ return CEAManagerHolder.INSTANCE;
+ }
+
+ @Override
+ public CEAPolicyUIConfiguration getCEAPolicyUIConfiguration() throws CEAManagementException {
+ CEAPolicyUIConfiguration ceaPolicyUIConfiguration;
+ try {
+ ceaPolicyUIConfiguration = CEAConfigManager.getInstance().getCeaPolicyUIConfiguration();
+ } catch (CEAConfigManagerException e) {
+ String msg = "Error occurred while retrieving CEA ui configs";
+ throw new CEAManagementException(msg, e);
+ }
+ return ceaPolicyUIConfiguration;
+ }
+
+ @Override
+ public void syncNow() throws CEAManagementException {
+ try {
+ CEAPolicyMonitoringTaskManager ceaPolicyMonitoringTaskManager = CEAManagementDataHolder.
+ getInstance().getCeaPolicyMonitoringTaskManager();
+ if (ceaPolicyMonitoringTaskManager == null) {
+ throw new IllegalStateException("CEA policy monitoring task manager not initialized properly");
+ }
+ CEAConfigManager ceaConfigManager = CEAConfigManager.getInstance();
+ CEAConfiguration ceaConfiguration = ceaConfigManager.getCeaConfiguration();
+ ceaPolicyMonitoringTaskManager.stopTask();
+ ceaPolicyMonitoringTaskManager.startTask(ceaConfiguration.getMonitoringConfiguration().getMonitoringFrequency());
+ } catch (CEAConfigManagerException e) {
+ String msg = "Error occurred while retrieving CEA configurations";
+ log.error(msg, e);
+ throw new CEAManagementException(msg, e);
+ } catch (CEAPolicyMonitoringTaskManagerException e) {
+ String msg = "Error occurred while triggering CEA policy monitoring task";
+ log.error(msg, e);
+ throw new CEAManagementException(msg, e);
+ }
+ }
+
+ @Override
+ public CEAPolicy createCEAPolicy(CEAPolicy ceaPolicy) throws CEAManagementException,
+ CEAPolicyAlreadyExistsException {
+ try {
+ CEAPolicyManagementDAOFactory.openConnection();
+ if (ceaPolicyDAO.retrieveCEAPolicy() != null) {
+ throw new CEAPolicyAlreadyExistsException("CEA policy already exists");
+ }
+ return ceaPolicyDAO.createCEAPolicy(ceaPolicy);
+ } catch (CEAPolicyManagementDAOException e) {
+ String msg = "Error occurred while creating CEA policy";
+ log.error(msg, e);
+ throw new CEAManagementException(msg, e);
+ } finally {
+ CEAPolicyManagementDAOFactory.closeConnection();
+ }
+ }
+
+ @Override
+ public CEAPolicy retrieveCEAPolicy() throws CEAManagementException {
+ try {
+ CEAPolicyManagementDAOFactory.openConnection();
+ return ceaPolicyDAO.retrieveCEAPolicy();
+ } catch (CEAPolicyManagementDAOException e) {
+ String msg = "Error occurred while retrieving CEA policy";
+ log.error(msg, e);
+ throw new CEAManagementException(msg, e);
+ } finally {
+ CEAPolicyManagementDAOFactory.closeConnection();
+ }
+ }
+
+ @Override
+ public List retrieveAllCEAPolicies() throws CEAManagementException {
+ try {
+ CEAPolicyManagementDAOFactory.openConnection();
+ return ceaPolicyDAO.retrieveAllCEAPolicies();
+ } catch (CEAPolicyManagementDAOException e) {
+ String msg = "Error occurred while retrieving CEA policies";
+ log.error(msg, e);
+ throw new CEAManagementException(msg, e);
+ } finally {
+ CEAPolicyManagementDAOFactory.closeConnection();
+ }
+ }
+
+ @Override
+ public CEAPolicy updateCEAPolicy(CEAPolicy ceaPolicy) throws CEAManagementException, CEAPolicyNotFoundException {
+ try {
+ CEAPolicyManagementDAOFactory.openConnection();
+ CEAPolicy existingCeaPolicy = ceaPolicyDAO.retrieveCEAPolicy();
+ if (existingCeaPolicy == null) {
+ throw new CEAPolicyNotFoundException("CEA policy not found");
+ }
+ return ceaPolicyDAO.updateCEAPolicy(existingCeaPolicy, ceaPolicy);
+ } catch (CEAPolicyManagementDAOException e) {
+ String msg = "Error occurred while updating CEA policy";
+ log.error(msg, e);
+ throw new CEAManagementException(msg, e);
+ } finally {
+ CEAPolicyManagementDAOFactory.closeConnection();
+ }
+ }
+
+ @Override
+ public void deleteCEAPolicy() throws CEAManagementException, CEAPolicyNotFoundException {
+ try {
+ CEAPolicyManagementDAOFactory.openConnection();
+ CEAPolicyMonitoringTaskManager ceaPolicyMonitoringTaskManager = CEAManagementDataHolder.
+ getInstance().getCeaPolicyMonitoringTaskManager();
+ if (ceaPolicyMonitoringTaskManager == null) {
+ String msg = "CEA policy monitoring task manager not initialized properly, " +
+ "hence aborting CEA policy deleting procedure";
+ throw new IllegalStateException(msg);
+ }
+ CEAPolicy existingCeaPolicy = ceaPolicyDAO.retrieveCEAPolicy();
+ if (existingCeaPolicy == null) throw new CEAPolicyNotFoundException("CEA policy not found");
+ ceaPolicyDAO.deleteCEAPolicy();
+ ceaPolicyMonitoringTaskManager.stopTask();
+ } catch (CEAPolicyManagementDAOException e) {
+ String msg = "Error occurred while deleting CEA policy";
+ log.error(msg, e);
+ throw new CEAManagementException(msg, e);
+ } catch (CEAPolicyMonitoringTaskManagerException e) {
+ String msg = "Error occurred while stopping CEA policy monitoring task";
+ log.error(msg, e);
+ throw new CEAManagementException(msg, e);
+ } finally {
+ CEAPolicyManagementDAOFactory.closeConnection();
+ }
+ }
+
+ @Override
+ public void updateSyncStatus(boolean status, Date syncedTime) throws CEAManagementException {
+ try {
+ CEAPolicyManagementDAOFactory.openConnection();
+ ceaPolicyDAO.updateLastSyncedTime(status, syncedTime);
+ } catch (CEAPolicyManagementDAOException e) {
+ String msg = "Error occurred while updating sync status";
+ log.error(msg, e);
+ throw new CEAManagementException(msg, e);
+ } finally {
+ CEAPolicyManagementDAOFactory.closeConnection();
+ }
+ }
+
+ private static class CEAManagerHolder {
+ public static final CEAManagerImpl INSTANCE = new CEAManagerImpl();
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/task/CEAPolicyMonitoringTask.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/task/CEAPolicyMonitoringTask.java
new file mode 100644
index 0000000000..755000745d
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/task/CEAPolicyMonitoringTask.java
@@ -0,0 +1,112 @@
+/*
+ * 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.core.task;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.CEAPolicy;
+import io.entgra.device.mgt.core.cea.mgt.common.exception.CEAConfigManagerException;
+import io.entgra.device.mgt.core.cea.mgt.common.exception.CEAManagementException;
+import io.entgra.device.mgt.core.cea.mgt.common.exception.EnforcementServiceManagerException;
+import io.entgra.device.mgt.core.cea.mgt.common.service.EnforcementServiceManager;
+import io.entgra.device.mgt.core.cea.mgt.core.bean.ActiveSyncServerConfiguration;
+import io.entgra.device.mgt.core.cea.mgt.core.bean.CEAConfiguration;
+import io.entgra.device.mgt.core.cea.mgt.core.config.CEAConfigManager;
+import io.entgra.device.mgt.core.cea.mgt.core.internal.CEAManagementDataHolder;
+import io.entgra.device.mgt.core.cea.mgt.core.mgt.CEAManager;
+import io.entgra.device.mgt.core.cea.mgt.core.mgt.impl.CEAManagerImpl;
+import io.entgra.device.mgt.core.cea.mgt.core.util.Constants;
+import io.entgra.device.mgt.core.cea.mgt.enforce.Impl.CEAPolicyOperationImpl;
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.CEAPolicyOperationException;
+import io.entgra.device.mgt.core.cea.mgt.enforce.service.CEAPolicyOperation;
+import io.entgra.device.mgt.core.device.mgt.core.task.impl.DynamicPartitionedScheduleTask;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.base.MultitenantConstants;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+
+import java.util.Date;
+import java.util.Objects;
+
+public class CEAPolicyMonitoringTask extends DynamicPartitionedScheduleTask {
+ private static final Log log = LogFactory.getLog(CEAPolicyMonitoringTask.class);
+
+ private CEAManager ceaManager;
+ private CEAConfigManager ceaConfigManager;
+ private EnforcementServiceManager enforcementServiceManager;
+
+ @Override
+ protected void executeDynamicTask() {
+ int tenantId = Integer.parseInt(Objects.requireNonNull(getProperty(Constants.TENANT_ID_KEY)));
+ try {
+ CEAConfiguration ceaConfiguration = ceaConfigManager.getCeaConfiguration();
+ CEAPolicy ceaPolicy = ceaManager.retrieveCEAPolicy();
+ ActiveSyncServerConfiguration activeSyncServerConfiguration = ceaConfiguration.
+ getActiveSyncServerConfiguration(ceaPolicy.getActiveSyncServer());
+ if (MultitenantConstants.SUPER_TENANT_ID == tenantId) {
+ enforce(ceaPolicy, activeSyncServerConfiguration);
+ return;
+ }
+ try {
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
+ enforce(ceaPolicy, activeSyncServerConfiguration);
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+
+ } catch (CEAManagementException e) {
+ log.error("Error occurred while executing dynamic partitioned task for the CEA policy monitoring", e);
+ } catch (CEAConfigManagerException e) {
+ log.error("Error occurred while retrieving CEA configuration", e);
+ }
+ }
+
+ private void enforce(CEAPolicy ceaPolicy, ActiveSyncServerConfiguration activeSyncServerConfiguration) {
+ boolean status = false;
+ Date syncedStartTime = new Date();
+ CEAPolicyOperation ceaPolicyOperation;
+ try {
+ ceaPolicyOperation = new CEAPolicyOperationImpl(enforcementServiceManager.
+ getEnforcementService(activeSyncServerConfiguration.getEnforcementService()), ceaPolicy);
+ ceaPolicyOperation.enforce();
+ status = true;
+ } catch (EnforcementServiceManagerException | CEAPolicyOperationException e) {
+ log.error("Error occurred while enforcing the CEA access policy for the tenant id" + ceaPolicy.getTenantId(), e);
+ } finally {
+ logbackEnforcementStatus(status, syncedStartTime);
+ }
+ }
+
+
+ private void logbackEnforcementStatus(boolean status, Date syncedStartTime) {
+ try {
+ ceaManager.updateSyncStatus(status, syncedStartTime);
+ } catch (CEAManagementException e) {
+ log.error("Error occurred while recording sync status", e);
+ }
+ }
+
+ @Override
+ protected void setup() {
+ ceaManager = CEAManagerImpl.getInstance();
+ ceaConfigManager = CEAConfigManager.getInstance();
+ enforcementServiceManager = CEAManagementDataHolder.getInstance().getEnforcementServiceManager();
+ }
+
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/task/CEAPolicyMonitoringTaskManager.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/task/CEAPolicyMonitoringTaskManager.java
new file mode 100644
index 0000000000..063abbcec4
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/task/CEAPolicyMonitoringTaskManager.java
@@ -0,0 +1,28 @@
+/*
+ * 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.core.task;
+
+import io.entgra.device.mgt.core.cea.mgt.core.exception.CEAPolicyMonitoringTaskManagerException;
+
+public interface CEAPolicyMonitoringTaskManager {
+ void startTask(long monitoringFrequency) throws CEAPolicyMonitoringTaskManagerException;
+
+ void stopTask() throws CEAPolicyMonitoringTaskManagerException;
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/task/CEAPolicyMonitoringTaskManagerImpl.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/task/CEAPolicyMonitoringTaskManagerImpl.java
new file mode 100644
index 0000000000..e3e0f79cda
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/task/CEAPolicyMonitoringTaskManagerImpl.java
@@ -0,0 +1,105 @@
+/*
+ * 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.core.task;
+
+import io.entgra.device.mgt.core.cea.mgt.common.exception.CEAConfigManagerException;
+import io.entgra.device.mgt.core.cea.mgt.core.bean.CEAConfiguration;
+import io.entgra.device.mgt.core.cea.mgt.core.config.CEAConfigManager;
+import io.entgra.device.mgt.core.cea.mgt.core.exception.CEAPolicyMonitoringTaskManagerException;
+import io.entgra.device.mgt.core.cea.mgt.core.internal.CEAManagementDataHolder;
+import io.entgra.device.mgt.core.cea.mgt.core.util.Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.ntask.common.TaskException;
+import org.wso2.carbon.ntask.core.TaskInfo;
+import org.wso2.carbon.ntask.core.TaskManager;
+import org.wso2.carbon.ntask.core.service.TaskService;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class CEAPolicyMonitoringTaskManagerImpl implements CEAPolicyMonitoringTaskManager {
+ private static final Log log = LogFactory.getLog(CEAPolicyMonitoringTaskManagerImpl.class);
+
+ @Override
+ public void startTask(long monitoringFrequency) throws CEAPolicyMonitoringTaskManagerException {
+ if (monitoringFrequency <= 0) {
+ throw new CEAPolicyMonitoringTaskManagerException("Invalid monitoring frequency");
+ }
+ TaskService taskService = CEAManagementDataHolder.getInstance().getTaskService();
+ if (taskService == null) {
+ throw new IllegalStateException("Task service is not initialized");
+ }
+ try {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ CEAConfiguration ceaConfiguration = CEAConfigManager.getInstance().getCeaConfiguration();
+ boolean isMonitoringEnable = ceaConfiguration.getMonitoringConfiguration().isMonitoringEnable();
+
+ if (!isMonitoringEnable) {
+ log.warn("CEA policy monitoring is disabled");
+ return;
+ }
+
+ taskService.registerTaskType(Constants.CEA_MONITORING_TASK_TYPE);
+
+ TaskManager taskManager = taskService.getTaskManager(Constants.CEA_MONITORING_TASK_TYPE);
+
+ TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo();
+ triggerInfo.setIntervalMillis(monitoringFrequency);
+ triggerInfo.setRepeatCount(-1);
+
+ Map properties = new HashMap<>();
+ properties.put(Constants.TENANT_ID_KEY, String.valueOf(tenantId));
+ if (!taskManager.isTaskScheduled(Constants.CEA_MONITORING_TASK_NAME + tenantId)) {
+ TaskInfo taskInfo = new TaskInfo(Constants.CEA_MONITORING_TASK_NAME + tenantId,
+ ceaConfiguration.getMonitoringConfiguration().getMonitoringClazz(), properties, triggerInfo);
+ taskManager.registerTask(taskInfo);
+ taskManager.rescheduleTask(taskInfo.getName());
+ } else {
+ throw new CEAPolicyMonitoringTaskManagerException("CEA policy monitoring task is already active");
+ }
+ } catch (CEAConfigManagerException e) {
+ String msg = "Error occurred while retrieving CEA config";
+ log.error(msg, e);
+ throw new CEAPolicyMonitoringTaskManagerException(msg, e);
+ } catch (TaskException e) {
+ String msg = "Error occurred while scheduling task for CEA policy monitoring";
+ log.error(msg, e);
+ throw new CEAPolicyMonitoringTaskManagerException(msg, e);
+ }
+ }
+
+ @Override
+ public void stopTask() throws CEAPolicyMonitoringTaskManagerException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ try {
+ TaskService taskService = CEAManagementDataHolder.getInstance().getTaskService();
+ if (taskService != null && taskService.isServerInit()) {
+ TaskManager taskManager = taskService.getTaskManager(Constants.CEA_MONITORING_TASK_TYPE);
+ taskManager.deleteTask(Constants.CEA_MONITORING_TASK_NAME + tenantId);
+ }
+ } catch (TaskException e) {
+ String msg = "Error occurred while stopping the " + Constants.CEA_MONITORING_TASK_NAME + tenantId;
+ log.error(msg, e);
+ throw new CEAPolicyMonitoringTaskManagerException(msg, e);
+ }
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/util/Constants.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/util/Constants.java
new file mode 100644
index 0000000000..43eb184b37
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/src/main/java/io/entgra/device/mgt/core/cea/mgt/core/util/Constants.java
@@ -0,0 +1,29 @@
+/*
+ * 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.core.util;
+
+public class Constants {
+ public static final String CDM_CONFIG_FILE_NAME = "cdm-config.xml";
+ public static final String CEA_POLICY_UI_FILE_NAME = "cea-ui-config.xml";
+ public static final String CEA_CONFIG_FILE_NAME = "cea-config.xml";
+ public static final String CEA_MONITORING_TASK_TYPE = "CEA_MONITORING_TASK";
+ public static final String CEA_MONITORING_TASK_NAME = "CEA_MONITORING_TASK";
+ public static final String TENANT_ID_KEY = "TENANT_ID";
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/pom.xml b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/pom.xml
new file mode 100644
index 0000000000..101fe08ae2
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/pom.xml
@@ -0,0 +1,116 @@
+
+
+
+
+
+ io.entgra.device.mgt.core
+ cea-mgt
+ 5.0.38-SNAPSHOT
+ ../pom.xml
+
+
+ io.entgra.device.mgt.core.cea.mgt.enforce
+ 4.0.0
+ bundle
+ Entgra IoT - CEA Management Enforcement Service
+ Entgra IoT - Conditional Email Access Management Enforcement Service
+
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${io.entgra.device.mgt.core.version}
+ CEA Management Enforcement Service Bundle
+
+ org.osgi.framework.*;version="${imp.package.version.osgi.framework}",
+ org.osgi.service.*;version="${imp.package.version.osgi.service}",
+ org.wso2.carbon.utils,
+ org.wso2.carbon.context.*,
+ org.apache.commons.logging,
+ com.google.gson.*,
+ io.entgra.device.mgt.core.device.mgt.common.*,
+ io.entgra.device.mgt.core.cea.mgt.common.*,
+ io.entgra.device.mgt.core.device.mgt.core.service,
+ org.wso2.carbon.user.api,
+ org.wso2.carbon.user.core.service
+
+
+ io.entgra.device.mgt.core.cea.mgt.enforce.*
+
+ *
+
+
+
+
+
+
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ com.google.code.gson
+ gson
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.common
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.device.mgt.core
+
+
+ org.wso2.carbon
+ org.wso2.carbon.user.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.user.core
+
+
+ com.microsoft.azure
+ msal4j
+ 1.14.0
+ provided
+
+
+
\ No newline at end of file
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/CEAPolicyOperationImpl.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/CEAPolicyOperationImpl.java
new file mode 100644
index 0000000000..0847bae8b1
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/CEAPolicyOperationImpl.java
@@ -0,0 +1,58 @@
+/*
+ * 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.enforce.Impl;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.CEAPolicy;
+import io.entgra.device.mgt.core.cea.mgt.common.service.CEAEnforcementService;
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.CEAPolicyOperationException;
+import io.entgra.device.mgt.core.cea.mgt.enforce.service.CEAPolicyOperation;
+import io.entgra.device.mgt.core.cea.mgt.enforce.util.annotation.Enforce;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.lang.reflect.Method;
+
+public class CEAPolicyOperationImpl implements CEAPolicyOperation {
+ private static final Log log = LogFactory.getLog(CEAPolicyOperationImpl.class);
+ private final CEAEnforcementService ceaEnforcementService;
+ private final CEAPolicy ceaPolicy;
+
+ public CEAPolicyOperationImpl(CEAEnforcementService ceaEnforcementService, CEAPolicy ceaPolicy) {
+ this.ceaEnforcementService = ceaEnforcementService;
+ this.ceaPolicy = ceaPolicy;
+ }
+
+ @Override
+ public void enforce() throws CEAPolicyOperationException {
+ try {
+ Method[] methods = ceaEnforcementService.getClass().getMethods();
+ for (Method method : methods) {
+ if (method.isAnnotationPresent(Enforce.class)) {
+ method.setAccessible(true);
+ method.invoke(ceaEnforcementService, ceaPolicy);
+ }
+ }
+ } catch (Exception e) {
+ String msg = "Error occurred while invoking CEA enforcement service";
+ log.error(msg, e);
+ throw new CEAPolicyOperationException(msg, e);
+ }
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/EnforcementServiceManagerImpl.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/EnforcementServiceManagerImpl.java
new file mode 100644
index 0000000000..c670edd0f4
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/EnforcementServiceManagerImpl.java
@@ -0,0 +1,61 @@
+/*
+ * 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.enforce.Impl;
+
+import io.entgra.device.mgt.core.cea.mgt.common.exception.EnforcementServiceManagerException;
+import io.entgra.device.mgt.core.cea.mgt.common.service.CEAEnforcementService;
+import io.entgra.device.mgt.core.cea.mgt.common.service.EnforcementServiceManager;
+import io.entgra.device.mgt.core.cea.mgt.enforce.util.Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class EnforcementServiceManagerImpl implements EnforcementServiceManager {
+ private static final Log log = LogFactory.getLog(EnforcementServiceManagerImpl.class);
+
+ @Override
+ public CEAEnforcementService getEnforcementService(String enforcementServiceClassName) throws EnforcementServiceManagerException {
+ try {
+ Class> enforcementServiceClass = Class.forName(enforcementServiceClassName);
+ Method method = enforcementServiceClass.getMethod(Constants.METHOD_NAME_GET_INSTANCE);
+ return (CEAEnforcementService) method.invoke(null);
+ } catch (ClassNotFoundException e) {
+ String msg = enforcementServiceClassName + " not found";
+ log.error(msg, e);
+ throw new EnforcementServiceManagerException(msg, e);
+ } catch (NoSuchMethodException e) {
+ String msg = Constants.METHOD_NAME_GET_INSTANCE + " not found in " + enforcementServiceClassName;
+ log.error(msg, e);
+ throw new EnforcementServiceManagerException(msg, e);
+ } catch (InvocationTargetException e) {
+ String msg = "Error occurred while invoking " + Constants.METHOD_NAME_GET_INSTANCE + " in "
+ + enforcementServiceClassName;
+ log.error(msg, e);
+ throw new EnforcementServiceManagerException(msg, e);
+ } catch (IllegalAccessException e) {
+ String msg = "Can't access the method " + Constants.METHOD_NAME_GET_INSTANCE + " in "
+ + enforcementServiceClassName;
+ log.error(msg, e);
+ throw new EnforcementServiceManagerException(msg, e);
+ }
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/ExchangeOnlineCEAEnforcementServiceImpl.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/ExchangeOnlineCEAEnforcementServiceImpl.java
new file mode 100644
index 0000000000..84eb6afe47
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/ExchangeOnlineCEAEnforcementServiceImpl.java
@@ -0,0 +1,629 @@
+/*
+ * 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.enforce.Impl;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncDevice;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServer;
+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.MailboxProfile;
+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.WebOutlookAccessPolicy;
+import io.entgra.device.mgt.core.cea.mgt.common.exception.CEAEnforcementException;
+import io.entgra.device.mgt.core.cea.mgt.common.service.CEAEnforcementService;
+import io.entgra.device.mgt.core.cea.mgt.common.util.Constants;
+import io.entgra.device.mgt.core.cea.mgt.common.util.EASMgtUtil;
+import io.entgra.device.mgt.core.cea.mgt.enforce.Impl.gateway.ExchangeOnlineGatewayServiceImpl;
+import io.entgra.device.mgt.core.cea.mgt.enforce.bean.ExoPowershellCommand;
+import io.entgra.device.mgt.core.cea.mgt.enforce.bean.PowershellCommand;
+import io.entgra.device.mgt.core.cea.mgt.enforce.bean.PowershellRequest;
+import io.entgra.device.mgt.core.cea.mgt.enforce.bean.PowershellResponse;
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.GatewayServiceException;
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.PowershellExecutionException;
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.UnsupportedOsException;
+import io.entgra.device.mgt.core.cea.mgt.enforce.service.gateway.GatewayService;
+import io.entgra.device.mgt.core.cea.mgt.enforce.util.DeviceMgtUtil;
+import io.entgra.device.mgt.core.cea.mgt.enforce.util.annotation.Enforce;
+import io.entgra.device.mgt.core.cea.mgt.enforce.util.shell.Powershell;
+import io.entgra.device.mgt.core.cea.mgt.enforce.util.shell.parser.Parser;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.user.api.UserStoreException;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementService {
+ private static final Log log = LogFactory.getLog(ExchangeOnlineCEAEnforcementServiceImpl.class);
+ private static volatile ExchangeOnlineCEAEnforcementServiceImpl INSTANCE;
+ private final GatewayService gatewayService;
+ private final Powershell powershell;
+
+ ExchangeOnlineCEAEnforcementServiceImpl() throws UnsupportedOsException {
+ gatewayService = new ExchangeOnlineGatewayServiceImpl();
+ powershell = Powershell.getPowershell();
+ }
+
+ public static ExchangeOnlineCEAEnforcementServiceImpl getInstance() throws UnsupportedOsException {
+ if (INSTANCE == null) {
+ synchronized (ExchangeOnlineCEAEnforcementServiceImpl.class) {
+ if (INSTANCE == null) {
+ INSTANCE = new ExchangeOnlineCEAEnforcementServiceImpl();
+ }
+ }
+ }
+ return INSTANCE;
+ }
+
+ @Enforce
+ public void enforceDefaultAccessPolicy(CEAPolicy ceaPolicy) throws CEAEnforcementException {
+ try {
+ PowershellCommand setActiveSyncOrganizationSettings = getCommand(Parser.
+ COMMAND_SetActiveSyncOrganizationSettings.COMMAND, ceaPolicy.getActiveSyncServer());
+ setActiveSyncOrganizationSettings.addOption(Parser.COMMAND_SetActiveSyncOrganizationSettings.
+ PARAMETER_DefaultAccessLevel,
+ Parser.COMMAND_SetActiveSyncOrganizationSettings.POLICY_TO_VALUE.
+ get(ceaPolicy.getAccessPolicy().getDefaultAccessPolicy().toString()));
+ PowershellResponse powershellResponse = powershell.execute(getPowershellRequest(setActiveSyncOrganizationSettings));
+ if (powershellResponse.isSuccess()) {
+ log.info("Default access policy successfully enforced for " + ceaPolicy.getTenantId());
+ } else {
+ log.error("Default access policy enforcement procedure failed for " + ceaPolicy.getTenantId());
+ }
+ } catch (GatewayServiceException e) {
+ String msg = "Active sync gateway service failed while enforcing default CEA access policy";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ } catch (PowershellExecutionException e) {
+ String msg = "Error occurred while executing powershell command for enforcing " +
+ "CEA access policy";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ }
+ }
+
+ @Enforce
+ public void enforceEmailOutlookAccessPolicy(CEAPolicy ceaPolicy) throws CEAEnforcementException {
+ Set emailOutlookAccessPolicies = ceaPolicy.getAccessPolicy().getEmailOutlookAccessPolicy();
+ if (emailOutlookAccessPolicies.contains(EmailOutlookAccessPolicy.NOT_CONFIGURED)) {
+ if (log.isDebugEnabled()) {
+ log.debug("CEA email outlook policy not configured, but the support is available in " +
+ ExchangeOnlineCEAEnforcementServiceImpl.class);
+ }
+ return;
+ }
+ ActiveSyncServer activeSyncServer = ceaPolicy.getActiveSyncServer();
+ try {
+ PowershellCommand setCASMailbox = getCommand(Parser.COMMAND_SetCASMailbox.COMMAND,
+ activeSyncServer);
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_Identity, "$_.Identity");
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_OutlookMobileEnabled, Parser.TRUE);
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_MacOutlookEnabled, Parser.TRUE);
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_OneWinNativeOutlookEnabled, Parser.TRUE);
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_EwsAllowMacOutlook, Parser.TRUE);
+
+ if (emailOutlookAccessPolicies.contains(EmailOutlookAccessPolicy.MOBILE_OUTLOOK_BLOCK)) {
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_OutlookMobileEnabled,
+ Parser.COMMAND_SetCASMailbox.POLICY_TO_VALUE.get(EmailOutlookAccessPolicy.MOBILE_OUTLOOK_BLOCK.toString()));
+ }
+
+ if (emailOutlookAccessPolicies.contains(EmailOutlookAccessPolicy.MAC_OUTLOOK_BLOCK)) {
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_MacOutlookEnabled,
+ Parser.COMMAND_SetCASMailbox.POLICY_TO_VALUE.get(EmailOutlookAccessPolicy.MAC_OUTLOOK_BLOCK.toString()));
+ }
+
+ if (emailOutlookAccessPolicies.contains(EmailOutlookAccessPolicy.WINDOWS_OUTLOOK_BLOCK)) {
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_OneWinNativeOutlookEnabled,
+ Parser.COMMAND_SetCASMailbox.POLICY_TO_VALUE.get(EmailOutlookAccessPolicy.WINDOWS_OUTLOOK_BLOCK.toString()));
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_EwsAllowMacOutlook,
+ Parser.COMMAND_SetCASMailbox.POLICY_TO_VALUE.get(EmailOutlookAccessPolicy.MAC_OLD_OUTLOOK_BLOCK.toString()));
+ }
+
+ PowershellResponse powershellResponse = powershell.execute(getPowershellRequest(
+ toAllMailboxesCommand(setCASMailbox, activeSyncServer)));
+ if (powershellResponse.isSuccess()) {
+ log.info("Email outlook access policy successfully enforced for " + ceaPolicy.getTenantId());
+ } else {
+ log.error("Email outlook access policy enforcement procedure failed for " + ceaPolicy.getTenantId());
+ }
+ } catch (GatewayServiceException e) {
+ String msg = "Active sync auth service failed while enforcing default " +
+ "CEA email outlook access policy";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ } catch (PowershellExecutionException e) {
+ String msg = "Error occurred while executing powershell command for enforcing " +
+ "CEA email outlook access policy";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ }
+ }
+
+ @Enforce
+ public void enforcePOPIMAPAccessPolicy(CEAPolicy ceaPolicy) throws CEAEnforcementException {
+ if (ceaPolicy.getAccessPolicy().getPOPIMAPAccessPolicy().
+ equalsName(EmailOutlookAccessPolicy.NOT_CONFIGURED.name())) {
+ if (log.isDebugEnabled()) {
+ log.debug("CEA POP/IMAP policy not configured, but support is available in " +
+ ExchangeOnlineCEAEnforcementServiceImpl.class);
+ }
+ return;
+ }
+ ActiveSyncServer activeSyncServer = ceaPolicy.getActiveSyncServer();
+ try {
+ PowershellCommand setCASMailbox = getCommand(Parser.COMMAND_SetCASMailbox.COMMAND,
+ activeSyncServer);
+ String POPIMAPPolicy = ceaPolicy.getAccessPolicy().getPOPIMAPAccessPolicy().toString();
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_Identity, "$_.Identity");
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_ImapEnabled,
+ Parser.COMMAND_SetCASMailbox.POLICY_TO_VALUE.get(POPIMAPPolicy));
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_PopEnabled,
+ Parser.COMMAND_SetCASMailbox.POLICY_TO_VALUE.get(POPIMAPPolicy));
+ PowershellResponse powershellResponse = powershell.execute(getPowershellRequest(
+ toAllMailboxesCommand(setCASMailbox, activeSyncServer)));
+ if (powershellResponse.isSuccess()) {
+ log.info("POP/IMAP access policy successfully enforced for " + ceaPolicy.getTenantId());
+ } else {
+ log.error("POP/IMAP access policy enforcement procedure failed for " + ceaPolicy.getTenantId());
+ }
+ } catch (GatewayServiceException e) {
+ String msg = "Active sync auth service failed while enforcing default CEA POP/IMAP policy";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ } catch (PowershellExecutionException e) {
+ String msg = "Error occurred while executing powershell command for enforcing " +
+ "CEA POP/IMAP policy";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ }
+ }
+
+ @Enforce
+ public void enforceWebOutlookAccessPolicy(CEAPolicy ceaPolicy) throws CEAEnforcementException {
+ if (ceaPolicy.getAccessPolicy().getWebOutlookAccessPolicy().
+ equalsName(WebOutlookAccessPolicy.NOT_CONFIGURED.name())) {
+ if (log.isDebugEnabled()) {
+ log.debug("CEA Outlook web access policy not configured, but support is available in " +
+ ExchangeOnlineCEAEnforcementServiceImpl.class);
+ }
+ return;
+ }
+ ActiveSyncServer activeSyncServer = ceaPolicy.getActiveSyncServer();
+ try {
+ PowershellCommand setCASMailbox = getCommand(Parser.COMMAND_SetCASMailbox.COMMAND,
+ activeSyncServer);
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_Identity, "$_.Identity");
+ setCASMailbox.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_OWAEnabled,
+ Parser.COMMAND_SetCASMailbox.POLICY_TO_VALUE.get(ceaPolicy.getAccessPolicy().
+ getWebOutlookAccessPolicy().toString()));
+ PowershellResponse powershellResponse = powershell.execute(getPowershellRequest(
+ toAllMailboxesCommand(setCASMailbox, activeSyncServer)));
+ if (powershellResponse.isSuccess()) {
+ log.info("Web outlook access policy successfully enforced for " + ceaPolicy.getTenantId());
+ } else {
+ log.error("Web outlook access policy enforcement procedure failed for " + ceaPolicy.getTenantId());
+ }
+ } catch (GatewayServiceException e) {
+ String msg = "Active sync auth service failed while enforcing CEA web outlook access policy";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ } catch (PowershellExecutionException e) {
+ String msg = "Error occurred while executing powershell command for enforcing " +
+ "CEA web outlook access policy";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ }
+ }
+
+ @Enforce
+ public void enforceConditionalAccessPolicy(CEAPolicy ceaPolicy) throws CEAEnforcementException {
+ GracePeriod gracePeriod = ceaPolicy.getGracePeriod();
+ ActiveSyncServer activeSyncServer = ceaPolicy.getActiveSyncServer();
+ boolean isSynced = ceaPolicy.isSynced();
+ Date created = ceaPolicy.getCreated();
+ Date lastSynced = ceaPolicy.getLastSynced();
+
+ /*
+ * Here we are filtering the devices(active sync devices) which are communicating
+ * with the exchange online server into valid and not valid categories.
+ * Valid category can contain devices which are currently managed by UEM or devices
+ * which are syncing with the exchange online server under a grace period.
+ * */
+
+ try {
+ /* Get the devices based on the last sync timestamp or cea policy created
+ * time to avoid unnecessary device bulks.
+ * */
+ List validActiveSyncDevices = isSynced ? DeviceMgtUtil.
+ getEnrolledActiveSyncDevices(lastSynced, false) :
+ DeviceMgtUtil.getEnrolledActiveSyncDevices(new Date(), true);
+ List notValidActiveSyncDevices = new ArrayList<>();
+
+ List connectedActiveSyncDevices = isSynced ?
+ getConnectedActiveSyncDevicesAfter(lastSynced, activeSyncServer) :
+ getAllConnectedActiveSyncDevices(activeSyncServer);
+ for (ActiveSyncDevice activeSyncDevice : connectedActiveSyncDevices) {
+ if (!EASMgtUtil.isManageByUEM(activeSyncDevice.getDeviceId())
+ && !validActiveSyncDevices.contains(activeSyncDevice)) {
+ notValidActiveSyncDevices.add(activeSyncDevice);
+ } else {
+ validActiveSyncDevices.add(activeSyncDevice);
+ }
+ }
+
+ if (gracePeriod.getGraceAllowedPolicy().equalsName(GraceAllowedPolicy.NOT_ALLOWED.name())) {
+ // Block grace offered new devices if exists
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.DAY_OF_MONTH, -Constants.MAX_GRACE_PERIOD_IN_DAYS);
+ List graceExceededNewlyConnectedActiveSyncDevices =
+ getConnectedActiveSyncDevicesAfter(calendar.getTime(), activeSyncServer);
+ List managedDevices = DeviceMgtUtil.getEnrolledActiveSyncDevices(calendar.getTime(), false);
+ categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
+ graceExceededNewlyConnectedActiveSyncDevices, managedDevices, gracePeriod, false);
+
+ // Block grace offered existing devices if exists
+ List connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy =
+ getConnectedActiveSyncDevicesBefore(created, activeSyncServer);
+ categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
+ connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy, validActiveSyncDevices, gracePeriod, false);
+ }
+
+ if (gracePeriod.getGraceAllowedPolicy().equalsName(GraceAllowedPolicy.NEW_AND_EXISTING.name()) ||
+ gracePeriod.getGraceAllowedPolicy().equalsName(GraceAllowedPolicy.NEW_ONLY.name())) {
+
+ List newlyConnectedActiveSyncDevices =
+ getConnectedActiveSyncDevicesAfter(isSynced ? lastSynced : created, activeSyncServer);
+ categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
+ newlyConnectedActiveSyncDevices, validActiveSyncDevices, gracePeriod, true);
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.DAY_OF_MONTH, -Constants.MAX_GRACE_PERIOD_IN_DAYS);
+ List graceExceededNewlyConnectedActiveSyncDevices =
+ getConnectedActiveSyncDevicesAfter(calendar.getTime(), activeSyncServer);
+ List managedDevices = DeviceMgtUtil.getEnrolledActiveSyncDevices(calendar.getTime(), false);
+ categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
+ graceExceededNewlyConnectedActiveSyncDevices, managedDevices, gracePeriod, true);
+ }
+
+ if (gracePeriod.getGraceAllowedPolicy().equalsName(GraceAllowedPolicy.NEW_AND_EXISTING.name()) ||
+ gracePeriod.getGraceAllowedPolicy().equalsName(GraceAllowedPolicy.EXISTING_ONLY.name())) {
+ List connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy =
+ getConnectedActiveSyncDevicesBefore(created, activeSyncServer);
+ categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
+ connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy, validActiveSyncDevices, gracePeriod, true);
+ }
+
+ List mailboxProfiles = generateMailboxProfiles(validActiveSyncDevices,
+ notValidActiveSyncDevices);
+ for (MailboxProfile mailboxProfile : mailboxProfiles) {
+ PowershellCommand powershellCommand = getCommand(Parser.COMMAND_SetCASMailbox.COMMAND, activeSyncServer);
+ powershellCommand.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_Identity, mailboxProfile.getIdentity());
+ powershellCommand.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_ActiveSyncAllowedDeviceIDs,
+ mailboxProfile.getAllowedEASIdentifierString());
+ powershellCommand.addOption(Parser.COMMAND_SetCASMailbox.PARAMETER_ActiveSyncBlockedDeviceIDs,
+ mailboxProfile.getBlockedEASIdentifierString());
+ powershell.execute(getPowershellRequest(powershellCommand));
+ }
+ } catch (GatewayServiceException e) {
+ String msg = "Active sync auth service failed while enforcing CEA policy";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ } catch (PowershellExecutionException e) {
+ String msg = "Error occurred while executing powershell command for enforcing CEA policy";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ } catch (DeviceManagementException | UserStoreException e) {
+ String msg = "Error occurred while retrieving active sync devices";
+ log.error(msg, e);
+ throw new CEAEnforcementException(msg, e);
+ }
+ }
+
+ /**
+ * Categorize active sync devices into valid and not valid
+ * @param validActiveSyncDevices Valid active sync devices
+ * @param notValidActiveSyncDevices Not valid active sync devices
+ * @param deviceList Device list to filter
+ * @param managedList Already managing devices from UEM
+ * @param gracePeriod Grace period to consider
+ * @param allowGrace Whether to allow grace or not
+ */
+ private void categorizeDevices(List validActiveSyncDevices, List notValidActiveSyncDevices,
+ List deviceList, List managedList, GracePeriod gracePeriod, boolean allowGrace) {
+ for (ActiveSyncDevice activeSyncDevice : deviceList) {
+ if (!EASMgtUtil.isManageByUEM(activeSyncDevice.getDeviceId())
+ && !managedList.contains(activeSyncDevice)) {
+ if (allowGrace) {
+ filterDeviceBasedOnGrace(activeSyncDevice, validActiveSyncDevices, notValidActiveSyncDevices, gracePeriod);
+ } else {
+ validActiveSyncDevices.remove(activeSyncDevice);
+ notValidActiveSyncDevices.add(activeSyncDevice);
+ }
+ } else {
+ // These devices are managed by UEM, so add to the valid category
+ notValidActiveSyncDevices.remove(activeSyncDevice);
+ validActiveSyncDevices.add(activeSyncDevice);
+ }
+ }
+ }
+
+ /**
+ * Filter active sync device based on grace period
+ * @param activeSyncDevice Active sync device
+ * @param validActiveSyncDevices Valid active sync device list
+ * @param notValidActiveSyncDevices Not valid active sync device list
+ * @param gracePeriod Grace period to consider
+ */
+ private void filterDeviceBasedOnGrace(ActiveSyncDevice activeSyncDevice, List validActiveSyncDevices,
+ List notValidActiveSyncDevices, GracePeriod gracePeriod) {
+ long timeDiff = Math.abs(new Date().getTime() - activeSyncDevice.getFirstSyncTime().getTime());
+ // Enforce the grace period if the device not exceeds the grace limit
+ if (TimeUnit.DAYS.convert(timeDiff, TimeUnit.MILLISECONDS) < gracePeriod.getGracePeriod()) {
+ notValidActiveSyncDevices.remove(activeSyncDevice);
+ validActiveSyncDevices.add(activeSyncDevice);
+ } else {
+ validActiveSyncDevices.remove(activeSyncDevice);
+ notValidActiveSyncDevices.add(activeSyncDevice);
+ }
+ }
+
+ /**
+ * Generate powershell command {@link PowershellCommand} from command string
+ * @param command Powershell command string
+ * @param activeSyncServer {@link ActiveSyncServer}
+ * @return {@link PowershellCommand}
+ * @throws GatewayServiceException Throws when error occurred while retrieving access token
+ */
+ private PowershellCommand getCommand(String command, ActiveSyncServer activeSyncServer)
+ throws GatewayServiceException {
+ String[] urlParts = activeSyncServer.getGatewayUrl().split("/");
+ ExoPowershellCommand.ExoPowershellCommandBuilder commandBuilder =
+ new ExoPowershellCommand.ExoPowershellCommandBuilder(command);
+ commandBuilder.accessToken(gatewayService.acquireAccessToken(activeSyncServer))
+ .organization(urlParts[urlParts.length - 1]);
+ return commandBuilder.build();
+ }
+
+ /**
+ * Wrap powershell command to effect all mailboxes in active sync server
+ * @param command {@link PowershellCommand} command to wrap
+ * @param activeSyncServer {@link ActiveSyncServer}
+ * @return {@link PowershellCommand}
+ * @throws GatewayServiceException Throws when error occurred while retrieving access token
+ */
+ private PowershellCommand toAllMailboxesCommand(PowershellCommand command,
+ ActiveSyncServer activeSyncServer) throws GatewayServiceException {
+ PowershellCommand getEXOMailbox = getCommand(Parser.COMMAND_GetEXOMailbox.COMMAND, activeSyncServer);
+ getEXOMailbox.addOption(Parser.COMMAND_GetEXOMailbox.PARAMETER_ResultSize, "unlimited");
+ PowershellCommand forEach = getCommand(Parser.COMMAND_ForEach.COMMAND, activeSyncServer);
+ forEach.addOption(Parser.COMMAND_ForEach.PARAMETER_Begin, "$upn = $_.UserPrincipalName;" + command.constructFullCommand());
+ forEach.addOption(Parser.COMMAND_ForEach.PARAMETER_End, "");
+ getEXOMailbox.pipe(forEach);
+ getEXOMailbox.setConvertToJson(false);
+ return getEXOMailbox;
+ }
+
+ /**
+ * Create new powershell request to execute via powershell binaries
+ * @param command {@link PowershellCommand}
+ * @return {@link PowershellRequest}
+ */
+ private PowershellRequest getPowershellRequest(PowershellCommand command) {
+ PowershellRequest powershellRequest = new PowershellRequest();
+ powershellRequest.setCommand(command);
+ return powershellRequest;
+ }
+
+ /**
+ * Generate mailbox profiles from active sync block and allowed devices
+ * @param activeSyncAllowedDevices Active sync allowed device list
+ * @param activeSyncBlockedDevices Active sync blocked device list
+ * @return List of {@link MailboxProfile}
+ */
+ private List generateMailboxProfiles(List activeSyncAllowedDevices,
+ List activeSyncBlockedDevices) {
+ List mailboxProfiles = new ArrayList<>();
+ MailboxProfile mailboxProfile;
+ for (ActiveSyncDevice activeSyncDevice : activeSyncAllowedDevices) {
+ mailboxProfile = new MailboxProfile();
+ mailboxProfile.setIdentity(activeSyncDevice.getUserPrincipalName());
+ if (mailboxProfiles.contains(mailboxProfile)) {
+ MailboxProfile existingMailboxProfile = mailboxProfiles.get(mailboxProfiles.indexOf(mailboxProfile));
+ existingMailboxProfile.addActiveSyncAllowedEASIdentifier(activeSyncDevice.getDeviceId());
+ } else {
+ mailboxProfile.addActiveSyncAllowedEASIdentifier(activeSyncDevice.getDeviceId());
+ mailboxProfiles.add(mailboxProfile);
+ }
+ }
+
+ for (ActiveSyncDevice activeSyncDevice : activeSyncBlockedDevices) {
+ mailboxProfile = new MailboxProfile();
+ mailboxProfile.setIdentity(activeSyncDevice.getUserPrincipalName());
+ if (mailboxProfiles.contains(mailboxProfile)) {
+ MailboxProfile existingMailboxProfile = mailboxProfiles.get(mailboxProfiles.indexOf(mailboxProfile));
+ existingMailboxProfile.addActiveSyncBlockEASIdentifier(activeSyncDevice.getDeviceId());
+ } else {
+ mailboxProfile.addActiveSyncBlockEASIdentifier(activeSyncDevice.getDeviceId());
+ mailboxProfiles.add(mailboxProfile);
+ }
+ }
+ return mailboxProfiles;
+ }
+
+ /**
+ * Construct active sync device list from powershell response
+ * @param powershellResponse Shell response return from powershell binary
+ * @return List of {@link ActiveSyncDevice}
+ * @throws CEAEnforcementException Throws when error occurred while generating the device list
+ */
+ private List constructActiveSyncDeviceList(PowershellResponse powershellResponse)
+ throws CEAEnforcementException {
+ if (powershellResponse == null) {
+ throw new CEAEnforcementException("Powershell response can't be null");
+ }
+
+ if (!powershellResponse.isSuccess()) {
+ throw new CEAEnforcementException("Powershell request failed while getting active sync devices");
+ }
+
+ if (powershellResponse.getResponseBody() == null) {
+ return Collections.emptyList();
+ }
+
+ if (!powershellResponse.getResponseBody().isJsonArray()) {
+ throw new CEAEnforcementException("Unexpected result retrieve when getting active sync devices");
+ }
+
+ SimpleDateFormat powershellDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+ List activeSyncDevices = new ArrayList<>();
+
+ JsonArray elements = powershellResponse.getResponseBody().getAsJsonArray();
+ JsonObject deviceJsonObject;
+ ActiveSyncDevice activeSyncDevice;
+ for (JsonElement element : elements) {
+ try {
+ deviceJsonObject = element.getAsJsonObject();
+ activeSyncDevice = new ActiveSyncDevice();
+ activeSyncDevice.setUserPrincipalName(deviceJsonObject.get("UserPrincipalName").getAsString());
+ activeSyncDevice.setDeviceId(deviceJsonObject.get("DeviceID").getAsString());
+ activeSyncDevice.setIdentity(deviceJsonObject.get("Identity").getAsString());
+ activeSyncDevice.setFirstSyncTime(powershellDateFormat.parse(deviceJsonObject.get("FirstSyncTime").getAsString()));
+ activeSyncDevices.add(activeSyncDevice);
+ } catch (ParseException e) {
+ throw new CEAEnforcementException("Error occurred while parsing active sync device json element");
+ }
+ }
+ return activeSyncDevices;
+ }
+
+ /**
+ * Get active sync devices, which are connected with active sync server after a certain timestamp
+ * @param after Timestamp to retrieve connected devices
+ * @param activeSyncServer {@link ActiveSyncServer}
+ * @return List of {@link ActiveSyncDevice}
+ * @throws GatewayServiceException Throws when error occurred while retrieving access token
+ * @throws PowershellExecutionException Throws when error occurred while executing the powershell command
+ * @throws CEAEnforcementException Throws when error occurred while constructing device list
+ */
+ private List getConnectedActiveSyncDevicesAfter(Date after, ActiveSyncServer activeSyncServer)
+ throws GatewayServiceException, PowershellExecutionException, CEAEnforcementException {
+ SimpleDateFormat powershellDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+ PowershellCommand getEXOMobileDeviceStatistics = getCommand(Parser.COMMAND_GetEXOMobileDeviceStatistics.COMMAND,
+ activeSyncServer);
+ getEXOMobileDeviceStatistics.addOption(Parser.COMMAND_GetEXOMobileDeviceStatistics.PARAMETER_ActiveSync, "");
+ getEXOMobileDeviceStatistics.addOption(
+ Parser.COMMAND_GetEXOMobileDeviceStatistics.PARAMETER_Mailbox, "$_.Identity");
+
+ PowershellCommand selectObject = getCommand(Parser.COMMAND_SelectObject.COMMAND, activeSyncServer);
+ selectObject.addOption("@{label='UserPrincipalName' ; expression={$upn}},FirstSyncTime, DeviceID, Identity", "");
+
+ PowershellCommand whereObject = getCommand(Parser.COMMAND_WhereObject.COMMAND, activeSyncServer);
+ whereObject.addOption(Parser.COMMAND_WhereObject.PARAMETER_Begin, "$_.FirstSyncTime -gt "
+ + "'" + powershellDateFormat.format(after) + "'");
+ whereObject.addOption(Parser.COMMAND_WhereObject.PARAMETER_End, "");
+
+ PowershellCommand convertToJson = getCommand(Parser.COMMAND_ConvertToJson.COMMAND, activeSyncServer);
+ convertToJson.addOption(Parser.COMMAND_ConvertToJson.PARAMETER_AsArray, "");
+ getEXOMobileDeviceStatistics.pipe(selectObject).pipe(whereObject).pipe(convertToJson);
+
+ PowershellCommand toAllMailboxes = toAllMailboxesCommand(getEXOMobileDeviceStatistics, activeSyncServer);
+ PowershellRequest powershellRequest = getPowershellRequest(toAllMailboxes);
+ PowershellResponse powershellResponse = powershell.execute(powershellRequest);
+ return constructActiveSyncDeviceList(powershellResponse);
+ }
+
+ /**
+ * Get active sync devices, which are connected with active sync server before a certain timestamp
+ * @param before Timestamp to retrieve connected devices
+ * @param activeSyncServer {@link ActiveSyncServer}
+ * @return List of {@link ActiveSyncDevice}
+ * @throws GatewayServiceException Throws when error occurred while retrieving access token
+ * @throws PowershellExecutionException Throws when error occurred while executing the powershell command
+ * @throws CEAEnforcementException Throws when error occurred while constructing device list
+ */
+ private List getConnectedActiveSyncDevicesBefore(Date before, ActiveSyncServer activeSyncServer)
+ throws GatewayServiceException, PowershellExecutionException, CEAEnforcementException {
+ SimpleDateFormat powershellDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+ PowershellCommand getEXOMobileDeviceStatistics = getCommand(Parser.COMMAND_GetEXOMobileDeviceStatistics.COMMAND,
+ activeSyncServer);
+ getEXOMobileDeviceStatistics.addOption(Parser.COMMAND_GetEXOMobileDeviceStatistics.PARAMETER_ActiveSync, "");
+ getEXOMobileDeviceStatistics.addOption(
+ Parser.COMMAND_GetEXOMobileDeviceStatistics.PARAMETER_Mailbox, "$_.Identity");
+
+ PowershellCommand selectObject = getCommand(Parser.COMMAND_SelectObject.COMMAND, activeSyncServer);
+ selectObject.addOption("@{label='UserPrincipalName' ; expression={$upn}},FirstSyncTime, DeviceID, Identity", "");
+
+ PowershellCommand whereObject = getCommand(Parser.COMMAND_WhereObject.COMMAND, activeSyncServer);
+ whereObject.addOption(Parser.COMMAND_WhereObject.PARAMETER_Begin, "$_.FirstSyncTime -lt "
+ + "'" + powershellDateFormat.format(before) + "'");
+ whereObject.addOption(Parser.COMMAND_WhereObject.PARAMETER_End, "");
+
+ PowershellCommand convertToJson = getCommand(Parser.COMMAND_ConvertToJson.COMMAND, activeSyncServer);
+ convertToJson.addOption(Parser.COMMAND_ConvertToJson.PARAMETER_AsArray, "");
+ getEXOMobileDeviceStatistics.pipe(selectObject).pipe(whereObject).pipe(convertToJson);
+
+ PowershellCommand toAllMailboxes = toAllMailboxesCommand(getEXOMobileDeviceStatistics, activeSyncServer);
+ PowershellRequest powershellRequest = getPowershellRequest(toAllMailboxes);
+ PowershellResponse powershellResponse = powershell.execute(powershellRequest);
+ return constructActiveSyncDeviceList(powershellResponse);
+ }
+
+ /**
+ * Get all connected active sync devices from active sync server
+ * @param activeSyncServer {@link ActiveSyncServer}
+ * @return List of {@link ActiveSyncDevice}
+ * @throws GatewayServiceException Throws when error occurred while retrieving access token
+ * @throws PowershellExecutionException Throws when error occurred while executing the powershell command
+ * @throws CEAEnforcementException Throws when error occurred while constructing device list
+ */
+ private List getAllConnectedActiveSyncDevices(ActiveSyncServer activeSyncServer)
+ throws GatewayServiceException, PowershellExecutionException, CEAEnforcementException {
+ PowershellCommand getEXOMobileDeviceStatistics = getCommand(Parser.COMMAND_GetEXOMobileDeviceStatistics.COMMAND,
+ activeSyncServer);
+ getEXOMobileDeviceStatistics.addOption(Parser.COMMAND_GetEXOMobileDeviceStatistics.PARAMETER_ActiveSync, "");
+ getEXOMobileDeviceStatistics.addOption(
+ Parser.COMMAND_GetEXOMobileDeviceStatistics.PARAMETER_Mailbox, "$_.Identity");
+
+ PowershellCommand convertToJson = getCommand(Parser.COMMAND_ConvertToJson.COMMAND, activeSyncServer);
+ convertToJson.addOption(Parser.COMMAND_ConvertToJson.PARAMETER_AsArray, "");
+
+ PowershellCommand selectObject = getCommand(Parser.COMMAND_SelectObject.COMMAND, activeSyncServer);
+ selectObject.addOption("@{label='UserPrincipalName' ; expression={$upn}},FirstSyncTime, DeviceID, Identity", "");
+
+ getEXOMobileDeviceStatistics.pipe(selectObject).pipe(convertToJson);
+
+ PowershellCommand toAllMailboxes = toAllMailboxesCommand(getEXOMobileDeviceStatistics, activeSyncServer);
+ PowershellRequest powershellRequest = getPowershellRequest(toAllMailboxes);
+ PowershellResponse powershellResponse = powershell.execute(powershellRequest);
+ return constructActiveSyncDeviceList(powershellResponse);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/gateway/ExchangeOnlineGatewayServiceImpl.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/gateway/ExchangeOnlineGatewayServiceImpl.java
new file mode 100644
index 0000000000..5b2b8b6772
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/Impl/gateway/ExchangeOnlineGatewayServiceImpl.java
@@ -0,0 +1,105 @@
+/*
+ * 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.enforce.Impl.gateway;
+
+import com.microsoft.aad.msal4j.ClientCredentialFactory;
+import com.microsoft.aad.msal4j.ClientCredentialParameters;
+import com.microsoft.aad.msal4j.ConfidentialClientApplication;
+import com.microsoft.aad.msal4j.IAuthenticationResult;
+import com.microsoft.aad.msal4j.IClientCredential;
+import com.microsoft.aad.msal4j.IConfidentialClientApplication;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServer;
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.GatewayServiceException;
+import io.entgra.device.mgt.core.cea.mgt.enforce.service.gateway.GatewayService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.net.MalformedURLException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+
+public class ExchangeOnlineGatewayServiceImpl implements GatewayService {
+ private static final Log log = LogFactory.getLog(ExchangeOnlineGatewayServiceImpl.class);
+ private static final Set SCOPES = new HashSet<>(Collections.singletonList("https://outlook.office365.com/.default"));
+ private static final Map confidentialClientApplications = new HashMap<>();
+
+ @Override
+ public String acquireAccessToken(ActiveSyncServer activeSyncServer) throws GatewayServiceException {
+ try {
+ IConfidentialClientApplication confidentialClientApplication = getOrCreateConfidentialClientApplication(
+ activeSyncServer.getClient(), activeSyncServer.getSecret(), activeSyncServer.getGatewayUrl());
+ ClientCredentialParameters clientCredentialParameters = ClientCredentialParameters.builder(SCOPES).build();
+ IAuthenticationResult result = confidentialClientApplication.acquireToken(clientCredentialParameters).get();
+ if (log.isDebugEnabled()) {
+ log.debug("Access token acquiring process is successful");
+ }
+ return result.accessToken();
+ } catch (MalformedURLException e) {
+ String msg = "Error occurred while constructing confidential client application";
+ log.error(msg, e);
+ throw new GatewayServiceException(msg, e);
+ } catch (InterruptedException e) {
+ String msg = "Error occurred while acquiring access token";
+ log.error(msg, e);
+ throw new GatewayServiceException(msg, e);
+ } catch (ExecutionException e) {
+ String msg = "Error occurred while executing token acquiring access token";
+ log.error(msg, e);
+ throw new GatewayServiceException(msg, e);
+ }
+ }
+
+ @Override
+ public boolean validate(ActiveSyncServer activeSyncServer) throws GatewayServiceException {
+ try {
+ IConfidentialClientApplication confidentialClientApplication = getOrCreateConfidentialClientApplication(
+ activeSyncServer.getClient(), activeSyncServer.getSecret(), activeSyncServer.getGatewayUrl());
+ return confidentialClientApplication.validateAuthority();
+ } catch (MalformedURLException e) {
+ String msg = "Error occurred while constructing confidential client application";
+ log.error(msg, e);
+ throw new GatewayServiceException(msg, e);
+ }
+ }
+
+ /**
+ * Retrieve confidential client application if exists, otherwise create and retrieve
+ * @param clientId Client ID of the Azure AD application
+ * @param secret Client Secret of the Azure AD application
+ * @param authority Authority URL of the tenant which Azure AD application belongs
+ * @return {@link IConfidentialClientApplication}
+ * @throws MalformedURLException Throws when trying to set malformed authority URL
+ */
+ private IConfidentialClientApplication getOrCreateConfidentialClientApplication(String clientId, String secret, String authority)
+ throws MalformedURLException {
+ IConfidentialClientApplication confidentialClientApplication = confidentialClientApplications.get(clientId);
+ if (confidentialClientApplication == null) {
+ IClientCredential credential = ClientCredentialFactory.createFromSecret(secret);
+ confidentialClientApplication = ConfidentialClientApplication.
+ builder(clientId, credential).authority(authority).build();
+ confidentialClientApplications.put(clientId, confidentialClientApplication);
+ }
+ return confidentialClientApplication;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/ExoPowershellCommand.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/ExoPowershellCommand.java
new file mode 100644
index 0000000000..a44c2df6e6
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/ExoPowershellCommand.java
@@ -0,0 +1,85 @@
+/*
+ * 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.enforce.bean;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class ExoPowershellCommand extends PowershellCommand {
+ private static final String COMMAND_IMPORT_MODULE_EXO = "Import-Module ExchangeOnlineManagement" + SYMBOL_END_LINE;
+ private static final String COMMAND_CONVERT_TO_JSON = "ConvertTo-Json";
+ private final String accessToken;
+ private final String organization;
+
+ protected ExoPowershellCommand(String command, String accessToken, String organization) {
+ super(command);
+ this.accessToken = accessToken;
+ this.organization = organization;
+ }
+
+ public String getCommandString() {
+ List partsOfCommand = new ArrayList<>(Arrays.asList(
+ COMMAND_IMPORT_MODULE_EXO,
+ constructConnectionCommand(),
+ constructFullCommand(),
+ SYMBOL_PIPE));
+
+ if (isOutputNull) {
+ partsOfCommand.add(COMMAND_OUTPUT_NULL);
+ } else if (convertToJson) {
+ partsOfCommand.add(COMMAND_CONVERT_TO_JSON);
+ } else {
+ partsOfCommand.remove(partsOfCommand.size() - 1);
+ }
+
+ return String.join(SYMBOL_SPLITTER, partsOfCommand);
+ }
+
+ private String constructConnectionCommand() {
+ return "Connect-ExchangeOnline" +
+ " -Organization " + organization +
+ " -AccessToken " + accessToken + " -ShowBanner:$false" + SYMBOL_END_LINE;
+ }
+
+ public static class ExoPowershellCommandBuilder {
+ private final String command;
+ private String accessToken;
+ private String organization;
+
+ public ExoPowershellCommandBuilder(String command) {
+ this.command = command;
+ }
+
+ public ExoPowershellCommandBuilder accessToken(String accessToken) {
+ this.accessToken = accessToken;
+ return this;
+ }
+
+ public ExoPowershellCommandBuilder organization(String organization) {
+ this.organization = organization;
+ return this;
+ }
+
+ public ExoPowershellCommand build() {
+ return new ExoPowershellCommand(command, accessToken, organization);
+ }
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/PowershellCommand.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/PowershellCommand.java
new file mode 100644
index 0000000000..94f2ff88b6
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/PowershellCommand.java
@@ -0,0 +1,82 @@
+/*
+ * 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.enforce.bean;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public abstract class PowershellCommand {
+ protected static final String COMMAND_OUTPUT_NULL = "Out-Null;";
+ protected static final String SYMBOL_PIPE = "|";
+ protected static final String SYMBOL_SPLITTER = "&";
+ protected static final String SYMBOL_END_LINE = ";";
+ protected final String command;
+ protected final Map parameters = new HashMap<>();
+ protected boolean isOutputNull = false;
+ protected boolean convertToJson = true;
+ protected PowershellCommand pipedCommand;
+
+ public PowershellCommand(String command) {
+ this.command = command;
+ }
+
+ public boolean isOutputNull() {
+ return isOutputNull;
+ }
+
+ public void setOutputNull(boolean outputNull) {
+ isOutputNull = outputNull;
+ }
+
+ public boolean isConvertToJson() {
+ return convertToJson;
+ }
+
+ public void setConvertToJson(boolean convertToJson) {
+ this.convertToJson = convertToJson;
+ }
+
+ public void addOption(String option, String value) {
+ parameters.put(option, value);
+ }
+
+ protected String constructParameterString() {
+ List optionList = new ArrayList<>();
+ for (String option : parameters.keySet()) {
+ optionList.add(option + " " + parameters.get(option));
+ }
+ return String.join(" ", optionList);
+ }
+
+ public String constructFullCommand() {
+ String fullCommand = command + " " + constructParameterString();
+ return pipedCommand == null ? fullCommand :
+ fullCommand + SYMBOL_SPLITTER + SYMBOL_PIPE + SYMBOL_SPLITTER + pipedCommand.constructFullCommand();
+ }
+
+ public PowershellCommand pipe(PowershellCommand command) {
+ pipedCommand = command;
+ return command;
+ }
+
+ public abstract String getCommandString();
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/PowershellRequest.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/PowershellRequest.java
new file mode 100644
index 0000000000..2d5aaaaf43
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/PowershellRequest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.enforce.bean;
+
+public class PowershellRequest {
+ private PowershellCommand command;
+
+ public PowershellCommand getCommand() {
+ return command;
+ }
+
+ public void setCommand(PowershellCommand command) {
+ this.command = command;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/PowershellResponse.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/PowershellResponse.java
new file mode 100644
index 0000000000..ab9e9672c2
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/bean/PowershellResponse.java
@@ -0,0 +1,68 @@
+/*
+ * 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.enforce.bean;
+
+import com.google.gson.JsonElement;
+
+public class PowershellResponse {
+ private JsonElement responseBody;
+ private String error;
+ private int code;
+ private boolean isSuccess;
+
+ public PowershellResponse(JsonElement responseBody, String error, int code, boolean isSuccess) {
+ this.responseBody = responseBody;
+ this.error = error;
+ this.code = code;
+ this.isSuccess = isSuccess;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+ public JsonElement getResponseBody() {
+ return responseBody;
+ }
+
+ public void setResponseBody(JsonElement responseBody) {
+ this.responseBody = responseBody;
+ }
+
+ public String getError() {
+ return error;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+
+ public boolean isSuccess() {
+ return isSuccess;
+ }
+
+ public void setSuccess(boolean success) {
+ isSuccess = success;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/CEAPolicyOperationException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/CEAPolicyOperationException.java
new file mode 100644
index 0000000000..4a4e029be1
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/CEAPolicyOperationException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.enforce.exception;
+
+public class CEAPolicyOperationException extends Exception {
+ public CEAPolicyOperationException(String msg) {
+ super(msg);
+ }
+
+ public CEAPolicyOperationException(String msg, Throwable t) {
+ super(msg, t);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/GatewayServiceException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/GatewayServiceException.java
new file mode 100644
index 0000000000..2da2f452c8
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/GatewayServiceException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.enforce.exception;
+
+public class GatewayServiceException extends Exception {
+ public GatewayServiceException(String msg) {
+ super(msg);
+ }
+
+ public GatewayServiceException(String msg, Throwable t) {
+ super(msg, t);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/PowershellExecutionException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/PowershellExecutionException.java
new file mode 100644
index 0000000000..9b70d78106
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/PowershellExecutionException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.enforce.exception;
+
+public class PowershellExecutionException extends Exception {
+ public PowershellExecutionException(String msg) {
+ super(msg);
+ }
+
+ public PowershellExecutionException(String msg, Throwable t) {
+ super(msg, t);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/UnsupportedOsException.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/UnsupportedOsException.java
new file mode 100644
index 0000000000..39121d0d19
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/exception/UnsupportedOsException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.enforce.exception;
+
+public class UnsupportedOsException extends Exception {
+ public UnsupportedOsException(String msg) {
+ super(msg);
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/internal/EnforcementServiceComponent.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/internal/EnforcementServiceComponent.java
new file mode 100644
index 0000000000..d890eb62f0
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/internal/EnforcementServiceComponent.java
@@ -0,0 +1,90 @@
+/*
+ * 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.enforce.internal;
+
+import io.entgra.device.mgt.core.cea.mgt.common.service.EnforcementServiceManager;
+import io.entgra.device.mgt.core.cea.mgt.enforce.Impl.EnforcementServiceManagerImpl;
+import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.user.core.service.RealmService;
+
+/**
+ * @scr.component name="io.entgra.device.mgt.core.cea.mgt.enforcementServiceManager" immediate="true"
+ * @scr.reference name="org.wso2.carbon.device.manager"
+ * interface="io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setDeviceManagementServiceProviderService"
+ * unbind="unsetDeviceManagementServiceProviderService"
+ * @scr.reference name="user.realmservice.default"
+ * interface="org.wso2.carbon.user.core.service.RealmService"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setRealmService"
+ * unbind="unsetRealmService"
+ */
+
+public class EnforcementServiceComponent {
+ private static final Log log = LogFactory.getLog(EnforcementServiceComponent.class);
+
+ protected void activate(ComponentContext componentContext) {
+ try {
+ EnforcementServiceManager enforcementServiceManager = new EnforcementServiceManagerImpl();
+ componentContext.getBundleContext().registerService(EnforcementServiceManager.class.getName(),
+ enforcementServiceManager, null);
+ if (log.isDebugEnabled()) {
+ log.debug("Enforcement service manager initialized");
+ }
+ } catch (Throwable t) {
+ String msg = "Error occurred while activating " + EnforcementServiceComponent.class.getName();
+ log.error(msg, t);
+ }
+ }
+
+ protected void setDeviceManagementServiceProviderService(DeviceManagementProviderService deviceManagementProviderService) {
+ EnforcementServiceComponentDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
+ if (log.isDebugEnabled()) {
+ log.debug("Device management provider service is set successfully");
+ }
+ }
+
+ protected void unsetDeviceManagementServiceProviderService(DeviceManagementProviderService deviceManagementProviderService) {
+ EnforcementServiceComponentDataHolder.getInstance().setDeviceManagementProviderService(null);
+ if (log.isDebugEnabled()) {
+ log.debug("Device management provider service is unset successfully");
+ }
+ }
+
+ protected void setRealmService(RealmService realmService) {
+ EnforcementServiceComponentDataHolder.getInstance().setRealmService(realmService);
+ if (log.isDebugEnabled()) {
+ log.debug("Realm service is set successfully");
+ }
+ }
+
+ protected void unsetRealmService(RealmService realmService) {
+ EnforcementServiceComponentDataHolder.getInstance().setRealmService(null);
+ if (log.isDebugEnabled()) {
+ log.debug("Realm service is unset successfully");
+ }
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/internal/EnforcementServiceComponentDataHolder.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/internal/EnforcementServiceComponentDataHolder.java
new file mode 100644
index 0000000000..b250957915
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/internal/EnforcementServiceComponentDataHolder.java
@@ -0,0 +1,55 @@
+/*
+ * 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.enforce.internal;
+
+import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
+import org.wso2.carbon.user.core.service.RealmService;
+
+public class EnforcementServiceComponentDataHolder {
+ private DeviceManagementProviderService deviceManagementProviderService;
+ private RealmService realmService;
+
+ EnforcementServiceComponentDataHolder() {
+ }
+
+ public static EnforcementServiceComponentDataHolder getInstance() {
+ return EnforcementServiceComponentDataHolderRegistry.INSTANCE;
+ }
+
+ public DeviceManagementProviderService getDeviceManagementProviderService() {
+ return deviceManagementProviderService;
+ }
+
+ public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
+ this.deviceManagementProviderService = deviceManagementProviderService;
+ }
+
+ public RealmService getRealmService() {
+ return realmService;
+ }
+
+ public void setRealmService(RealmService realmService) {
+ this.realmService = realmService;
+ }
+
+ private static class EnforcementServiceComponentDataHolderRegistry {
+ public static final EnforcementServiceComponentDataHolder INSTANCE = new EnforcementServiceComponentDataHolder();
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/service/CEAPolicyOperation.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/service/CEAPolicyOperation.java
new file mode 100644
index 0000000000..ed5cb64795
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/service/CEAPolicyOperation.java
@@ -0,0 +1,31 @@
+/*
+ * 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.enforce.service;
+
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.CEAPolicyOperationException;
+
+public interface CEAPolicyOperation {
+ /**
+ * Sync with the active sync server and enforce the conditional access policy
+ *
+ * @throws CEAPolicyOperationException Throws when error occurred while performing enforcement operations
+ */
+ void enforce() throws CEAPolicyOperationException;
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/service/gateway/GatewayService.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/service/gateway/GatewayService.java
new file mode 100644
index 0000000000..1c53e50f72
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/service/gateway/GatewayService.java
@@ -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.enforce.service.gateway;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServer;
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.GatewayServiceException;
+
+public interface GatewayService {
+ /**
+ * Retrieve access token to invoke active sync server endpoints
+ *
+ * @param activeSyncServer {@link ActiveSyncServer}
+ * @return Obtained access token
+ * @throws GatewayServiceException Throws when error occurred while obtaining an access token
+ */
+ String acquireAccessToken(ActiveSyncServer activeSyncServer) throws GatewayServiceException;
+
+ /**
+ * Validate the access token
+ *
+ * @param activeSyncServer {@link ActiveSyncServer}
+ * @return True when the token is valid, otherwise false
+ * @throws GatewayServiceException Throws when error occurred while validating the token
+ */
+ boolean validate(ActiveSyncServer activeSyncServer) throws GatewayServiceException;
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/Constants.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/Constants.java
new file mode 100644
index 0000000000..ca82f75fa1
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/Constants.java
@@ -0,0 +1,27 @@
+/*
+ * 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.enforce.util;
+
+public class Constants {
+ public static final String EMAIL_CLAIM_URI = "http://wso2.org/claims/emailaddress";
+ public static final String DEVICE_TYPE_ANDROID = "android";
+ public static final String DEVICE_PROPERTY_EAS_ID = "EASDeviceIdentifier";
+ public static final String METHOD_NAME_GET_INSTANCE = "getInstance";
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/DeviceMgtUtil.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/DeviceMgtUtil.java
new file mode 100644
index 0000000000..714661333d
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/DeviceMgtUtil.java
@@ -0,0 +1,130 @@
+/*
+ * 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.enforce.util;
+
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncDevice;
+import io.entgra.device.mgt.core.cea.mgt.enforce.internal.EnforcementServiceComponentDataHolder;
+import io.entgra.device.mgt.core.device.mgt.common.Device;
+import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
+import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.user.api.UserStoreException;
+import org.wso2.carbon.user.api.UserStoreManager;
+import org.wso2.carbon.user.core.service.RealmService;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class DeviceMgtUtil {
+ private static final Log log = LogFactory.getLog(DeviceMgtUtil.class);
+
+ /**
+ * Retrieve enrolled devices before or after a certain timestamp
+ * @param date Timestamp to retrieve devices
+ * @param isPriorTo Whether to retrieve prior devices based on the provided timestamp
+ * @return List of {@link ActiveSyncDevice}
+ * @throws DeviceManagementException Throws when error occurred while retrieving devices
+ * @throws UserStoreException Throws when failed to obtain user details belongs to a device
+ */
+ public static List getEnrolledActiveSyncDevices(Date date, boolean isPriorTo)
+ throws DeviceManagementException, UserStoreException {
+ DeviceManagementProviderService deviceManagementProviderService =
+ EnforcementServiceComponentDataHolder.getInstance().getDeviceManagementProviderService();
+ if (deviceManagementProviderService == null) {
+ String msg = "Device management provider service has not initialized";
+ log.error(msg);
+ throw new IllegalStateException(msg);
+ }
+ List devices = isPriorTo ? deviceManagementProviderService.getEnrolledDevicesPriorTo(date) :
+ deviceManagementProviderService.getEnrolledDevicesSince(date);
+ if (devices == null) {
+ return new ArrayList<>();
+ }
+ return DeviceMgtUtil.constructActiveSyncDeviceList(devices);
+ }
+
+ private static UserStoreManager getUserStoreManager(int tenantId) throws UserStoreException {
+
+ RealmService realmService = EnforcementServiceComponentDataHolder.getInstance().getRealmService();
+ if (realmService == null) {
+ String msg = "Realm service has not initialized";
+ log.error(msg);
+ throw new IllegalStateException(msg);
+ }
+ return realmService.getTenantUserRealm(tenantId).getUserStoreManager();
+ }
+
+ /**
+ * Generate active sync device list from retrieved device list from device management service
+ * @param devices List of devices retrieved from device management service
+ * @return List of {@link ActiveSyncDevice}
+ * @throws UserStoreException Throws when failed to load user details form user store
+ */
+ private static List constructActiveSyncDeviceList(List devices)
+ throws UserStoreException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ List activeSyncDevices = new ArrayList<>();
+ UserStoreManager userStoreManager = getUserStoreManager(tenantId);
+ if (userStoreManager == null) {
+ String msg = "Retrieved null for user store manager";
+ log.error(msg);
+ throw new IllegalStateException(msg);
+ }
+
+ // filter out the android devices since android devices are resolved from the active sync server
+ devices = devices.stream().filter(device -> !Objects.equals(device.getType(), Constants.DEVICE_TYPE_ANDROID)).
+ collect(Collectors.toList());
+
+ for (Device device : devices) {
+ activeSyncDevices.add(mapToActiveSyncDevice(device, userStoreManager));
+ }
+
+ return activeSyncDevices;
+ }
+
+ /**
+ * Map devices which are retrieved from device management service to active sync devices
+ * @param device Device list retrieved from device management service
+ * @param userStoreManager {@link UserStoreManager}
+ * @return {@link ActiveSyncDevice}
+ * @throws UserStoreException Throws when failed to load user details form user store
+ */
+ public static ActiveSyncDevice mapToActiveSyncDevice(Device device, UserStoreManager userStoreManager)
+ throws UserStoreException {
+ EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo();
+ ActiveSyncDevice activeSyncDevice = new ActiveSyncDevice();
+ activeSyncDevice.setUserPrincipalName(userStoreManager.
+ getUserClaimValue(enrolmentInfo.getOwner(), Constants.EMAIL_CLAIM_URI, null));
+ if (!Objects.equals(device.getType(), Constants.DEVICE_TYPE_ANDROID)) {
+ for (Device.Property property : device.getProperties()) {
+ if (property != null && Objects.equals(property.getName(), Constants.DEVICE_PROPERTY_EAS_ID)) {
+ activeSyncDevice.setDeviceId(property.getValue());
+ }
+ }
+ }
+ return activeSyncDevice;
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/annotation/Enforce.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/annotation/Enforce.java
new file mode 100644
index 0000000000..e92be4c232
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/annotation/Enforce.java
@@ -0,0 +1,30 @@
+/*
+ * 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.enforce.util.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Enforce {
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/Powershell.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/Powershell.java
new file mode 100644
index 0000000000..23a61c683e
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/Powershell.java
@@ -0,0 +1,58 @@
+/*
+ * 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.enforce.util.shell;
+
+import io.entgra.device.mgt.core.cea.mgt.enforce.bean.PowershellRequest;
+import io.entgra.device.mgt.core.cea.mgt.enforce.bean.PowershellResponse;
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.PowershellExecutionException;
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.UnsupportedOsException;
+import io.entgra.device.mgt.core.cea.mgt.enforce.util.shell.os.LinuxPowershell;
+import io.entgra.device.mgt.core.cea.mgt.enforce.util.shell.os.MacPowershell;
+import io.entgra.device.mgt.core.cea.mgt.enforce.util.shell.os.WindowsPowershell;
+
+public interface Powershell {
+ String OS = System.getProperty("os.name").toLowerCase();
+ boolean IS_UNIX = (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0);
+ boolean IS_WINDOWS = (OS.indexOf("win") >= 0);
+ boolean IS_MAC = (OS.indexOf("mac") >= 0);
+
+ static Powershell getPowershell() throws UnsupportedOsException {
+ if (IS_UNIX) {
+ return LinuxPowershell.getInstance();
+ }
+ if (IS_WINDOWS) {
+ return WindowsPowershell.getInstance();
+ }
+ if (IS_MAC) {
+ return MacPowershell.getInstance();
+ }
+ throw new UnsupportedOsException("OS is not supported!");
+ }
+
+ /**
+ * Execute the powershell request
+ *
+ * @param powershellRequest {@link PowershellRequest}
+ * @return {@link PowershellResponse}
+ * @throws PowershellExecutionException Throws when error occurred while execution
+ */
+ PowershellResponse execute(PowershellRequest powershellRequest) throws PowershellExecutionException;
+}
+
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/AbstractPowershell.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/AbstractPowershell.java
new file mode 100644
index 0000000000..cc7304bcad
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/AbstractPowershell.java
@@ -0,0 +1,116 @@
+/*
+ * 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.enforce.util.shell.os;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import io.entgra.device.mgt.core.cea.mgt.enforce.bean.PowershellRequest;
+import io.entgra.device.mgt.core.cea.mgt.enforce.bean.PowershellResponse;
+import io.entgra.device.mgt.core.cea.mgt.enforce.exception.PowershellExecutionException;
+import io.entgra.device.mgt.core.cea.mgt.enforce.util.shell.Powershell;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.List;
+
+public class AbstractPowershell implements Powershell {
+ private static final Log log = LogFactory.getLog(AbstractPowershell.class);
+ protected static final String SYMBOL_SPLITTER = "&";
+ private static final String PARAMETER_COMMAND = "-Command";
+ private static final String COMMAND_REDIRECT_WARNINGS = "$WarningPreference = 'SilentlyContinue';";
+ private final String BINARY;
+
+ AbstractPowershell(String BINARY) {
+ this.BINARY = BINARY;
+ }
+
+ @Override
+ public PowershellResponse execute(PowershellRequest powershellRequest) throws PowershellExecutionException {
+
+ String commandString = String.join(SYMBOL_SPLITTER, Arrays.asList(BINARY, PARAMETER_COMMAND, COMMAND_REDIRECT_WARNINGS,
+ powershellRequest.getCommand().getCommandString()));
+ ProcessBuilder processBuilder = new ProcessBuilder(Arrays.asList(commandString.split(SYMBOL_SPLITTER)));
+ StringWriter standardOutputStringWriter = new StringWriter();
+ PrintWriter standardOutputPrintWriter = new PrintWriter(standardOutputStringWriter);
+ StringWriter errorStringWriter = new StringWriter();
+ PrintWriter errorPrintWriter = new PrintWriter(errorStringWriter);
+ try {
+ Process process = processBuilder.start();
+ List streamConsumerThreads = Arrays.asList(
+ new Thread(new ThreadedStreamConsumer(process.getInputStream(), standardOutputPrintWriter)),
+ new Thread(new ThreadedStreamConsumer(process.getErrorStream(), errorPrintWriter))
+ );
+
+ for (Thread streamConsumerThread : streamConsumerThreads) {
+ streamConsumerThread.start();
+ }
+ int exitCode = process.waitFor();
+
+ for (Thread streamConsumerThread : streamConsumerThreads) {
+ streamConsumerThread.join();
+ }
+ return constructResponse(exitCode, getStringContent(standardOutputStringWriter),
+ getStringContent(errorStringWriter));
+ } catch (IOException e) {
+ String msg = "IOException occurred while executing powershell command : "
+ + powershellRequest.getCommand();
+ log.error(msg, e);
+ throw new PowershellExecutionException(msg, e);
+ } catch (InterruptedException e) {
+ String msg = "Thread got interrupted while executing powershell command : "
+ + powershellRequest.getCommand();
+ log.error(msg, e);
+ throw new PowershellExecutionException(msg, e);
+ }
+ }
+
+ private PowershellResponse constructResponse(int exitCode, String standardOutput, String errorOutput) {
+ JsonElement standardOutputJson = new Gson().fromJson(standardOutput, JsonElement.class);
+ return new PowershellResponse(standardOutputJson,
+ errorOutput, exitCode, exitCode == 0);
+ }
+
+ private String getStringContent(StringWriter stringWriter) {
+ return stringWriter.getBuffer().toString().trim();
+ }
+
+ private static class ThreadedStreamConsumer implements Runnable {
+ private final InputStream inputStream;
+ private final PrintWriter printWriter;
+
+ public ThreadedStreamConsumer(InputStream inputStream, PrintWriter printWriter) {
+ this.inputStream = inputStream;
+ this.printWriter = printWriter;
+ }
+
+ @Override
+ public void run() {
+ new BufferedReader(new InputStreamReader(inputStream)).
+ lines().forEach(printWriter::println);
+ }
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/LinuxPowershell.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/LinuxPowershell.java
new file mode 100644
index 0000000000..7a1d31861c
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/LinuxPowershell.java
@@ -0,0 +1,36 @@
+/*
+ * 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.enforce.util.shell.os;
+
+public class LinuxPowershell extends AbstractPowershell {
+ private static final String BINARY = "pwsh";
+
+ LinuxPowershell() {
+ super(BINARY);
+ }
+
+ public static LinuxPowershell getInstance() {
+ return LinuxPowershellHolderRegistry.INSTANCE;
+ }
+
+ private static class LinuxPowershellHolderRegistry {
+ public static LinuxPowershell INSTANCE = new LinuxPowershell();
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/MacPowershell.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/MacPowershell.java
new file mode 100644
index 0000000000..c74ba9fd2e
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/MacPowershell.java
@@ -0,0 +1,36 @@
+/*
+ * 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.enforce.util.shell.os;
+
+public class MacPowershell extends AbstractPowershell {
+ private static final String BINARY = "pwsh";
+
+ MacPowershell() {
+ super(BINARY);
+ }
+
+ public static MacPowershell getInstance() {
+ return MacPowershell.MacPowershellHolderRegistry.INSTANCE;
+ }
+
+ private static class MacPowershellHolderRegistry {
+ public static MacPowershell INSTANCE = new MacPowershell();
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/WindowsPowershell.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/WindowsPowershell.java
new file mode 100644
index 0000000000..8e1ab76700
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/os/WindowsPowershell.java
@@ -0,0 +1,36 @@
+/*
+ * 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.enforce.util.shell.os;
+
+public class WindowsPowershell extends AbstractPowershell {
+ private static final String BINARY = "powershell.exe";
+
+ WindowsPowershell() {
+ super(BINARY);
+ }
+
+ public static WindowsPowershell getInstance() {
+ return WindowsPowershell.WindowsPowershellHolderRegistry.INSTANCE;
+ }
+
+ private static class WindowsPowershellHolderRegistry {
+ public static WindowsPowershell INSTANCE = new WindowsPowershell();
+ }
+}
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/parser/Parser.java b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/parser/Parser.java
new file mode 100644
index 0000000000..fdc4d21621
--- /dev/null
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/src/main/java/io/entgra/device/mgt/core/cea/mgt/enforce/util/shell/parser/Parser.java
@@ -0,0 +1,113 @@
+/*
+ * 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.enforce.util.shell.parser;
+
+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 java.util.Collections;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class Parser {
+ public static final String TRUE = "$true";
+ public static final String FALSE = "$false";
+ public static final String ALLOW = "ALLOW";
+ public static final String BLOCK = "BLOCK";
+
+ public static class COMMAND_SetActiveSyncOrganizationSettings {
+ public static final String COMMAND = "Set-ActiveSyncOrganizationSettings";
+ public static final String PARAMETER_DefaultAccessLevel = "-DefaultAccessLevel";
+ public static final Map POLICY_TO_VALUE = Stream.of(new String[][]{
+ {DefaultAccessPolicy.ALLOW.toString(), "Allow"},
+ {DefaultAccessPolicy.BLOCK.toString(), "Block"},
+ {DefaultAccessPolicy.QUARANTINE.toString(), "Quarantine"}
+ }).collect(Collectors.collectingAndThen(
+ Collectors.toMap(entry -> entry[0], entry -> entry[1]),
+ Collections::unmodifiableMap
+ ));
+ }
+
+ public static class COMMAND_SetCASMailbox {
+ public static final String COMMAND = "Set-CASMailbox";
+ public static final String PARAMETER_Identity = "-Identity";
+ public static final String PARAMETER_ActiveSyncAllowedDeviceIDs = "-ActiveSyncAllowedDeviceIDs";
+ public static final String PARAMETER_ActiveSyncBlockedDeviceIDs = "-ActiveSyncBlockedDeviceIDs";
+ public static final String PARAMETER_EwsAllowMacOutlook = "-EwsAllowMacOutlook";
+ public static final String PARAMETER_MacOutlookEnabled = "-MacOutlookEnabled";
+ public static final String PARAMETER_OneWinNativeOutlookEnabled = "-OneWinNativeOutlookEnabled";
+ public static final String PARAMETER_OutlookMobileEnabled = "-OutlookMobileEnabled";
+ public static final String PARAMETER_OWAEnabled = "-OWAEnabled";
+ public static final String PARAMETER_ImapEnabled = "-ImapEnabled";
+ public static final String PARAMETER_PopEnabled = "-PopEnabled";
+ public static final Map POLICY_TO_VALUE = Stream.of(new String[][]{
+ {EmailOutlookAccessPolicy.MOBILE_OUTLOOK_BLOCK.toString(), FALSE},
+ {EmailOutlookAccessPolicy.MAC_OUTLOOK_BLOCK.toString(), FALSE},
+ {EmailOutlookAccessPolicy.WINDOWS_OUTLOOK_BLOCK.toString(), FALSE},
+ {EmailOutlookAccessPolicy.MAC_OLD_OUTLOOK_BLOCK.toString(), FALSE},
+ {ALLOW, TRUE},
+ {BLOCK, FALSE}
+ }).collect(Collectors.collectingAndThen(
+ Collectors.toMap(entry -> entry[0], entry -> entry[1]),
+ Collections::unmodifiableMap
+ ));
+ }
+
+ public static class COMMAND_GetEXOMailbox {
+ public static final String COMMAND = "Get-EXOMailbox";
+ public static final String PARAMETER_ResultSize = "-ResultSize";
+ }
+
+ public static class COMMAND_ForEach {
+ public static final String COMMAND = "ForEach";
+ public static final String PARAMETER_Begin = "{";
+ public static final String PARAMETER_End = "}";
+ }
+
+ public static class COMMAND_WhereObject {
+ public static final String COMMAND = "Where-Object";
+ public static final String PARAMETER_Begin = "{";
+ public static final String PARAMETER_End = "}";
+ }
+
+ public static class COMMAND_GetEXOMobileDeviceStatistics {
+ public static final String COMMAND = "Get-EXOMobileDeviceStatistics";
+ public static final String PARAMETER_ActiveSync = "-ActiveSync";
+ public static final String PARAMETER_Mailbox = "-Mailbox";
+ }
+
+ public static class COMMAND_ConvertToJson {
+ public static final String COMMAND = "ConvertTo-Json";
+ public static final String PARAMETER_AsArray = "-AsArray";
+ }
+
+ public static class COMMAND_SelectObject {
+ public static final String COMMAND = "Select-Object";
+ }
+
+ public static class COMMAND_SetVariable {
+ public static final String COMMAND = "Set-Variable";
+ public static final String PARAMETER_Name = "-Name";
+ public static final String PARAMETER_Value = "-Value";
+ public static final String PARAMETER_PassThrough = "-PassThru";
+ }
+
+}
diff --git a/components/cea-mgt/pom.xml b/components/cea-mgt/pom.xml
new file mode 100644
index 0000000000..a4c3d279bf
--- /dev/null
+++ b/components/cea-mgt/pom.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.parent
+ 5.0.38-SNAPSHOT
+ ../../pom.xml
+
+
+ 4.0.0
+ cea-mgt
+ pom
+ Entgra IoT - CEA Management Component
+ Entgra IoT - Conditional Email Access Management Component
+
+
+ io.entgra.device.mgt.core.cea.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.common
+ io.entgra.device.mgt.core.cea.mgt.enforce
+
+
\ No newline at end of file
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml
index 073cdd8521..7b431ecccf 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml
@@ -460,5 +460,10 @@
io.entgra.device.mgt.core.apimgt.webapp.publisher
provided
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.common
+ provided
+
\ No newline at end of file
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/AccessPolicyWrapper.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/AccessPolicyWrapper.java
new file mode 100644
index 0000000000..a2d3405e27
--- /dev/null
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/AccessPolicyWrapper.java
@@ -0,0 +1,58 @@
+package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.Set;
+
+@ApiModel(value = "AccessPolicyWrapper", description = "Access policy transferring DTO")
+public class AccessPolicyWrapper {
+ @JsonProperty(value = "defaultAccessPolicy", required = true)
+ @ApiModelProperty(name = "defaultAccessPolicy", value = "Default access policy value", required = true)
+ private String defaultAccessPolicy;
+
+ @JsonProperty(value = "emailOutlookAccessPolicy", required = true)
+ @ApiModelProperty(name = "emailOutlookAccessPolicy", value = "Email outlook access policy value", required = true)
+ private Set emailOutlookAccessPolicy;
+
+ @JsonProperty(value = "POPIMAPAccessPolicy", required = true)
+ @ApiModelProperty(name = "POPIMAPAccessPolicy", value = "POP/IMAP access policy value", required = true)
+ private String POPIMAPAccessPolicy;
+
+ @JsonProperty(value = "webOutlookAccessPolicy", required = true)
+ @ApiModelProperty(name = "webOutlookAccessPolicy", value = "Web outlook access policy value", required = true)
+ private String webOutlookAccessPolicy;
+
+ public String getDefaultAccessPolicy() {
+ return defaultAccessPolicy;
+ }
+
+ public void setDefaultAccessPolicy(String defaultAccessPolicy) {
+ this.defaultAccessPolicy = defaultAccessPolicy;
+ }
+
+ public Set getEmailOutlookAccessPolicy() {
+ return emailOutlookAccessPolicy;
+ }
+
+ public void setEmailOutlookAccessPolicy(Set emailOutlookAccessPolicy) {
+ this.emailOutlookAccessPolicy = emailOutlookAccessPolicy;
+ }
+
+ public String getPOPIMAPAccessPolicy() {
+ return POPIMAPAccessPolicy;
+ }
+
+ public void setPOPIMAPAccessPolicy(String POPIMAPAccessPolicy) {
+ this.POPIMAPAccessPolicy = POPIMAPAccessPolicy;
+ }
+
+ public String getWebOutlookAccessPolicy() {
+ return webOutlookAccessPolicy;
+ }
+
+ public void setWebOutlookAccessPolicy(String webOutlookAccessPolicy) {
+ this.webOutlookAccessPolicy = webOutlookAccessPolicy;
+ }
+}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/CEAPolicyWrapper.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/CEAPolicyWrapper.java
new file mode 100644
index 0000000000..56e872a189
--- /dev/null
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/CEAPolicyWrapper.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2018 - 2023, 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.device.mgt.api.jaxrs.beans;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.entgra.device.mgt.core.cea.mgt.common.bean.ActiveSyncServer;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(value = "CEAPolicyWrapper", description = "CEA policy transferring DTO")
+public class CEAPolicyWrapper {
+ @JsonProperty(value = "activeSyncServerEntries", required = true)
+ @ApiModelProperty(name = "activeSyncServerEntries", value = "Active sync server properties", required = true)
+ private ActiveSyncServer activeSyncServerEntries;
+
+ @JsonProperty(value = "conditionalAccessPolicyEntries", required = true)
+ @ApiModelProperty(name = "conditionalAccessPolicyEntries", value = "Definition of the access policy", required = true)
+ private AccessPolicyWrapper conditionalAccessPolicyEntries;
+
+ @JsonProperty(value = "gracePeriodEntries", required = true)
+ @ApiModelProperty(name = "gracePeriodEntries", value = "Definition of the grace period", required = true)
+ private GracePeriodWrapper gracePeriodEntries;
+
+ public ActiveSyncServer getActiveSyncServerEntries() {
+ return activeSyncServerEntries;
+ }
+
+ public void setActiveSyncServerEntries(ActiveSyncServer activeSyncServerEntries) {
+ this.activeSyncServerEntries = activeSyncServerEntries;
+ }
+
+ public AccessPolicyWrapper getConditionalAccessPolicyEntries() {
+ return conditionalAccessPolicyEntries;
+ }
+
+ public void setConditionalAccessPolicyEntries(AccessPolicyWrapper conditionalAccessPolicyEntries) {
+ this.conditionalAccessPolicyEntries = conditionalAccessPolicyEntries;
+ }
+
+ public GracePeriodWrapper getGracePeriodEntries() {
+ return gracePeriodEntries;
+ }
+
+ public void setGracePeriodEntries(GracePeriodWrapper gracePeriodEntries) {
+ this.gracePeriodEntries = gracePeriodEntries;
+ }
+}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/GracePeriodWrapper.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/GracePeriodWrapper.java
new file mode 100644
index 0000000000..a52a9f099d
--- /dev/null
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/GracePeriodWrapper.java
@@ -0,0 +1,35 @@
+package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
+
+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 {
+
+ @JsonProperty(value = "gracePeriod", required = true)
+ @ApiModelProperty(name = "gracePeriod", value = "Grace period in days", required = true)
+ private int gracePeriod;
+
+ @JsonProperty(value = "graceAllowedPolicy", required = true)
+ @ApiModelProperty(name = "graceAllowedPolicy", value = "Grace allowed policy values", required = true)
+ private String graceAllowedPolicy;
+
+ public int getGracePeriod() {
+ return gracePeriod;
+ }
+
+ public void setGracePeriod(int gracePeriod) {
+ this.gracePeriod = gracePeriod;
+ }
+
+ public String getGraceAllowedPolicy() {
+ return graceAllowedPolicy;
+ }
+
+ public void setGraceAllowedPolicy(String graceAllowedPolicy) {
+ this.graceAllowedPolicy = graceAllowedPolicy;
+ }
+}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/CEAManagementAdminService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/CEAManagementAdminService.java
new file mode 100644
index 0000000000..7ecfb2ae35
--- /dev/null
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/CEAManagementAdminService.java
@@ -0,0 +1,336 @@
+/*
+ * Copyright (c) 2018 - 2023, 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.device.mgt.api.jaxrs.service.api.admin;
+
+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 javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Api(tags = {"conditional_email_access", "device_management"})
+@Path("/admin/cea-policies")
+@SwaggerDefinition(
+ info = @Info(
+ description = "Conditional Email Access Management",
+ version = "v1.0.0",
+ title = "CEAManagementAdminService API",
+ extensions = @Extension(properties = {
+ @ExtensionProperty(name = "name", value = "CEAManagementAdminService"),
+ @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/admin/cea-policies"),
+ })
+ ),
+ consumes = {MediaType.APPLICATION_JSON},
+ produces = {MediaType.APPLICATION_JSON},
+ schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
+ tags = {
+ @Tag(name = "device_management", description = "Device management"),
+ @Tag(name = "conditional_email_access", description = "Mailbox access management")
+ }
+)
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@Scopes(
+ scopes = {
+ @Scope(
+ name = "CEA policy ui configuration view",
+ description = "CEA policy ui configuration view",
+ key = "dm:admin:cea:view",
+ roles = {"Internal/devicemgt-admin"},
+ permissions = {"/device-mgt/admin/cea/view"}
+ ),
+ @Scope(
+ name = "Add CEA policy",
+ description = "Add CEA policy",
+ key = "dm:admin:cea:add",
+ roles = {"Internal/devicemgt-admin"},
+ permissions = {"/device-mgt/admin/cea/add"}
+ ),
+ @Scope(
+ name = "Update CEA policy",
+ description = "Update CEA policy",
+ key = "dm:admin:cea:update",
+ roles = {"Internal/devicemgt-admin"},
+ permissions = {"/device-mgt/admin/cea/update"}
+ ),
+ @Scope(
+ name = "Delete CEA policy",
+ description = "Delete CEA policy",
+ key = "dm:admin:cea:delete",
+ roles = {"Internal/devicemgt-admin"},
+ permissions = {"/device-mgt/admin/cea/delete"}
+ ),
+ @Scope(
+ name = "Sync CEA policy",
+ description = "Sync CEA policy",
+ key = "dm:admin:cea:sync",
+ roles = {"Internal/devicemgt-admin"},
+ permissions = {"/device-mgt/admin/cea/sync"}
+ )
+ }
+)
+public interface CEAManagementAdminService {
+ @GET
+ @Path("/ui")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = HttpMethod.GET,
+ value = "Retrieve CEA policy ui configurations",
+ notes = "Returns CEA policy ui configurations for supporting mail services",
+ tags = {"conditional_email_access", "device_management"},
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:view")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(code = 200,
+ message = "OK. \n Successfully retrieve the cea ui configurations",
+ response = Integer.class),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. \n Empty body because the client has already the latest version of " +
+ "the requested resource."),
+ @ApiResponse(
+ code = 404,
+ message = "Configurations not found",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported."),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the group count.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response getCEAPolicyUI();
+
+
+ @POST
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = HttpMethod.POST,
+ value = "Add CEA policy",
+ notes = "Create conditional email access policy",
+ tags = {"conditional_email_access", "device_management"},
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:add")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 201,
+ message = "OK. \n Successfully created the CEA policy",
+ response = Response.class),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n The specified resource does not exist."),
+ @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."),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while creating the resource.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response createCEAPolicy(
+ @ApiParam(
+ name = "ceaPolicy",
+ value = "Conditional email access policy details",
+ required = true
+ )
+ CEAPolicyWrapper ceaPolicyWrapper);
+
+ @GET
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = HttpMethod.GET,
+ value = "Retrieve CEA policy",
+ notes = "Retrieve conditional email access policy",
+ tags = {"conditional_email_access", "device_management"},
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:view")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully retrieved the CEA policy",
+ response = Response.class),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n The specified resource does not exist."),
+ @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."),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while creating the resource.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response retrieveCEAPolicy();
+
+ @DELETE
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = HttpMethod.DELETE,
+ value = "Delete CEA policy",
+ notes = "Delete conditional email access policy",
+ tags = {"conditional_email_access", "device_management"},
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:delete")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully deleted the CEA policy",
+ response = Response.class),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n The specified resource does not exist."),
+ @ApiResponse(
+ code = 415,
+ message = "Unsupported media type. \n The entity of the request was in a not supported format."),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while creating the resource.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response deleteCEAPolicy();
+
+ @PUT
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = HttpMethod.PUT,
+ value = "Update CEA policy",
+ notes = "Update conditional email access policy",
+ tags = {"conditional_email_access", "device_management"},
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:update")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully updated the CEA policy",
+ response = Response.class),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n The specified resource does not exist."),
+ @ApiResponse(
+ code = 415,
+ message = "Unsupported media type. \n The entity of the request was in a not supported format."),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while creating the resource.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response updateCEAPolicy(@ApiParam(
+ name = "ceaPolicy",
+ value = "Conditional email access policy details",
+ required = true
+ ) CEAPolicyWrapper ceaPolicyWrapper);
+
+ @GET
+ @Path("/sync-now")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = HttpMethod.GET,
+ value = "Sync with active sync server",
+ notes = "Sync and enforce conditional access policy",
+ tags = {"conditional_email_access", "device_management"},
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "dm:admin:cea:sync")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 201,
+ message = "OK. \n Successfully triggered CEA policy sync",
+ response = Response.class),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n The specified resource does not exist."),
+ @ApiResponse(
+ code = 415,
+ message = "Unsupported media type. \n The entity of the request was in a not supported format."),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while creating the resource.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response sync();
+}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/CEAManagementAdminServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/CEAManagementAdminServiceImpl.java
new file mode 100644
index 0000000000..8389ce8f9c
--- /dev/null
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/CEAManagementAdminServiceImpl.java
@@ -0,0 +1,202 @@
+/*
+ * 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.device.mgt.api.jaxrs.service.impl.admin;
+
+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;
+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 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 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;
+import javax.ws.rs.POST;
+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")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class CEAManagementAdminServiceImpl implements CEAManagementAdminService {
+ private static final Log log = LogFactory.getLog(CEAManagementAdminServiceImpl.class);
+
+ @GET
+ @Path("/ui")
+ @Override
+ public Response getCEAPolicyUI() {
+ CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
+ try {
+ CEAPolicyUIConfiguration ceaPolicyUIConfiguration = ceaManagementService.getCEAPolicyUIConfiguration();
+ if (ceaPolicyUIConfiguration == null) {
+ return Response.status(HttpStatus.SC_NOT_FOUND).entity("UI configurations not found").build();
+ }
+ return Response.status(HttpStatus.SC_OK).entity(ceaPolicyUIConfiguration).build();
+ } catch (CEAManagementException e) {
+ String msg = "Error occurred while retrieving CEA ui configs";
+ log.error(msg, e);
+ return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ }
+
+ @POST
+ @Override
+ public Response createCEAPolicy(CEAPolicyWrapper ceaPolicyWrapper) {
+ try {
+ RequestValidationUtil.validateCEAPolicy(ceaPolicyWrapper);
+ CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
+ CEAPolicy ceaPolicy = constructCEAPolicy(ceaPolicyWrapper);
+ ceaPolicy = ceaManagementService.createCEAPolicy(ceaPolicy);
+ return Response.status(HttpStatus.SC_CREATED).entity(ceaPolicy).build();
+ } catch (CEAPolicyAlreadyExistsException e) {
+ String msg = "CEA policy already exists for the tenant";
+ log.warn(msg);
+ return Response.status(HttpStatus.SC_CONFLICT).entity(msg).build();
+ } catch (CEAManagementException e) {
+ String msg = "Error occurred while creating CEA policy";
+ log.error(msg, e);
+ return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ }
+
+ @Override
+ public Response retrieveCEAPolicy() {
+ try {
+ CEAManagementService ceaManagementService = DeviceMgtAPIUtils.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();
+ }
+ return Response.status(HttpStatus.SC_OK).entity(ceaPolicy).build();
+ } catch (CEAManagementException e) {
+ String msg = "Error occurred while retrieving CEA policy";
+ log.error(msg, e);
+ return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ }
+
+ @Override
+ public Response deleteCEAPolicy() {
+ try {
+ CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
+ ceaManagementService.deleteCEAPolicy();
+ return Response.status(HttpStatus.SC_OK).build();
+ } catch (CEAPolicyNotFoundException e) {
+ String msg = "CEA policy isn't exists in the tenant";
+ log.warn(msg);
+ return Response.status(HttpStatus.SC_NOT_FOUND).entity(msg).build();
+ } catch (CEAManagementException e) {
+ String msg = "Error occurred while deleting CEA policy";
+ log.error(msg, e);
+ return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ }
+
+ @Override
+ public Response updateCEAPolicy(CEAPolicyWrapper ceaPolicyWrapper) {
+ try {
+ RequestValidationUtil.validateCEAPolicy(ceaPolicyWrapper);
+ CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
+ CEAPolicy ceaPolicy = constructCEAPolicy(ceaPolicyWrapper);
+ ceaPolicy = ceaManagementService.updateCEAPolicy(ceaPolicy);
+ return Response.status(HttpStatus.SC_CREATED).entity(ceaPolicy).build();
+ } catch (CEAPolicyNotFoundException e) {
+ String msg = "CEA policy isn't exists in the tenant";
+ log.warn(msg);
+ return Response.status(HttpStatus.SC_NOT_FOUND).entity(msg).build();
+ } catch (CEAManagementException e) {
+ String msg = "Error occurred while updating CEA policy";
+ log.error(msg, e);
+ return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ }
+
+ @GET
+ @Path("/sync-now")
+ @Override
+ public Response sync() {
+ CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
+ try {
+ ceaManagementService.syncNow();
+ return Response.status(HttpStatus.SC_OK).build();
+ } catch (CEAManagementException e) {
+ String msg = "Error occurred while trigger syncing";
+ log.error(msg, e);
+ return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ }
+
+ /**
+ * Construct {@link CEAPolicy} from {@link CEAPolicyWrapper}
+ * @param ceaPolicyWrapper {@link CEAPolicyWrapper}
+ * @return {@link CEAPolicy}
+ */
+ private CEAPolicy constructCEAPolicy(CEAPolicyWrapper ceaPolicyWrapper) {
+ AccessPolicyWrapper accessPolicyWrapper = ceaPolicyWrapper.getConditionalAccessPolicyEntries();
+ AccessPolicy accessPolicy = new AccessPolicy();
+ accessPolicy.setDefaultAccessPolicy(Enum.valueOf(DefaultAccessPolicy.class,
+ accessPolicyWrapper.getDefaultAccessPolicy()));
+ accessPolicy.setPOPIMAPAccessPolicy(Enum.valueOf(POPIMAPAccessPolicy.class,
+ accessPolicyWrapper.getPOPIMAPAccessPolicy()));
+ accessPolicy.setWebOutlookAccessPolicy(Enum.valueOf(WebOutlookAccessPolicy.class,
+ accessPolicyWrapper.getWebOutlookAccessPolicy()));
+ Set emailOutlookAccessPolicy = new HashSet<>();
+ for (String value : ceaPolicyWrapper.getConditionalAccessPolicyEntries().getEmailOutlookAccessPolicy()) {
+ emailOutlookAccessPolicy.add(Enum.valueOf(EmailOutlookAccessPolicy.class, value));
+ }
+ accessPolicy.setEmailOutlookAccessPolicy(emailOutlookAccessPolicy);
+ GracePeriodWrapper gracePeriodWrapper = ceaPolicyWrapper.getGracePeriodEntries();
+ GracePeriod gracePeriod = new GracePeriod();
+ gracePeriod.setGracePeriod(gracePeriodWrapper.getGracePeriod());
+ gracePeriod.setGraceAllowedPolicy(Enum.valueOf(GraceAllowedPolicy.class,
+ gracePeriodWrapper.getGraceAllowedPolicy()));
+ ActiveSyncServer activeSyncServer = ceaPolicyWrapper.getActiveSyncServerEntries();
+ CEAPolicy ceaPolicy = new CEAPolicy();
+ ceaPolicy.setAccessPolicy(accessPolicy);
+ ceaPolicy.setGracePeriod(gracePeriod);
+ ceaPolicy.setActiveSyncServer(activeSyncServer);
+ return ceaPolicy;
+ }
+}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java
index 5eb474cb32..0d984bd1e5 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java
@@ -19,6 +19,15 @@ 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;
@@ -913,4 +922,100 @@ 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);
+ }
+ }
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/Constants.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/Constants.java
index eb718ea320..5cb098bce1 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/Constants.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/Constants.java
@@ -88,4 +88,8 @@ public class Constants {
public static final String TENANT = "/permission/admin/tenants";
}
+ public static final class CEAPolicyConstants {
+ CEAPolicyConstants() {};
+ public static final String CEAPolicyMetaKey = "_CEA_POLICY";
+ }
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java
index a39cdba7b2..e28989ae6c 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java
@@ -22,6 +22,7 @@ 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;
@@ -157,11 +158,11 @@ public class DeviceMgtAPIUtils {
private static DeviceStatusManagementService deviceStatusManagementService;
private static OTPManagementService otpManagementService;
-
private static volatile SubscriptionManager subscriptionManager;
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,4 +1231,19 @@ 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;
+ }
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml
index 7cdb4ffa0e..21e75b40d0 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml
@@ -51,6 +51,7 @@
+
@@ -103,6 +104,7 @@
+
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java
index 7b05067899..2e7e69e358 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java
@@ -838,4 +838,6 @@ public interface DeviceDAO {
* @throws DeviceManagementDAOException
*/
List getAgentVersions(int tenantId) throws DeviceManagementDAOException;
+ List getDevicesEnrolledSince(Date since) throws DeviceManagementDAOException;
+ List getDevicesEnrolledPriorTo(Date priorTo) throws DeviceManagementDAOException;
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
index 1199203539..8c17c204a8 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
@@ -38,6 +38,7 @@ import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUti
import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceType;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoCluster;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoCoordinate;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -3283,4 +3284,63 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
}
return agentVersions;
}
+
+ public List getDevicesEnrolledSince(Date since) throws DeviceManagementDAOException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ List devices = new ArrayList<>();
+ String query = "SELECT e.ID AS ENROLMENT_ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, " +
+ "e.DATE_OF_LAST_UPDATE, e.IS_TRANSFERRED, e.STATUS,d.DEVICE_NAME, d.DESCRIPTION, d.DEVICE_TYPE, d.DEVICE_IDENTIFICATION " +
+ "FROM DM_ENROLMENT e,(SELECT d1.ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_IDENTIFICATION, " +
+ "t1.NAME AS DEVICE_TYPE FROM DM_DEVICE d1, DM_DEVICE_TYPE t1 WHERE d1.DEVICE_TYPE_ID = t1.ID " +
+ "AND d1.TENANT_ID = ?) d WHERE e.STATUS NOT IN ('DELETED', 'REMOVED') AND e.DATE_OF_ENROLMENT > ? AND e.TENANT_ID = ?";
+ try {
+ Connection connection = DeviceManagementDAOFactory.getConnection();
+ try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+ preparedStatement.setInt(1, tenantId);
+ preparedStatement.setTimestamp(2, new Timestamp(since.getTime()));
+ preparedStatement.setInt(3, tenantId);
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ Device device = DeviceManagementDAOUtil.loadDevice(resultSet);
+ device.setProperties(getDeviceProps(device.getDeviceIdentifier(), tenantId).getProperties());
+ devices.add(device);
+ }
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving devices";
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ return devices;
+ }
+ public List getDevicesEnrolledPriorTo(Date priorTo) throws DeviceManagementDAOException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ List devices = new ArrayList<>();
+ String query = "SELECT e.ID AS ENROLMENT_ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, " +
+ "e.DATE_OF_LAST_UPDATE, e.IS_TRANSFERRED, e.STATUS, d.DEVICE_NAME, d.DESCRIPTION, d.DEVICE_TYPE, d.DEVICE_IDENTIFICATION " +
+ "FROM DM_ENROLMENT e,(SELECT d1.ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_IDENTIFICATION, " +
+ "t1.NAME AS DEVICE_TYPE FROM DM_DEVICE d1, DM_DEVICE_TYPE t1 WHERE d1.DEVICE_TYPE_ID = t1.ID " +
+ "AND d1.TENANT_ID = ?) d WHERE e.STATUS NOT IN ('DELETED', 'REMOVED') AND e.DATE_OF_ENROLMENT < ? AND e.TENANT_ID = ?";
+ try {
+ Connection connection = DeviceManagementDAOFactory.getConnection();
+ try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+ preparedStatement.setInt(1, tenantId);
+ preparedStatement.setTimestamp(2, new Timestamp(priorTo.getTime()));
+ preparedStatement.setInt(3, tenantId);
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ Device device = DeviceManagementDAOUtil.loadDevice(resultSet);
+ device.setProperties(getDeviceProps(device.getDeviceIdentifier(), tenantId).getProperties());
+ devices.add(device);
+ }
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving devices";
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ return devices;
+ }
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java
index 2e35b5a254..44f6fe15dd 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java
@@ -1061,7 +1061,6 @@ public interface DeviceManagementProviderService {
*/
List getInstalledApplicationsOnDevice(Device device, int offset, int limit)
throws DeviceManagementException;
-
/**
* This method is for getting the installed application list of a device
* @param device {@link Device}
@@ -1069,4 +1068,6 @@ public interface DeviceManagementProviderService {
* @throws DeviceManagementException if any service level or DAO level error occurs
*/
List getInstalledApplicationsOnDevice(Device device) throws DeviceManagementException;
+ List getEnrolledDevicesSince(Date since) throws DeviceManagementException;
+ List getEnrolledDevicesPriorTo(Date before) throws DeviceManagementException;
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
index 22c79aacc1..5c8a8eb28e 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
@@ -159,17 +159,7 @@ import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.LocalTime;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -5157,4 +5147,44 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
return newApplicationList;
}
+
+ @Override
+ public List getEnrolledDevicesSince(Date since) throws DeviceManagementException {
+ List devices;
+ try {
+ DeviceManagementDAOFactory.openConnection();
+ devices = deviceDAO.getDevicesEnrolledSince(since);
+ } catch (DeviceManagementDAOException e) {
+ String msg = "Error occurred while getting devices enrolled device since " + since.getTime();
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } catch (SQLException e) {
+ String msg = "Error occurred while opening a connection to the data source";
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } finally {
+ DeviceManagementDAOFactory.closeConnection();
+ }
+ return devices;
+ }
+
+ @Override
+ public List getEnrolledDevicesPriorTo(Date priorTo) throws DeviceManagementException {
+ List devices;
+ try {
+ DeviceManagementDAOFactory.openConnection();
+ devices = deviceDAO.getDevicesEnrolledPriorTo(priorTo);
+ } catch (DeviceManagementDAOException e) {
+ String msg = "Error occurred while getting devices enrolled device prior to " + priorTo.getTime();
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } catch (SQLException e) {
+ String msg = "Error occurred while opening a connection to the data source";
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } finally {
+ DeviceManagementDAOFactory.closeConnection();
+ }
+ return devices;
+ }
}
diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/pom.xml b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/pom.xml
index daf251590e..fcc467681d 100644
--- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/pom.xml
+++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/pom.xml
@@ -14,7 +14,7 @@
~ 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
+ ~ speciString acquireAccessToken(ActiveSyncServer activeSyncServer) throws CEAManagementException;fic language governing permissions and limitations
~ under the License.
-->
diff --git a/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/pom.xml b/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/pom.xml
new file mode 100644
index 0000000000..e3ba0f7e72
--- /dev/null
+++ b/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/pom.xml
@@ -0,0 +1,121 @@
+
+
+
+
+
+ io.entgra.device.mgt.core
+ cea-mgt-feature
+ 5.0.38-SNAPSHOT
+
+
+ 4.0.0
+ io.entgra.device.mgt.core.cea.mgt.server.feature
+ Entgra IoT - CEA Management Server Feature
+ Entgra IoT - CEA Management Server Feature
+
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.common
+ 5.0.33-SNAPSHOT
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.core
+ 5.0.33-SNAPSHOT
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.enforce
+ 5.0.33-SNAPSHOT
+
+
+
+
+
+
+ maven-resources-plugin
+ 2.6
+
+
+ copy-resources
+ generate-resources
+
+ copy-resources
+
+
+ src/main/resources
+
+
+ resources
+
+ build.properties
+ p2.inf
+
+
+
+
+
+
+
+
+ org.wso2.maven
+ carbon-p2-plugin
+ ${carbon.p2.plugin.version}
+
+
+ p2-feature-generation
+ package
+
+ p2-feature-gen
+
+
+ io.entgra.device.mgt.core.cea.mgt.server
+ ../../etc/feature.properties
+
+
+ org.wso2.carbon.p2.category.type:server
+
+ org.eclipse.equinox.p2.type.group:true
+
+
+
+
+
+
+ io.entgra.device.mgt.core:io.entgra.device.mgt.core.cea.mgt.common:${io.entgra.device.mgt.core.version}
+
+
+ io.entgra.device.mgt.core:io.entgra.device.mgt.core.cea.mgt.core:${io.entgra.device.mgt.core.version}
+
+
+ io.entgra.device.mgt.core:io.entgra.device.mgt.core.cea.mgt.enforce:${io.entgra.device.mgt.core.version}
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/build.properties b/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/build.properties
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/conf/cea-config.xml b/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/conf/cea-config.xml
new file mode 100644
index 0000000000..37a41156d4
--- /dev/null
+++ b/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/conf/cea-config.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+ exchange-online
+ io.entgra.device.mgt.core.cea.mgt.enforce.Impl.ExchangeOnlineCEAEnforcementServiceImpl
+ io.entgra.device.mgt.core.cea.mgt.enforce.Impl.gateway.ExchangeOnlineGatewayServiceImpl
+
+
+
+ true
+ 180000
+ io.entgra.device.mgt.core.cea.mgt.core.task.CEAPolicyMonitoringTask
+
+
\ No newline at end of file
diff --git a/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/conf/cea-ui-config.xml b/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/conf/cea-ui-config.xml
new file mode 100644
index 0000000000..3db76cfb88
--- /dev/null
+++ b/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/conf/cea-ui-config.xml
@@ -0,0 +1,249 @@
+
+
+
+
+
+
+ label_exchangeOnlineServerName
+ exchange-online
+ label_exchangeOnlineServerDescription
+
+
+
+ gatewayUrl
+ true
+ false
+ label_exchangeOnlineAuthorityUrl
+ label_tooltipExchangeOnlineAuthorityUrl
+
+
+ true
+
+
+
+
+ gatewayUrl
+ url
+ label_placeholderExchangeOnlineAuthorityUrl
+
+
+
+ client
+ true
+ false
+ label_azureADClientID
+ label_tooltipAzureADClientID
+
+
+ true
+
+
+
+
+ client
+ text
+ label_placeholderClientID
+
+
+
+ secret
+ true
+ false
+ label_azureADClientSecret
+ label_tooltipAzureADClientSecret
+
+
+ true
+
+
+
+
+ secret
+ password
+ label_placeholderClientSecret
+
+
+
+
+
+ defaultAccessPolicy
+ true
+ false
+ label_defaultGlobalAccessPolicy
+ label_tooltipDefaultGlobalAccessPolicy
+
+
+ true
+
+
+
+
+ defaultAccessPolicy
+ label_placeholderDefaultGlobalAccessPolicy
+
+
+ label_ceaPolicyValueLabelAllow
+ ALLOW
+
+
+ label_ceaPolicyValueLabelBlock
+ BLOCK
+
+
+ label_ceaPolicyValueLabelQuarantine
+ QUARANTINE
+
+
+
+
+
+ emailOutlookAccessPolicy
+ true
+ false
+ label_emailOutlookAccessPolicy
+ label_tooltipEmailOutlookAccessPolicy
+
+
+ true
+
+
+
+
+ emailOutlookAccessPolicy
+
+
+ label_ceaPolicyValueLabelMobileOutlookBlock
+ MOBILE_OUTLOOK_BLOCK
+
+
+ label_ceaPolicyValueLabelWindowsOutlookBlock
+ WINDOWS_OUTLOOK_BLOCK
+
+
+ label_ceaPolicyValueLabelMacOutlookBlock
+ MAC_OUTLOOK_BLOCK
+
+
+
+
+
+ webOutlookAccessPolicy
+ true
+ false
+ label_webOutlookAccessPolicy
+ label_tooltipWebOutlookAccessPolicy
+
+
+ true
+
+
+
+
+ webOutlookAccessPolicy
+
+ label_ceaPolicyValueLabelBlock
+ BLOCK
+ label_ceaPolicyValueLabelAllow
+ ALLOW
+
+
+
+
+ POPIMAPAccessPolicy
+ true
+ false
+ label_popImapAccessPolicy
+ label_tooltipPopImapAccessPolicy
+
+
+ true
+
+
+
+
+ POPIMAPAccessPolicy
+
+ label_ceaPolicyValueLabelBlock
+ BLOCK
+ label_ceaPolicyValueLabelAllow
+ ALLOW
+
+
+
+
+
+
+ gracePeriod
+ true
+ false
+ label_gracePeriod
+ label_tooltipGracePeriod
+
+
+ true
+
+
+
+
+ gracePeriod
+ number
+ label_placeholderGracePeriod
+
+
+
+ graceAllowedPolicy
+ true
+ false
+ label_graceAllowedPolicy
+ label_tooltipGraceAllowedPolicy
+
+
+ true
+
+
+
+
+ graceAllowedPolicy
+ label_placeholderGraceAllowedPolicy
+
+
+ label_ceaPolicyValueLabelNewOnly
+ NEW_ONLY
+
+
+ label_ceaPolicyValueLabelExistingOnly
+ EXISTING_ONLY
+
+
+ label_ceaPolicyValueLabelNewAndExisting
+ NEW_AND_EXISTING
+
+
+ label_ceaPolicyValueLabelNotAllowed
+ NOT_ALLOWED
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/p2.inf b/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/p2.inf
new file mode 100644
index 0000000000..6800d0f82f
--- /dev/null
+++ b/features/cea-mgt-feature/io.entgra.device.mgt.core.cea.mgt.server.feature/src/main/resources/p2.inf
@@ -0,0 +1,3 @@
+instructions.configure = \
+org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.device.mgt.core.cea.mgt.server_${feature.version}/conf/cea-config.xml,target:${installFolder}/../../conf/cea-config.xml,overwrite:true);\
+org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.device.mgt.core.cea.mgt.server_${feature.version}/conf/cea-ui-config.xml,target:${installFolder}/../../conf/cea-ui-config.xml,overwrite:true);\
\ No newline at end of file
diff --git a/features/cea-mgt-feature/pom.xml b/features/cea-mgt-feature/pom.xml
new file mode 100644
index 0000000000..e9d2202de1
--- /dev/null
+++ b/features/cea-mgt-feature/pom.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.parent
+ 5.0.38-SNAPSHOT
+ ../../pom.xml
+
+
+ 4.0.0
+ cea-mgt-feature
+ pom
+ Entgra IoT - CEA Management Feature
+
+
+ io.entgra.device.mgt.core.cea.mgt.server.feature
+
+
\ No newline at end of file
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml
index b4b84e47fc..b83eb5aa69 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml
@@ -406,6 +406,11 @@
am:store:vpp:assets:view
and:devices:enroll
ios:devices:enroll
+ dm:admin:cea:view
+ dm:admin:cea:add
+ dm:admin:cea:update
+ dm:admin:cea:delete
+ dm:admin:cea:sync
device-mgt
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql
index b1f68e0570..7df1fd271e 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql
@@ -839,3 +839,17 @@ CREATE TABLE SUB_OPERATION_TEMPLATE (
);
-- END OF SUB_OPERATION_TEMPLATE TABLE--
+
+-- DM_CEA_POLICIES TABLE --
+
+CREATE TABLE IF NOT EXISTS DM_CEA_POLICIES (
+ ID INT AUTO_INCREMENT PRIMARY KEY,
+ POLICY_CONTENT VARCHAR(2000) NOT NULL,
+ CREATED_TIMESTAMP TIMESTAMP NOT NULL,
+ UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
+ LAST_SYNCED_TIMESTAMP TIMESTAMP NULL,
+ IS_SYNCED BOOLEAN NOT NULL DEFAULT FALSE,
+ TENANT_ID INT UNIQUE NOT NULL
+);
+
+-- END OF DM_CEA_POLICIES TABLE --
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql
index 7090ca20ff..053390b884 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql
@@ -914,3 +914,20 @@ CREATE TABLE SUB_OPERATION_TEMPLATE (
);
-- END SUB_OPERATION_TEMPLATE TABLE--
+
+-- DM_CEA_POLICIES TABLE --
+
+IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'DM_CEA_POLICIES')
+BEGIN
+ CREATE TABLE DM_CEA_POLICIES (
+ ID INT IDENTITY(1,1) PRIMARY KEY,
+ POLICY_CONTENT VARCHAR(2000) NOT NULL,
+ CREATED_TIMESTAMP DATETIME NOT NULL DEFAULT GETDATE(),
+ UPDATED_TIMESTAMP DATETIME NOT NULL DEFAULT GETDATE(),
+ LAST_SYNCED_TIMESTAMP DATETIME NULL,
+ IS_SYNCED BIT NOT NULL DEFAULT 0,
+ TENANT_ID INT UNIQUE NOT NULL
+ );
+END;
+
+-- END OF DM_CEA_POLICIES TABLE --
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql
index 5e33d6b2b4..33b20d1b93 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql
@@ -907,3 +907,17 @@ CREATE TABLE SUB_OPERATION_TEMPLATE (
) ENGINE=InnoDB;
-- END OF SUB_OPERATION_TEMPLATE TABLE--
+
+-- DM_CEA_POLICIES TABLE --
+
+CREATE TABLE IF NOT EXISTS DM_CEA_POLICIES (
+ ID INT AUTO_INCREMENT PRIMARY KEY,
+ POLICY_CONTENT VARCHAR(2000) NOT NULL,
+ CREATED_TIMESTAMP TIMESTAMP NOT NULL,
+ UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
+ LAST_SYNCED_TIMESTAMP TIMESTAMP NULL,
+ IS_SYNCED BOOLEAN NOT NULL DEFAULT FALSE,
+ TENANT_ID INT UNIQUE NOT NULL
+);
+
+-- END OF DM_CEA_POLICIES TABLE --
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql
index 035f31d31d..2b064d516b 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql
@@ -1194,3 +1194,27 @@ ALTER TABLE SUB_OPERATION_TEMPLATE
CREATE SEQUENCE SUB_OPERATION_TEMPLATE_seq START WITH 1 INCREMENT BY 1;
-- END OF SUB_OPERATION_TEMPLATE TABLE--
+
+-- DM_CEA_POLICIES TABLE --
+
+DECLARE
+ table_exists NUMBER;
+BEGIN
+ SELECT COUNT(*) INTO table_exists FROM user_tables WHERE table_name = 'DM_CEA_POLICIES';
+
+ IF table_exists = 0 THEN
+ EXECUTE IMMEDIATE '
+ CREATE TABLE DM_CEA_POLICIES (
+ ID NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY,
+ POLICY_CONTENT VARCHAR2(2000) NOT NULL,
+ CREATED_TIMESTAMP TIMESTAMP NOT NULL,
+ UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
+ LAST_SYNCED_TIMESTAMP TIMESTAMP,
+ IS_SYNCED CHAR(1) DEFAULT ''N'' NOT NULL,
+ TENANT_ID NUMBER UNIQUE NOT NULL
+ )';
+ END IF;
+END;
+/
+
+-- END OF DM_CEA_POLICIES TABLE --
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql
index 1b9393885c..748b94fa4e 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql
@@ -846,3 +846,16 @@ CREATE TABLE DM_DEVICE_CERTIFICATE (
PRIMARY KEY (ID)
)
+-- DM_CEA_POLICIES TABLE --
+
+CREATE TABLE IF NOT EXISTS DM_CEA_POLICIES (
+ ID SERIAL PRIMARY KEY,
+ POLICY_CONTENT VARCHAR(2000) NOT NULL,
+ CREATED_TIMESTAMP TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ UPDATED_TIMESTAMP TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ LAST_SYNCED_TIMESTAMP TIMESTAMPTZ,
+ IS_SYNCED BOOLEAN NOT NULL DEFAULT FALSE,
+ TENANT_ID INT UNIQUE NOT NULL
+);
+
+-- END OF DM_CEA_POLICIES TABLE --
diff --git a/pom.xml b/pom.xml
index 6cb074ff08..833cd27dc0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,6 +51,7 @@
components/subtype-mgt
components/tenant-mgt
components/operation-template-mgt
+ components/cea-mgt
features/device-mgt
features/apimgt-extensions
features/application-mgt
@@ -68,6 +69,7 @@
features/subtype-mgt
features/tenant-mgt
features/operation-template-mgt-plugin-feature
+ features/cea-mgt-feature
@@ -383,6 +385,27 @@
${io.entgra.device.mgt.core.version}
+
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.common
+ ${io.entgra.device.mgt.core.version}
+
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.core
+ ${io.entgra.device.mgt.core.version}
+
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.cea.mgt.enforce
+ ${io.entgra.device.mgt.core.version}
+
+
+
org.wso2.carbon