parent
912fe06ee4
commit
f5250abe78
16
components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java → components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/APIManagerServiceComponent.java
16
components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java → components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/APIManagerServiceComponent.java
44
components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java → components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/APIManagerServiceDataHolder.java
44
components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java → components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/APIManagerServiceDataHolder.java
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.apimgt.extension.rest.api.util;
|
||||
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
||||
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.utils.multitenancy.MultitenantConstants;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||
|
||||
/**
|
||||
* This class contains utility methods needed for API publishing
|
||||
*/
|
||||
public class APIPublisherUtils {
|
||||
private static final Log log = LogFactory.getLog(APIPublisherUtils.class);
|
||||
|
||||
/**
|
||||
* This method will create the temporary user created to publish scopes to the sub tenant space.
|
||||
* @param tenantDomain sub tenant domain from which the user will be created
|
||||
* @throws APIServicesException if the user was unable to be created
|
||||
*/
|
||||
public static void createScopePublishUserIfNotExists(String tenantDomain) throws APIServicesException {
|
||||
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||
try {
|
||||
UserStoreManager userStoreManager =
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager();
|
||||
if (!userStoreManager.isExistingUser(MultitenantUtils.getTenantAwareUsername(Constants.SCOPE_PUBLISH_RESERVED_USER_NAME))) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating scope publish user '" + Constants.SCOPE_PUBLISH_RESERVED_USER_NAME + "' in '" +
|
||||
tenantDomain + "' tenant domain.");
|
||||
}
|
||||
String[] roles = {Constants.ADMIN_ROLE_KEY};
|
||||
userStoreManager.addUser(
|
||||
MultitenantUtils.getTenantAwareUsername(Constants.SCOPE_PUBLISH_RESERVED_USER_NAME),
|
||||
Constants.SCOPE_PUBLISH_RESERVED_USER_PASSWORD,
|
||||
roles,
|
||||
null,
|
||||
""
|
||||
);
|
||||
}
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error occurred while creating scope publishing user in tenant: '" + tenantDomain + "'.";
|
||||
log.error(msg);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will delete the temporary user created to publish scopes to the sub tenant space.
|
||||
* @param tenantDomain sub tenant domain from which the scope publish user will be removed from
|
||||
*/
|
||||
public static void removeScopePublishUserIfExists(String tenantDomain) {
|
||||
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||
try {
|
||||
UserStoreManager userStoreManager =
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager();
|
||||
if (userStoreManager.isExistingUser(MultitenantUtils.getTenantAwareUsername(Constants.SCOPE_PUBLISH_RESERVED_USER_NAME))) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleting scope publish user '" + Constants.SCOPE_PUBLISH_RESERVED_USER_NAME + "' from '" +
|
||||
tenantDomain + "' tenant domain.");
|
||||
}
|
||||
userStoreManager.deleteUser(MultitenantUtils.getTenantAwareUsername(Constants.SCOPE_PUBLISH_RESERVED_USER_NAME));
|
||||
}
|
||||
} catch(UserStoreException e){
|
||||
String msg = "Error occurred while deleting scope publishing user from tenant: '" + tenantDomain + "'.";
|
||||
log.error(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
~
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>cea-mgt</artifactId>
|
||||
<version>5.0.39-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>io.entgra.device.mgt.core.cea.mgt.common</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>Entgra IoT - CEA Management Common</name>
|
||||
<description>Entgra IoT - Conditional Email Access Management Common</description>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${io.entgra.device.mgt.core.version}</Bundle-Version>
|
||||
<Bundle-Description>CEA Management Common Bundle</Bundle-Description>
|
||||
<Import-Package>
|
||||
org.apache.commons.logging,
|
||||
io.entgra.device.mgt.core.device.mgt.common.*
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
io.entgra.device.mgt.core.cea.mgt.common.*
|
||||
</Export-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>io.entgra.device.mgt.core.device.mgt.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -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> emailOutlookAccessPolicy;
|
||||
private POPIMAPAccessPolicy POPIMAPAccessPolicy;
|
||||
private WebOutlookAccessPolicy webOutlookAccessPolicy;
|
||||
|
||||
public DefaultAccessPolicy getDefaultAccessPolicy() {
|
||||
return defaultAccessPolicy;
|
||||
}
|
||||
|
||||
public void setDefaultAccessPolicy(DefaultAccessPolicy defaultAccessPolicy) {
|
||||
this.defaultAccessPolicy = defaultAccessPolicy;
|
||||
}
|
||||
|
||||
public Set<EmailOutlookAccessPolicy> getEmailOutlookAccessPolicy() {
|
||||
return emailOutlookAccessPolicy;
|
||||
}
|
||||
|
||||
public void setEmailOutlookAccessPolicy(Set<EmailOutlookAccessPolicy> 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<ActiveSyncDevice> activeSyncDevices;
|
||||
private CEAPolicy ceaPolicy;
|
||||
|
||||
public List<ActiveSyncDevice> getActiveSyncDevices() {
|
||||
return activeSyncDevices;
|
||||
}
|
||||
|
||||
public void setActiveSyncDevices(List<ActiveSyncDevice> activeSyncDevices) {
|
||||
this.activeSyncDevices = activeSyncDevices;
|
||||
}
|
||||
|
||||
public CEAPolicy getCeaPolicy() {
|
||||
return ceaPolicy;
|
||||
}
|
||||
|
||||
public void setCeaPolicy(CEAPolicy ceaPolicy) {
|
||||
this.ceaPolicy = ceaPolicy;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<String> activeSyncAllowedEASIdentifiers = new HashSet<>();
|
||||
private final Set<String> activeSyncBlockedEASIdentifiers = new HashSet<>();
|
||||
private String identity;
|
||||
|
||||
public Set<String> getActiveSyncAllowedEASIdentifiers() {
|
||||
return activeSyncAllowedEASIdentifiers;
|
||||
}
|
||||
|
||||
public Set<String> 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<String> processedEASIdentifiers = new HashSet<>();
|
||||
for (String activeSyncAllowedEASIdentifier : activeSyncAllowedEASIdentifiers) {
|
||||
processedEASIdentifiers.add("'" + activeSyncAllowedEASIdentifier + "'");
|
||||
}
|
||||
add = String.join(",", processedEASIdentifiers);
|
||||
}
|
||||
|
||||
if (!activeSyncBlockedEASIdentifiers.isEmpty()) {
|
||||
Set<String> 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<String> processedEASIdentifiers = new HashSet<>();
|
||||
for (String activeSyncAllowedEASIdentifier : activeSyncAllowedEASIdentifiers) {
|
||||
processedEASIdentifiers.add("'" + activeSyncAllowedEASIdentifier + "'");
|
||||
}
|
||||
remove = String.join(",", processedEASIdentifiers);
|
||||
}
|
||||
|
||||
if (!activeSyncBlockedEASIdentifiers.isEmpty()) {
|
||||
Set<String> 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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<ServerUIConfiguration> serverUIConfigurations;
|
||||
|
||||
public List<ServerUIConfiguration> getServerConfigurations() {
|
||||
return serverUIConfigurations;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "ServerUIConfigurations", required = true)
|
||||
@XmlElement(name = "ServerUIConfiguration")
|
||||
public void setServerConfigurations(List<ServerUIConfiguration> serverUIConfigurations) {
|
||||
this.serverUIConfigurations = serverUIConfigurations;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<Checkbox> checkboxes;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Name", required = true)
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Checkbox> getCheckboxes() {
|
||||
return checkboxes;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "Checkboxes", required = true)
|
||||
@XmlElement(name = "Checkbox")
|
||||
public void setCheckboxes(List<Checkbox> checkboxes) {
|
||||
this.checkboxes = checkboxes;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<Entry> activeSyncServerEntries;
|
||||
private List<Entry> conditionalAccessPolicyEntries;
|
||||
private List<Entry> gracePeriodEntries;
|
||||
|
||||
public List<Entry> getActiveSyncServerEntries() {
|
||||
return activeSyncServerEntries;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "ActiveSyncServerEntries", required = true)
|
||||
@XmlElement(name = "Entry", required = true)
|
||||
public void setActiveSyncServerEntries(List<Entry> activeSyncServerEntries) {
|
||||
this.activeSyncServerEntries = activeSyncServerEntries;
|
||||
}
|
||||
|
||||
public List<Entry> getConditionalAccessPolicyEntries() {
|
||||
return conditionalAccessPolicyEntries;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "ConditionalAccessPolicyEntries", required = true)
|
||||
@XmlElement(name = "Entry", required = true)
|
||||
public void setConditionalAccessPolicyEntries(List<Entry> conditionalAccessPolicyEntries) {
|
||||
this.conditionalAccessPolicyEntries = conditionalAccessPolicyEntries;
|
||||
}
|
||||
|
||||
public List<Entry> getGracePeriodEntries() {
|
||||
return gracePeriodEntries;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "GracePeriodEntries", required = true)
|
||||
@XmlElement(name = "Entry", required = true)
|
||||
public void setGracePeriodEntries(List<Entry> gracePeriodEntries) {
|
||||
this.gracePeriodEntries = gracePeriodEntries;
|
||||
}
|
||||
}
|
@ -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<Option> 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<Option> getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "Options", required = true)
|
||||
@XmlElement(name = "Option")
|
||||
public void setOptions(List<Option> options) {
|
||||
this.options = options;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
~
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>cea-mgt</artifactId>
|
||||
<version>5.0.39-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>io.entgra.device.mgt.core.cea.mgt.core</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>Entgra IoT - CEA Management Core</name>
|
||||
<description>Entgra IoT - Conditional Email Access Management Core</description>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${io.entgra.device.mgt.core.version}</Bundle-Version>
|
||||
<Bundle-Description>CEA Management Core Bundle</Bundle-Description>
|
||||
<Private-Package>io.entgra.device.mgt.core.cea.mgt.core.internal</Private-Package>
|
||||
<Import-Package>
|
||||
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.*
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!io.entgra.device.mgt.core.cea.mgt.core.internal,
|
||||
io.entgra.device.mgt.core.cea.mgt.core.*
|
||||
</Export-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>io.entgra.device.mgt.core.cea.mgt.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>io.entgra.device.mgt.core.cea.mgt.enforce</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>io.entgra.device.mgt.core.device.mgt.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.commons</groupId>
|
||||
<artifactId>org.wso2.carbon.ntask.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>io.entgra.device.mgt.core.device.mgt.core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<ActiveSyncServerConfiguration> activeSyncServerConfigurations;
|
||||
private MonitoringConfiguration monitoringConfiguration;
|
||||
|
||||
public List<ActiveSyncServerConfiguration> getActiveSyncServerConfigurations() {
|
||||
return activeSyncServerConfigurations;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "ActiveSyncServerConfigurations", required = true)
|
||||
@XmlElement(name = "ActiveSyncServerConfiguration", required = true)
|
||||
public void setActiveSyncServerConfigurations(List<ActiveSyncServerConfiguration> 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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> T initConfig(String docPath, Class<T> 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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<JNDIProperty> 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<JNDIProperty> getJndiProperties() {
|
||||
return jndiProperties;
|
||||
}
|
||||
|
||||
public void setJndiProperties(List<JNDIProperty> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<CEAPolicy> 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;
|
||||
}
|
@ -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<Connection> 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<JNDILookupDefinition.JNDIProperty> jndiProperties = ceaDatasourceConfiguration.getJndiLookupDefinition().getJndiProperties();
|
||||
|
||||
if (jndiProperties == null || jndiProperties.isEmpty()) {
|
||||
return lookupDatasource(datasourceName);
|
||||
}
|
||||
Hashtable<Object, Object> 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<Object, Object> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<CEAPolicy> retrieveAllCEAPolicies() throws CEAPolicyManagementDAOException {
|
||||
List<CEAPolicy> 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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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<CEAPolicy> 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;
|
||||
}
|
@ -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<CEAPolicy> 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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
@ -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<String, String> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>cea-mgt</artifactId>
|
||||
<version>5.0.39-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>io.entgra.device.mgt.core.cea.mgt.enforce</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>bundle</packaging>
|
||||
<name>Entgra IoT - CEA Management Enforcement Service</name>
|
||||
<description>Entgra IoT - Conditional Email Access Management Enforcement Service</description>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${io.entgra.device.mgt.core.version}</Bundle-Version>
|
||||
<Bundle-Description>CEA Management Enforcement Service Bundle</Bundle-Description>
|
||||
<Import-Package>
|
||||
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
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
io.entgra.device.mgt.core.cea.mgt.enforce.*
|
||||
</Export-Package>
|
||||
<DynamicImport-Package>*</DynamicImport-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>io.entgra.device.mgt.core.cea.mgt.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>io.entgra.device.mgt.core.device.mgt.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.user.api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.user.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>msal4j</artifactId>
|
||||
<version>1.14.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<EmailOutlookAccessPolicy> 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<ActiveSyncDevice> validActiveSyncDevices = isSynced ? DeviceMgtUtil.
|
||||
getEnrolledActiveSyncDevices(lastSynced, false) :
|
||||
DeviceMgtUtil.getEnrolledActiveSyncDevices(new Date(), true);
|
||||
List<ActiveSyncDevice> notValidActiveSyncDevices = new ArrayList<>();
|
||||
|
||||
List<ActiveSyncDevice> 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<ActiveSyncDevice> graceExceededNewlyConnectedActiveSyncDevices =
|
||||
getConnectedActiveSyncDevicesAfter(calendar.getTime(), activeSyncServer);
|
||||
List<ActiveSyncDevice> managedDevices = DeviceMgtUtil.getEnrolledActiveSyncDevices(calendar.getTime(), false);
|
||||
categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
|
||||
graceExceededNewlyConnectedActiveSyncDevices, managedDevices, gracePeriod, false);
|
||||
|
||||
// Block grace offered existing devices if exists
|
||||
List<ActiveSyncDevice> 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<ActiveSyncDevice> 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<ActiveSyncDevice> graceExceededNewlyConnectedActiveSyncDevices =
|
||||
getConnectedActiveSyncDevicesAfter(calendar.getTime(), activeSyncServer);
|
||||
List<ActiveSyncDevice> 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<ActiveSyncDevice> connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy =
|
||||
getConnectedActiveSyncDevicesBefore(created, activeSyncServer);
|
||||
categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
|
||||
connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy, validActiveSyncDevices, gracePeriod, true);
|
||||
}
|
||||
|
||||
List<MailboxProfile> 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<ActiveSyncDevice> validActiveSyncDevices, List<ActiveSyncDevice> notValidActiveSyncDevices,
|
||||
List<ActiveSyncDevice> deviceList, List<ActiveSyncDevice> 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<ActiveSyncDevice> validActiveSyncDevices,
|
||||
List<ActiveSyncDevice> 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<MailboxProfile> generateMailboxProfiles(List<ActiveSyncDevice> activeSyncAllowedDevices,
|
||||
List<ActiveSyncDevice> activeSyncBlockedDevices) {
|
||||
List<MailboxProfile> 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<ActiveSyncDevice> 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<ActiveSyncDevice> 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<ActiveSyncDevice> 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<ActiveSyncDevice> 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<ActiveSyncDevice> 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);
|
||||
}
|
||||
}
|
@ -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<String> SCOPES = new HashSet<>(Collections.singletonList("https://outlook.office365.com/.default"));
|
||||
private static final Map<String, IConfidentialClientApplication> 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;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue