forked from community/device-mgt-core
remotes/1729253769841084517/master
commit
a95d9438e5
@ -0,0 +1,28 @@
|
|||||||
|
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
@ApiModel(value = "InvitationMailProfile", description = "Holds data related to JIT Enrollment invitation mails")
|
||||||
|
public class InvitationMailProfile {
|
||||||
|
@ApiModelProperty(name = "username", value = "Username (same as username in external IDP)", required = true)
|
||||||
|
private String username;
|
||||||
|
@ApiModelProperty(name = "mail", value = "Mail will be sent to this mail address", required = true)
|
||||||
|
private String mail;
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMail() {
|
||||||
|
return mail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMail(String mail) {
|
||||||
|
this.mail = mail;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApiModel(value = "JITEnrollmentInvitation", description = "Holds data related to JIT enrollment invitations")
|
||||||
|
public class JITEnrollmentInvitation {
|
||||||
|
@ApiModelProperty(name = "mailProfiles", value = "Mail profiles to send mail invitations", required = true)
|
||||||
|
private List<InvitationMailProfile> mailProfiles;
|
||||||
|
@ApiModelProperty(name = "ownershipType", value = "Ownership type of the enrollment", required = true)
|
||||||
|
private String ownershipType;
|
||||||
|
@ApiModelProperty(name = "deviceType", value = "Device type", required = true)
|
||||||
|
private String deviceType;
|
||||||
|
@ApiModelProperty(name = "sp", value = "Service provider name", required = true)
|
||||||
|
private String sp;
|
||||||
|
|
||||||
|
public List<InvitationMailProfile> getMailProfiles() {
|
||||||
|
return mailProfiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMailProfiles(List<InvitationMailProfile> mailProfiles) {
|
||||||
|
this.mailProfiles = mailProfiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwnershipType() {
|
||||||
|
return ownershipType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnershipType(String ownershipType) {
|
||||||
|
this.ownershipType = ownershipType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceType() {
|
||||||
|
return deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceType(String deviceType) {
|
||||||
|
this.deviceType = deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSp() {
|
||||||
|
return sp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSp(String sp) {
|
||||||
|
this.sp = sp;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,252 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
|
||||||
|
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
|
||||||
|
import io.swagger.annotations.*;
|
||||||
|
import org.apache.axis2.transport.http.HTTPConstants;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata related REST-API implementation.
|
||||||
|
*/
|
||||||
|
@SwaggerDefinition(
|
||||||
|
info = @Info(
|
||||||
|
version = "1.0.0",
|
||||||
|
title = "Device Status Filter Service",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = "name", value = "DeviceStatusManagement"),
|
||||||
|
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/device-status-filters"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
),
|
||||||
|
tags = {
|
||||||
|
@Tag(name = "device_management")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@Scopes(
|
||||||
|
scopes = {
|
||||||
|
@Scope(
|
||||||
|
name = "View Device Status Filter",
|
||||||
|
description = "View device status details",
|
||||||
|
key = "dm:devicestatusfilter:view",
|
||||||
|
roles = {"Internal/devicemgt-user"},
|
||||||
|
permissions = {"/device-mgt/device-status-filters/view"}
|
||||||
|
),
|
||||||
|
@Scope(
|
||||||
|
name = "Update Device status filter",
|
||||||
|
description = "Updating Device status filter",
|
||||||
|
key = "dm:devicestatusfilter:update",
|
||||||
|
roles = {"Internal/devicemgt-user"},
|
||||||
|
permissions = {"/device-mgt/device-status-filters/update"}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@Api(value = "Device Status Management")
|
||||||
|
@Path("/device-status-filters")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public interface DeviceStatusFilterService {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{device-type}")
|
||||||
|
@ApiOperation(
|
||||||
|
httpMethod = HTTPConstants.HEADER_GET,
|
||||||
|
value = "Get device status filters",
|
||||||
|
notes = "Get device status filters for the tenant of the logged in user",
|
||||||
|
tags = "Tenant Metadata Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devicestatusfilter:view")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Successfully retrieved device status filters.",
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "The content type of the body"),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "ETag",
|
||||||
|
description = "Entity Tag of the response resource.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Last-Modified",
|
||||||
|
description = "Date and time the resource was last modified.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
}),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. " +
|
||||||
|
"\n Server error occurred while getting device status filters.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
Response getDeviceStatusFilters( @ApiParam(
|
||||||
|
name = "deviceType",
|
||||||
|
value = "The device type.",
|
||||||
|
required = true) @PathParam ("device-type") String deviceType);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/is-enabled")
|
||||||
|
@ApiOperation(
|
||||||
|
httpMethod = HTTPConstants.HEADER_GET,
|
||||||
|
value = "Get device status filter",
|
||||||
|
notes = "Get device status filter enable or not for the tenant of the logged in user",
|
||||||
|
tags = "Tenant Metadata Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devicestatusfilter:view")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Successfully retrieved device status filter.",
|
||||||
|
response = Response.class,
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "The content type of the body"),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "ETag",
|
||||||
|
description = "Entity Tag of the response resource.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Last-Modified",
|
||||||
|
description = "Date and time the resource was last modified.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
}),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. " +
|
||||||
|
"\n Server error occurred while getting device status check.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
Response getDeviceStatusCheck();
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/toggle-device-status")
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = HTTPConstants.HEADER_POST,
|
||||||
|
value = "Update Device status check for tenant",
|
||||||
|
notes = "Update Device status check for the tenant of the logged in user",
|
||||||
|
tags = "Tenant Metadata Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devicestatusfilter:update")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Successfully updated device status check.",
|
||||||
|
response = Response.class,
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "The content type of the body"),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "ETag",
|
||||||
|
description = "Entity Tag of the response resource.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Last-Modified",
|
||||||
|
description = "Date and time the resource was last modified.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
}),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. " +
|
||||||
|
"\n Server error occurred while updating device status check.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
Response updateDeviceStatusCheck(
|
||||||
|
@ApiParam(
|
||||||
|
name = "Device status check",
|
||||||
|
value = "The device status filtering is enable or not.",
|
||||||
|
required = true)
|
||||||
|
@QueryParam("isEnabled") boolean isEnabled);
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = HTTPConstants.HEADER_POST,
|
||||||
|
value = "Update Device status filters for given device type for tenant",
|
||||||
|
notes = "Update Device status filters for given device type for the tenant of the logged in user",
|
||||||
|
tags = "Tenant Metadata Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devicestatusfilter:update")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Successfully updated device status filters for given device type..",
|
||||||
|
response = Response.class,
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "The content type of the body"),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "ETag",
|
||||||
|
description = "Entity Tag of the response resource.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Last-Modified",
|
||||||
|
description = "Date and time the resource was last modified.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
}),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. " +
|
||||||
|
"\n Server error occurred while updating device status filters for given device type.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
Response updateDeviceStatusFilters(
|
||||||
|
@ApiParam(
|
||||||
|
name = "deviceType",
|
||||||
|
value = "The device type for which you want to update device status filters.",
|
||||||
|
required = true)
|
||||||
|
@QueryParam("deviceType") String deviceType,
|
||||||
|
@ApiParam(
|
||||||
|
name = "deviceStatus",
|
||||||
|
value = "A list of device status values to update for the given device type.",
|
||||||
|
required = true)
|
||||||
|
@QueryParam("deviceStatus") List<String> deviceStatus);
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.DeviceStatusFilterService;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Path("/device-status-filters")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceStatusFilterServiceImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GET
|
||||||
|
@Path("/{deviceType}")
|
||||||
|
public Response getDeviceStatusFilters(@PathParam("deviceType") String deviceType) {
|
||||||
|
List<String> result;
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
try {
|
||||||
|
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
|
||||||
|
result = deviceManagementProviderService.getDeviceStatusFilters(deviceType, tenantId);
|
||||||
|
if (result != null) {
|
||||||
|
return Response.status(Response.Status.OK).entity(result).build();
|
||||||
|
}
|
||||||
|
return Response.status(Response.Status.NO_CONTENT).entity(false).build();
|
||||||
|
} catch (MetadataManagementException e) {
|
||||||
|
String msg = "Error occurred while getting device status filter of the tenant.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/is-enabled")
|
||||||
|
@Override
|
||||||
|
public Response getDeviceStatusCheck() {
|
||||||
|
boolean result;
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
try {
|
||||||
|
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
|
||||||
|
result = deviceManagementProviderService.getDeviceStatusCheck(tenantId);
|
||||||
|
return Response.status(Response.Status.OK).entity(result).build();
|
||||||
|
} catch (MetadataManagementException e) {
|
||||||
|
String msg = "Error occurred while getting device status filter of the tenant.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PUT
|
||||||
|
@Path("/toggle-device-status")
|
||||||
|
public Response updateDeviceStatusCheck(
|
||||||
|
@QueryParam("isEnabled")
|
||||||
|
boolean isEnabled) {
|
||||||
|
boolean result;
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
try {
|
||||||
|
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
|
||||||
|
result = deviceManagementProviderService.updateDefaultDeviceStatusCheck(tenantId, isEnabled);
|
||||||
|
if (result) {
|
||||||
|
return Response.status(Response.Status.OK).entity("Successfully updated device status check.").build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NO_CONTENT).entity(false).build();
|
||||||
|
}
|
||||||
|
} catch (MetadataManagementException e) {
|
||||||
|
String msg = "Error occurred while updating device status check.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PUT
|
||||||
|
public Response updateDeviceStatusFilters(
|
||||||
|
@QueryParam("deviceType")
|
||||||
|
String deviceType,
|
||||||
|
@QueryParam("deviceStatus")
|
||||||
|
List<String> deviceStatus
|
||||||
|
) {
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
try {
|
||||||
|
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
|
||||||
|
deviceManagementProviderService.updateDefaultDeviceStatusFilters(tenantId, deviceType, deviceStatus);
|
||||||
|
return Response.status(Response.Status.OK).entity("Successfully updated device status filters for " + deviceType).build();
|
||||||
|
} catch (MetadataManagementException e) {
|
||||||
|
String msg = "Error occurred while updating device status for " + deviceType;
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.device.mgt.common.metadata.mgt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AllowedDeviceStatus {
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private List<String> status;
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(List<String> status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.device.mgt.common.metadata.mgt;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface DeviceStatusManagementService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is useful to create & persist default device status filter for provided tenant if
|
||||||
|
* it doesn't exist already
|
||||||
|
*
|
||||||
|
* @throws MetadataManagementException if error while adding default device status
|
||||||
|
*/
|
||||||
|
void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is useful to reset existing device status to default values in xml
|
||||||
|
*
|
||||||
|
* @throws MetadataManagementException if error while resetting default device status
|
||||||
|
*/
|
||||||
|
void resetToDefaultDeviceStausFilter() throws MetadataManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is useful to update existing allowed device status
|
||||||
|
*
|
||||||
|
* @throws MetadataManagementException if error while updating existing device status
|
||||||
|
*/
|
||||||
|
void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus)
|
||||||
|
throws MetadataManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is useful to update existing device status check
|
||||||
|
*
|
||||||
|
* @throws MetadataManagementException if error while updating existing device status
|
||||||
|
*/
|
||||||
|
boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked)
|
||||||
|
throws MetadataManagementException;
|
||||||
|
/**
|
||||||
|
* This method is useful to get existing device status filters
|
||||||
|
*
|
||||||
|
* @throws MetadataManagementException if error while getting existing device status
|
||||||
|
*/
|
||||||
|
List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is useful to get existing device status filters by device type and tenant id
|
||||||
|
*
|
||||||
|
* @throws MetadataManagementException if error while getting existing device status
|
||||||
|
*/
|
||||||
|
List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is useful to get existing device status filters
|
||||||
|
*
|
||||||
|
* @throws MetadataManagementException if error while getting existing device status check
|
||||||
|
*/
|
||||||
|
boolean getDeviceStatusCheck(int tenantId) throws MetadataManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is useful to check status is valid for device type
|
||||||
|
*
|
||||||
|
* @throws MetadataManagementException if error while getting existing device status check
|
||||||
|
*/
|
||||||
|
boolean isDeviceStatusValid(String deviceType, String deviceStatus, int tenantId) throws MetadataManagementException;
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.device.mgt.core.config.ui;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceStatusConfigurations {
|
||||||
|
|
||||||
|
private List<DeviceStatusItem> deviceStatusItems;
|
||||||
|
private boolean deviceStatusCheck;
|
||||||
|
|
||||||
|
@XmlElement(name = "DeviceStatusItem")
|
||||||
|
public List<DeviceStatusItem> getDeviceStatusItems() {
|
||||||
|
return deviceStatusItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "EnableDeviceStatusCheck")
|
||||||
|
public boolean isDeviceStatusCheck() {
|
||||||
|
return deviceStatusCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceStatusCheck(boolean deviceStatusCheck) {
|
||||||
|
this.deviceStatusCheck = deviceStatusCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceStatusItems(List<DeviceStatusItem> deviceStatusItems) {
|
||||||
|
this.deviceStatusItems = deviceStatusItems;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.device.mgt.core.config.ui;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceStatusItem {
|
||||||
|
|
||||||
|
private List<String> status;
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@XmlElement(name = "Type")
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElementWrapper(name = "AllowedStatus")
|
||||||
|
@XmlElement(name = "Status")
|
||||||
|
public List<String> getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(List<String> status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,322 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.device.mgt.core.metadata.mgt;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.AllowedDeviceStatus;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.DeviceStatusConfigurations;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.DeviceStatusItem;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.UIConfigurationManager;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataDAO;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.util.MetadataConstants;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class DeviceStatusManagementServiceImpl implements DeviceStatusManagementService {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceStatusManagementServiceImpl.class);
|
||||||
|
|
||||||
|
private final MetadataDAO metadataDAO;
|
||||||
|
|
||||||
|
public DeviceStatusManagementServiceImpl() {
|
||||||
|
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException {
|
||||||
|
try {
|
||||||
|
MetadataManagementDAOFactory.beginTransaction();
|
||||||
|
if (!metadataDAO.isExist(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY) && !metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
|
||||||
|
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus());
|
||||||
|
Metadata defaultDeviceStatusCheckMetadata = constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck());
|
||||||
|
// Add default device status and device status check metadata entries
|
||||||
|
addMetadataEntry(tenantId, defaultDeviceStatusMetadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
||||||
|
addMetadataEntry(tenantId, defaultDeviceStatusCheckMetadata, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
||||||
|
}
|
||||||
|
MetadataManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (MetadataManagementDAOException e) {
|
||||||
|
MetadataManagementDAOFactory.rollbackTransaction();
|
||||||
|
String msg = "Error occurred while inserting default device status metadata entry.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
String msg = "Error occurred while opening a connection to the data source";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MetadataManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetToDefaultDeviceStausFilter() throws MetadataManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus) throws MetadataManagementException {
|
||||||
|
try {
|
||||||
|
MetadataManagementDAOFactory.beginTransaction();
|
||||||
|
// Retrieve the current device status metadata
|
||||||
|
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
||||||
|
if (metadata != null) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
|
||||||
|
}.getType();
|
||||||
|
List<AllowedDeviceStatus> currentStatusList = gson.fromJson(metadata.getMetaValue(), listType);
|
||||||
|
|
||||||
|
// Find the status for the specified deviceType
|
||||||
|
for (AllowedDeviceStatus status : currentStatusList) {
|
||||||
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
||||||
|
// Update the status list for the specified deviceType
|
||||||
|
status.setStatus(deviceStatus);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
metadata.setMetaValue(gson.toJson(currentStatusList));
|
||||||
|
updateMetadataEntry(tenantId, metadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
||||||
|
}
|
||||||
|
MetadataManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (MetadataManagementDAOException e) {
|
||||||
|
MetadataManagementDAOFactory.rollbackTransaction();
|
||||||
|
String msg = "Error occurred while updating device status metadata entry.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
String msg = "Error occurred while opening a connection to the data source";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MetadataManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked) throws MetadataManagementException {
|
||||||
|
boolean success = false;
|
||||||
|
try {
|
||||||
|
MetadataManagementDAOFactory.beginTransaction();
|
||||||
|
if (metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
|
||||||
|
Metadata isDeviceStatusChecked = constructDeviceStatusCheckMetadata(isChecked);
|
||||||
|
// Add default device status check metadata entries
|
||||||
|
updateMetadataEntry(tenantId, isDeviceStatusChecked, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
MetadataManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (MetadataManagementDAOException e) {
|
||||||
|
MetadataManagementDAOFactory.rollbackTransaction();
|
||||||
|
String msg = "Error occurred while updating device status check metadata entry.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
String msg = "Error occurred while opening a connection to the data source";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MetadataManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException {
|
||||||
|
try {
|
||||||
|
MetadataManagementDAOFactory.openConnection();
|
||||||
|
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
||||||
|
Gson gson = new Gson();
|
||||||
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType();
|
||||||
|
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
|
||||||
|
|
||||||
|
return statusList;
|
||||||
|
} catch (MetadataManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while retrieving device status meta data for tenant:" + tenantId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while opening a connection to the data source";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MetadataManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException {
|
||||||
|
try {
|
||||||
|
MetadataManagementDAOFactory.openConnection();
|
||||||
|
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
||||||
|
Gson gson = new Gson();
|
||||||
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType();
|
||||||
|
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
|
||||||
|
|
||||||
|
for (AllowedDeviceStatus status : statusList) {
|
||||||
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
||||||
|
return status.getStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Device type not found in metadata
|
||||||
|
return Collections.emptyList();
|
||||||
|
} catch (MetadataManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while retrieving device status meta data for tenant: " + tenantId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while opening a connection to the data source";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MetadataManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getDeviceStatusCheck(int tenantId) throws MetadataManagementException {
|
||||||
|
try {
|
||||||
|
MetadataManagementDAOFactory.openConnection();
|
||||||
|
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
||||||
|
String metaValue = metadata.getMetaValue();
|
||||||
|
return Boolean.parseBoolean(metaValue);
|
||||||
|
} catch (MetadataManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while retrieving device status check meta data for tenant:" + tenantId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while opening a connection to the data source";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MetadataManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDeviceStatusValid(String deviceType, String deviceStatus, int tenantId) throws MetadataManagementException {
|
||||||
|
try {
|
||||||
|
MetadataManagementDAOFactory.openConnection();
|
||||||
|
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
|
||||||
|
}.getType();
|
||||||
|
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
|
||||||
|
|
||||||
|
for (AllowedDeviceStatus status : statusList) {
|
||||||
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
||||||
|
List<String> allowedStatus = status.getStatus();
|
||||||
|
return allowedStatus.contains(deviceStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false; // Device type not found in metadata
|
||||||
|
} catch (MetadataManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while retrieving device status meta data for tenant: " + tenantId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while opening a connection to the data source";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MetadataManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MetadataManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException {
|
||||||
|
metadataDAO.addMetadata(tenantId, metadata);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(key + " metadata entry has been inserted successfully");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException {
|
||||||
|
metadataDAO.updateMetadata(tenantId, metadata);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(key + " metadata entry has been updated successfully");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Metadata constructDeviceStatusMetadata(List<DeviceStatusItem> deviceStatusItems) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String deviceStatusItemsJsonString = gson.toJson(deviceStatusItems);
|
||||||
|
|
||||||
|
Metadata metadata = new Metadata();
|
||||||
|
metadata.setMetaKey(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
||||||
|
metadata.setMetaValue(deviceStatusItemsJsonString);
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Metadata constructDeviceStatusCheckMetadata(boolean deviceStatusCheck) {
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("deviceStatusCheck", String.valueOf(deviceStatusCheck));
|
||||||
|
Metadata metadata = new Metadata();
|
||||||
|
metadata.setMetaKey(MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
||||||
|
metadata.setMetaValue(String.valueOf(deviceStatusCheck));
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DeviceStatusItem> getDefaultDeviceStatus() {
|
||||||
|
DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations();
|
||||||
|
List<DeviceStatusItem> deviceStatusItems = new ArrayList<>();
|
||||||
|
|
||||||
|
if (deviceStatusConfigurations != null) {
|
||||||
|
// Access the list of DeviceStatusItem objects
|
||||||
|
deviceStatusItems = deviceStatusConfigurations.getDeviceStatusItems();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("DeviceStatusConfigurations is null.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return deviceStatusItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getDefaultDeviceStatusCheck() {
|
||||||
|
DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations();
|
||||||
|
boolean deviceStatusCheck = false;
|
||||||
|
|
||||||
|
if (deviceStatusConfigurations != null) {
|
||||||
|
// Access the deviceStatusCheck
|
||||||
|
deviceStatusCheck = deviceStatusConfigurations.isDeviceStatusCheck();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("DeviceStatusConfigurations is null.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceStatusCheck;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,410 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
~ Version 2.0 (the "License"); you may not use this file except
|
||||||
|
~ in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
|
~ software distributed under the License is distributed on an
|
||||||
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
~ KIND, either express or implied. See the License for the
|
||||||
|
~ specific language governing permissions and limitations
|
||||||
|
~ under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<UIConfiguration>
|
||||||
|
<EnableOAuth>true</EnableOAuth>
|
||||||
|
<EnableSSO>true</EnableSSO>
|
||||||
|
<!-- session time out in seconds -->
|
||||||
|
<SessionTimeOut>3600</SessionTimeOut>
|
||||||
|
<!-- maximum number of login cache entries -->
|
||||||
|
<LoginCacheCapacity>10000</LoginCacheCapacity>
|
||||||
|
<!-- hubspot account info for live chat -->
|
||||||
|
<HubspotChat>
|
||||||
|
<EnableHubspot>false</EnableHubspot>
|
||||||
|
<TrackingUrl>tracking_url</TrackingUrl>
|
||||||
|
<!-- access token - whenever the access token will be rotated, needs to be changed this with the new token -->
|
||||||
|
<AccessToken>access_token</AccessToken>
|
||||||
|
<SenderActorId>sender_actorId</SenderActorId>
|
||||||
|
</HubspotChat>
|
||||||
|
<Billing>
|
||||||
|
<HideBillGenerationInSuperTenant>false</HideBillGenerationInSuperTenant>
|
||||||
|
<HideBillGenerationInSubTenant>true</HideBillGenerationInSubTenant>
|
||||||
|
<HideTotalCalculationInSuperTenant>false</HideTotalCalculationInSuperTenant>
|
||||||
|
<HideTotalCalculationInSubTenant>true</HideTotalCalculationInSubTenant>
|
||||||
|
<HideDomainSelectionInSuperTenant>false</HideDomainSelectionInSuperTenant>
|
||||||
|
<HideDomainSelectionInSubTenant>true</HideDomainSelectionInSubTenant>
|
||||||
|
</Billing>
|
||||||
|
<DeviceInfoConfigurations>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>name</DefinedValue>
|
||||||
|
<DisplayValue>label_device</DisplayValue>
|
||||||
|
<Type>default</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>type</DefinedValue>
|
||||||
|
<DisplayValue>label_type</DisplayValue>
|
||||||
|
<Type>default</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>owner</DefinedValue>
|
||||||
|
<DisplayValue>label_owner</DisplayValue>
|
||||||
|
<Type>default</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>serial</DefinedValue>
|
||||||
|
<DisplayValue>label_serialNumber</DisplayValue>
|
||||||
|
<Type>default</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>ownership</DefinedValue>
|
||||||
|
<DisplayValue>label_ownership</DisplayValue>
|
||||||
|
<Type>default</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>status</DefinedValue>
|
||||||
|
<DisplayValue>label_status</DisplayValue>
|
||||||
|
<Type>default</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>dateOfLastUpdate</DefinedValue>
|
||||||
|
<DisplayValue>label_last_updated</DisplayValue>
|
||||||
|
<Type>default</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>actions</DefinedValue>
|
||||||
|
<DisplayValue>label_actions</DisplayValue>
|
||||||
|
<Type>default</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>batteryLevel</DefinedValue>
|
||||||
|
<DisplayValue>label_battery_leve</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>deviceModel</DefinedValue>
|
||||||
|
<DisplayValue>label_deviceModel</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>osVersion</DefinedValue>
|
||||||
|
<DisplayValue>label_os_version</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>vendor</DefinedValue>
|
||||||
|
<DisplayValue>label_vendor</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>availableRAMMemory</DefinedValue>
|
||||||
|
<DisplayValue>label_available_ram_memory</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>connectionType</DefinedValue>
|
||||||
|
<DisplayValue>label_connection_type</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>cpuUsage</DefinedValue>
|
||||||
|
<DisplayValue>label_cpu_usage</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>externalAvailableMemory</DefinedValue>
|
||||||
|
<DisplayValue>label_external_available_memory</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>externalTotalMemory</DefinedValue>
|
||||||
|
<DisplayValue>label_external_tot_memory</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>internalAvailableMemory</DefinedValue>
|
||||||
|
<DisplayValue>label_internal_available_memory</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>internalTotalMemory</DefinedValue>
|
||||||
|
<DisplayValue>label_internal_tot_memory</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>osBuildDate</DefinedValue>
|
||||||
|
<DisplayValue>label_os_build_date</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>pluggedIn</DefinedValue>
|
||||||
|
<DisplayValue>label_plugged_in</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>ssid</DefinedValue>
|
||||||
|
<DisplayValue>label_ssid</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>totalRAMMemory</DefinedValue>
|
||||||
|
<DisplayValue>label_tot_ram_memory</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
<DeviceInfoItem>
|
||||||
|
<DefinedValue>updatedTime</DefinedValue>
|
||||||
|
<DisplayValue>label_updated_time</DisplayValue>
|
||||||
|
<Type>deviceInfo</Type>
|
||||||
|
</DeviceInfoItem>
|
||||||
|
</DeviceInfoConfigurations>
|
||||||
|
<DeviceStatusConfigurations>
|
||||||
|
<EnableDeviceStatusCheck>true</EnableDeviceStatusCheck>
|
||||||
|
<DeviceStatusItem>
|
||||||
|
<Type>android</Type>
|
||||||
|
<AllowedStatus>
|
||||||
|
<Status>ACTIVE</Status>
|
||||||
|
<Status>CREATED</Status>
|
||||||
|
<Status>INACTIVE</Status>
|
||||||
|
<Status>UNREACHABLE</Status>
|
||||||
|
<Status>UNCLAIMED</Status>
|
||||||
|
<Status>SUSPENDED</Status>
|
||||||
|
<Status>BLOCKED</Status>
|
||||||
|
<Status>REMOVED</Status>
|
||||||
|
<Status>SUSPENDED</Status>
|
||||||
|
<Status>DISENROLLMENT_REQUESTED</Status>
|
||||||
|
</AllowedStatus>
|
||||||
|
</DeviceStatusItem>
|
||||||
|
<DeviceStatusItem>
|
||||||
|
<Type>ios</Type>
|
||||||
|
<AllowedStatus>
|
||||||
|
<Status>ACTIVE</Status>
|
||||||
|
<Status>CREATED</Status>
|
||||||
|
<Status>INACTIVE</Status>
|
||||||
|
<Status>UNREACHABLE</Status>
|
||||||
|
<Status>UNCLAIMED</Status>
|
||||||
|
<Status>SUSPENDED</Status>
|
||||||
|
<Status>BLOCKED</Status>
|
||||||
|
<Status>REMOVED</Status>
|
||||||
|
<Status>SUSPENDED</Status>
|
||||||
|
<Status>DISENROLLMENT_REQUESTED</Status>
|
||||||
|
</AllowedStatus>
|
||||||
|
</DeviceStatusItem>
|
||||||
|
<DeviceStatusItem>
|
||||||
|
<Type>windows</Type>
|
||||||
|
<AllowedStatus>
|
||||||
|
<Status>ACTIVE</Status>
|
||||||
|
<Status>CREATED</Status>
|
||||||
|
<Status>INACTIVE</Status>
|
||||||
|
<Status>UNREACHABLE</Status>
|
||||||
|
<Status>UNCLAIMED</Status>
|
||||||
|
<Status>SUSPENDED</Status>
|
||||||
|
<Status>BLOCKED</Status>
|
||||||
|
<Status>REMOVED</Status>
|
||||||
|
<Status>SUSPENDED</Status>
|
||||||
|
<Status>DISENROLLMENT_REQUESTED</Status>
|
||||||
|
</AllowedStatus>
|
||||||
|
</DeviceStatusItem>
|
||||||
|
</DeviceStatusConfigurations>
|
||||||
|
<AppRegistration>
|
||||||
|
<Tags>
|
||||||
|
<Tag>analytics_management</Tag>
|
||||||
|
<Tag>application_management</Tag>
|
||||||
|
<Tag>device_management</Tag>
|
||||||
|
<Tag>subscription_management</Tag>
|
||||||
|
<Tag>review_management</Tag>
|
||||||
|
</Tags>
|
||||||
|
<AllowToAllDomains>true</AllowToAllDomains>
|
||||||
|
</AppRegistration>
|
||||||
|
<Scopes>
|
||||||
|
<Scope>grafana:api:view</Scope>
|
||||||
|
<Scope>am:store:app:review:view</Scope>
|
||||||
|
<Scope>am:store:app:review:update</Scope>
|
||||||
|
<Scope>am:pub:sp:app:view</Scope>
|
||||||
|
<Scope>am:pub:sp:create</Scope>
|
||||||
|
<Scope>am:pub:sp:attach</Scope>
|
||||||
|
<Scope>am:pub:sp:detach</Scope>
|
||||||
|
<Scope>am:pub:sp:connect</Scope>
|
||||||
|
<Scope>am:pub:app:view</Scope>
|
||||||
|
<Scope>am:pub:app:update</Scope>
|
||||||
|
<Scope>am:store:app:view</Scope>
|
||||||
|
<Scope>am:store:app:modify</Scope>
|
||||||
|
<Scope>am:store:app:sub:install</Scope>
|
||||||
|
<Scope>am:store:app:sub:uninstall</Scope>
|
||||||
|
<Scope>am:admin:pub:app:review:view</Scope>
|
||||||
|
<Scope>am:admin:pub:app:update</Scope>
|
||||||
|
<Scope>am:admin:store:app:review:update</Scope>
|
||||||
|
<Scope>am:admin:store:app:sub:view</Scope>
|
||||||
|
<Scope>am:admin:store:app:sub:modify</Scope>
|
||||||
|
<Scope>dm:device-type:view</Scope>
|
||||||
|
<Scope>and:enterprise:modify</Scope>
|
||||||
|
<Scope>and:enterprise:view</Scope>
|
||||||
|
<Scope>dm:sign-csr</Scope>
|
||||||
|
<Scope>dm:admin:devices:view</Scope>
|
||||||
|
<Scope>dm:devices:status:change</Scope>
|
||||||
|
<Scope>rm:roles:add</Scope>
|
||||||
|
<Scope>rm:users:add</Scope>
|
||||||
|
<Scope>rm:roles:update</Scope>
|
||||||
|
<Scope>rm:roles:permissions:view</Scope>
|
||||||
|
<Scope>rm:roles:details:view</Scope>
|
||||||
|
<Scope>rm:roles:view</Scope>
|
||||||
|
<Scope>rm:roles:combined:add</Scope>
|
||||||
|
<Scope>rm:roles:delete</Scope>
|
||||||
|
<Scope>dm:activity:get</Scope>
|
||||||
|
<Scope>dm:devices:delete</Scope>
|
||||||
|
<Scope>dm:devices:app:view</Scope>
|
||||||
|
<Scope>dm:devices:policy:view</Scope>
|
||||||
|
<Scope>dm:devices:compliance:view</Scope>
|
||||||
|
<Scope>dm:devices:features:view</Scope>
|
||||||
|
<Scope>dm:devices:ops:view</Scope>
|
||||||
|
<Scope>dm:devices:search</Scope>
|
||||||
|
<Scope>dm:devices:details</Scope>
|
||||||
|
<Scope>dm:devices:update</Scope>
|
||||||
|
<Scope>dm:devices:view</Scope>
|
||||||
|
<Scope>dm:devices:enrollment-guide:view</Scope>
|
||||||
|
<Scope>dm:conf:view</Scope>
|
||||||
|
<Scope>dm:conf:manage</Scope>
|
||||||
|
<Scope>pm:policies:remove</Scope>
|
||||||
|
<Scope>pm:policies:priorities:update</Scope>
|
||||||
|
<Scope>pm:policies:deactivate</Scope>
|
||||||
|
<Scope>pm:policies:details:view</Scope>
|
||||||
|
<Scope>pm:policies:add</Scope>
|
||||||
|
<Scope>pm:policies:activate</Scope>
|
||||||
|
<Scope>pm:policies:update</Scope>
|
||||||
|
<Scope>pm:policies:change</Scope>
|
||||||
|
<Scope>dm:policies:view</Scope>
|
||||||
|
<Scope>um:users:add</Scope>
|
||||||
|
<Scope>um:users:details:view</Scope>
|
||||||
|
<Scope>um:users:count</Scope>
|
||||||
|
<Scope>um:users:delete</Scope>
|
||||||
|
<Scope>um:roles:view</Scope>
|
||||||
|
<Scope>um:users:user-details:view</Scope>
|
||||||
|
<Scope>um:users:cred:change</Scope>
|
||||||
|
<Scope>um:users:search</Scope>
|
||||||
|
<Scope>um:users:is-exist</Scope>
|
||||||
|
<Scope>um:users:update</Scope>
|
||||||
|
<Scope>um:users:invite</Scope>
|
||||||
|
<Scope>um:admin:users:view</Scope>
|
||||||
|
<Scope>dm:admin:enrollment:update</Scope>
|
||||||
|
<Scope>gm:devices:view</Scope>
|
||||||
|
<Scope>gm:groups:update</Scope>
|
||||||
|
<Scope>gm:groups:add</Scope>
|
||||||
|
<Scope>gm:groups:device:view</Scope>
|
||||||
|
<Scope>gm:devices:count</Scope>
|
||||||
|
<Scope>gm:devices-types:view</Scope>
|
||||||
|
<Scope>gm:groups:remove</Scope>
|
||||||
|
<Scope>gm:groups:view</Scope>
|
||||||
|
<Scope>gm:groups:groups-view</Scope>
|
||||||
|
<Scope>gm:roles:share</Scope>
|
||||||
|
<Scope>gm:groups:count</Scope>
|
||||||
|
<Scope>gm:roles:view</Scope>
|
||||||
|
<Scope>gm:devices:remove</Scope>
|
||||||
|
<Scope>gm:devices:add</Scope>
|
||||||
|
<Scope>gm:devices:assign</Scope>
|
||||||
|
<Scope>dm:device-type:conf:view</Scope>
|
||||||
|
<Scope>dm:device-type:features:view</Scope>
|
||||||
|
<Scope>dm:device-type:view</Scope>
|
||||||
|
<Scope>am:admin:app:install</Scope>
|
||||||
|
<Scope>am:admin:app:uninstall</Scope>
|
||||||
|
<Scope>gm:admin:groups:count</Scope>
|
||||||
|
<Scope>gm:admin:groups:view</Scope>
|
||||||
|
<Scope>gm:admin:groups:add</Scope>
|
||||||
|
<Scope>dm:notif:mark-checked</Scope>
|
||||||
|
<Scope>dm:notifications:view</Scope>
|
||||||
|
<Scope>cm:cert:delete</Scope>
|
||||||
|
<Scope>cm:cert:details:get</Scope>
|
||||||
|
<Scope>cm:cert:view</Scope>
|
||||||
|
<Scope>cm:cert:add</Scope>
|
||||||
|
<Scope>cm:cert:verify</Scope>
|
||||||
|
<Scope>dm:admin</Scope>
|
||||||
|
<Scope>dm:device-type:deploy</Scope>
|
||||||
|
<Scope>dm:device-type:event:modify</Scope>
|
||||||
|
<Scope>dm:device-type:event:view</Scope>
|
||||||
|
<Scope>dm:admin:device-type:modify</Scope>
|
||||||
|
<Scope>dm:admin:device-type:view</Scope>
|
||||||
|
<Scope>dm:admin:device-type:conf:add</Scope>
|
||||||
|
<Scope>dm:device:enroll</Scope>
|
||||||
|
<Scope>dm:geo:an:view</Scope>
|
||||||
|
<Scope>dm:geo:alerts:manage</Scope>
|
||||||
|
<Scope>dm:admin:devices:permanent-delete</Scope>
|
||||||
|
<Scope>and:conf:manage</Scope>
|
||||||
|
<Scope>and:conf:view</Scope>
|
||||||
|
<Scope>um:users:permission:view</Scope>
|
||||||
|
<Scope>ios:conf:view</Scope>
|
||||||
|
<Scope>ios:conf:manage</Scope>
|
||||||
|
<Scope>ios:dep:view</Scope>
|
||||||
|
<Scope>ios:dep:add</Scope>
|
||||||
|
<Scope>win:conf:view</Scope>
|
||||||
|
<Scope>win:conf:manage</Scope>
|
||||||
|
<Scope>and:ops:lock-devices</Scope>
|
||||||
|
<Scope>and:ops:unlock-devices</Scope>
|
||||||
|
<Scope>and:ops:location</Scope>
|
||||||
|
<Scope>and:ops:clear-password</Scope>
|
||||||
|
<Scope>and:ops:control-camera</Scope>
|
||||||
|
<Scope>and:ops:enterprise-wipe</Scope>
|
||||||
|
<Scope>and:ops:wipe</Scope>
|
||||||
|
<Scope>and:ops:ring</Scope>
|
||||||
|
<Scope>and:ops:app-list</Scope>
|
||||||
|
<Scope>and:ops:reboot</Scope>
|
||||||
|
<Scope>and:ops:change-LockTask</Scope>
|
||||||
|
<Scope>and:ops:mute</Scope>
|
||||||
|
<Scope>and:ops:conf-display-msg</Scope>
|
||||||
|
<Scope>and:ops:send-app-restrictions</Scope>
|
||||||
|
<Scope>and:ops:file-transfer</Scope>
|
||||||
|
<Scope>and:ops:set-webclip</Scope>
|
||||||
|
<Scope>and:ops:password-policy</Scope>
|
||||||
|
<Scope>and:ops:change-lock-code</Scope>
|
||||||
|
<Scope>and:ops:upgrade-firmware</Scope>
|
||||||
|
<Scope>and:ops:send-notif</Scope>
|
||||||
|
<Scope>dm:geo:geo-fence:manage</Scope>
|
||||||
|
<Scope>dm:whitelable:view</Scope>
|
||||||
|
<Scope>dm:whitelable:update</Scope>
|
||||||
|
<Scope>dm:metadata:view</Scope>
|
||||||
|
<Scope>dm:metadata:create</Scope>
|
||||||
|
<Scope>dm:metadata:update</Scope>
|
||||||
|
<Scope>and:ops:add-google-acc</Scope>
|
||||||
|
<Scope>and:ops:authenticate-acc</Scope>
|
||||||
|
<Scope>and:ops:update-default-sim</Scope>
|
||||||
|
<Scope>and:ops:add-google-acc</Scope>
|
||||||
|
<Scope>and:ops:device-info</Scope>
|
||||||
|
<Scope>win:ops:lock-devices</Scope>
|
||||||
|
<Scope>win:devices:enroll</Scope>
|
||||||
|
<Scope>win:ops:disenroll</Scope>
|
||||||
|
<Scope>win:ops:wipe</Scope>
|
||||||
|
<Scope>win:ops:ring</Scope>
|
||||||
|
<Scope>win:ops:lock-reset</Scope>
|
||||||
|
<Scope>win:ops:reboot</Scope>
|
||||||
|
<Scope>win:ops:location</Scope>
|
||||||
|
<Scope>admin:tenant:view</Scope>
|
||||||
|
<Scope>dm:admin:devices:usage:view</Scope>
|
||||||
|
<Scope>and:ops:clear-app</Scope>
|
||||||
|
<Scope>and:ops:suspend-package</Scope>
|
||||||
|
<Scope>and:ops:alternate-install</Scope>
|
||||||
|
<Scope>ios:ops:lock</Scope>
|
||||||
|
<Scope>ios:ops:location</Scope>
|
||||||
|
<Scope>ios:ops:ring</Scope>
|
||||||
|
<Scope>ios:ops:clear-passcode</Scope>
|
||||||
|
<Scope>ios:ops:enterprise-wipe</Scope>
|
||||||
|
<Scope>ios:ops:notif</Scope>
|
||||||
|
<Scope>ios:ops:wipe</Scope>
|
||||||
|
<Scope>ios:ops:boolean-setting</Scope>
|
||||||
|
<Scope>ios:ops:wallpaper</Scope>
|
||||||
|
<Scope>ios:ops:app-attributes</Scope>
|
||||||
|
<Scope>ios:ops:app-conf</Scope>
|
||||||
|
<Scope>mac:ops:restart</Scope>
|
||||||
|
<Scope>mac:ops:shutdown</Scope>
|
||||||
|
<Scope>am:store:vpp:user:modify</Scope>
|
||||||
|
<Scope>am:store:vpp:user:view</Scope>
|
||||||
|
<Scope>am:store:vpp:assets:modify</Scope>
|
||||||
|
<Scope>am:store:vpp:assets:view</Scope>
|
||||||
|
<Scope>and:devices:enroll</Scope>
|
||||||
|
<Scope>ios:devices:enroll</Scope>
|
||||||
|
</Scopes>
|
||||||
|
<SSOConfiguration>
|
||||||
|
<Issuer>device-mgt</Issuer>
|
||||||
|
</SSOConfiguration>
|
||||||
|
</UIConfiguration>
|
@ -0,0 +1,277 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.ui.request.interceptor;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.beans.AuthData;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.beans.JITData;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.beans.JITEnrollmentData;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.beans.ProxyResponse;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.exceptions.JITEnrollmentException;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerConstants;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerUtil;
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.HttpHeaders;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@WebServlet(
|
||||||
|
name = "JIT Enrollment callback handler",
|
||||||
|
description = "Call token endpoint and retrieve token",
|
||||||
|
urlPatterns = {
|
||||||
|
"/jit-enrollment-callback"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public class JITEnrollmentCallbackHandler extends HttpServlet {
|
||||||
|
private static final Log log = LogFactory.getLog(JITEnrollmentCallbackHandler.class);
|
||||||
|
private String gatewayUrl;
|
||||||
|
private String keyManagerUrl;
|
||||||
|
private JITData JITInfo;
|
||||||
|
private String encodedClientCredentials;
|
||||||
|
private String applicationName;
|
||||||
|
private String clientId;
|
||||||
|
private String clientSecret;
|
||||||
|
private String scope;
|
||||||
|
private String JITConfigurationPath;
|
||||||
|
private JITEnrollmentData JITEnrollmentInfo;
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
gatewayUrl = request.getScheme() + HandlerConstants.SCHEME_SEPARATOR
|
||||||
|
+ System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
|
||||||
|
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(request.getScheme());
|
||||||
|
keyManagerUrl = request.getScheme() + HandlerConstants.SCHEME_SEPARATOR
|
||||||
|
+ System.getProperty(HandlerConstants.IOT_KM_HOST_ENV_VAR)
|
||||||
|
+ HandlerConstants.COLON + HandlerUtil.getKeyManagerPort(request.getScheme());
|
||||||
|
JITConfigurationPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "jit-config.xml";
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
try {
|
||||||
|
if (session == null) {
|
||||||
|
response.sendError(HttpStatus.SC_UNAUTHORIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JITInfo = (JITData) session.getAttribute(HandlerConstants.SESSION_JIT_DATA_KEY);
|
||||||
|
if (JITInfo == null) {
|
||||||
|
response.sendError(HttpStatus.SC_UNAUTHORIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JITEnrollmentInfo = (JITEnrollmentData)
|
||||||
|
session.getAttribute(HandlerConstants.SESSION_JIT_ENROLLMENT_DATA_KEY);
|
||||||
|
if (JITEnrollmentInfo == null) {
|
||||||
|
response.sendError(HttpStatus.SC_UNAUTHORIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
applicationName = request.getContextPath().substring(1,
|
||||||
|
request.getContextPath().indexOf("-ui-request-handler"));
|
||||||
|
initializeJITEnrollmentConfigurations();
|
||||||
|
populateApplicationData(registerApplication());
|
||||||
|
persistAuthData(session, getToken());
|
||||||
|
response.sendRedirect(JITEnrollmentInfo.getRedirectUrl() + "?ownershipType=" +
|
||||||
|
JITEnrollmentInfo.getOwnershipType() + "&os=" + JITEnrollmentInfo.getOs() + "&username=" +
|
||||||
|
JITEnrollmentInfo.getUsername() + "&tenantDomain=" + JITEnrollmentInfo.getTenantDomain());
|
||||||
|
} catch (JITEnrollmentException | IOException ex) {
|
||||||
|
log.error("Error occurred while processing JIT provisioning callback request", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeJITEnrollmentConfigurations() throws JITEnrollmentException {
|
||||||
|
try {
|
||||||
|
File JITConfigurationFile = new File(JITConfigurationPath);
|
||||||
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||||
|
Document JITConfigurationDoc = documentBuilder.parse(JITConfigurationFile);
|
||||||
|
JITConfigurationDoc.getDocumentElement().normalize();
|
||||||
|
Element enrollmentScopes;
|
||||||
|
if (Objects.equals(JITEnrollmentInfo.getOs(), HandlerConstants.OS_ANDROID)) {
|
||||||
|
enrollmentScopes = (Element) JITConfigurationDoc.
|
||||||
|
getElementsByTagName(HandlerConstants.TAG_ANDROID_ENROLLMENT_SCOPES).item(0);
|
||||||
|
} else if (Objects.equals(JITEnrollmentInfo.getOs(), HandlerConstants.OS_IOS)) {
|
||||||
|
enrollmentScopes = (Element) JITConfigurationDoc.
|
||||||
|
getElementsByTagName(HandlerConstants.TAG_IOS_ENROLLMENT_SCOPES).item(0);
|
||||||
|
} else if (Objects.equals(JITEnrollmentInfo.getOs(), HandlerConstants.OS_WINDOWS)) {
|
||||||
|
enrollmentScopes = (Element) JITConfigurationDoc.
|
||||||
|
getElementsByTagName(HandlerConstants.TAG_WINDOWS_ENROLLMENT_SCOPES).item(0);
|
||||||
|
} else {
|
||||||
|
String msg = "OS type not supported";
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error(msg);
|
||||||
|
}
|
||||||
|
throw new JITEnrollmentException(msg);
|
||||||
|
}
|
||||||
|
NodeList scopeList = enrollmentScopes.getElementsByTagName("Scope");
|
||||||
|
StringBuilder scopeStr = new StringBuilder();
|
||||||
|
for (int idx = 0; idx < scopeList.getLength(); idx++) {
|
||||||
|
Node scopeNode = scopeList.item(idx);
|
||||||
|
if (scopeNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
|
Element scopeElement = (Element) scopeNode;
|
||||||
|
scopeStr.append(" ").append(scopeElement.getTextContent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scope = scopeStr.toString();
|
||||||
|
} catch (ParserConfigurationException ex) {
|
||||||
|
String msg = "Error occurred when document builder creating the file configuration";
|
||||||
|
throw new JITEnrollmentException(msg, ex);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
String msg = "IO error occurred while parsing the JIT config file";
|
||||||
|
throw new JITEnrollmentException(msg, ex);
|
||||||
|
} catch (SAXException ex) {
|
||||||
|
String msg = "Parse error occurred while parsing the JIT config document";
|
||||||
|
throw new JITEnrollmentException(msg, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Parse string data and build json object
|
||||||
|
* @param data - Json string
|
||||||
|
* @return {@link JsonObject} Json object corresponding to provided json string
|
||||||
|
* @throws JITEnrollmentException throws when error occurred while parsing
|
||||||
|
*/
|
||||||
|
private JsonObject parseResponseData(String data) throws JITEnrollmentException {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
JsonElement responseData = parser.parse(data);
|
||||||
|
if (responseData.isJsonObject()) {
|
||||||
|
return responseData.getAsJsonObject();
|
||||||
|
}
|
||||||
|
throw new JITEnrollmentException("Unexpected response body return");
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Build application registration request
|
||||||
|
* @return {@link HttpPost} Application registration request
|
||||||
|
*/
|
||||||
|
private HttpPost buildApplicationRegistrationRequest() {
|
||||||
|
HttpPost applicationRegistrationRequest = new HttpPost(gatewayUrl + HandlerConstants.APP_REG_ENDPOINT);
|
||||||
|
applicationRegistrationRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BASIC
|
||||||
|
+ JITInfo.getEncodedClientCredentials());
|
||||||
|
applicationRegistrationRequest.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
|
||||||
|
JsonArray tags = new JsonArray();
|
||||||
|
tags.add("device_management");
|
||||||
|
JsonObject payload = new JsonObject();
|
||||||
|
payload.addProperty("applicationName", applicationName);
|
||||||
|
payload.add("tags", tags);
|
||||||
|
payload.addProperty("allowedToAllDomains", false);
|
||||||
|
payload.addProperty("mappingAnExistingOAuthApp", false);
|
||||||
|
applicationRegistrationRequest.setEntity(new StringEntity(payload.toString(), ContentType.APPLICATION_JSON));
|
||||||
|
return applicationRegistrationRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Populate dynamic client's data
|
||||||
|
* @param application - application data receiving from dcr request
|
||||||
|
*/
|
||||||
|
private void populateApplicationData(JsonObject application) {
|
||||||
|
clientId = application.get("client_id").getAsString();
|
||||||
|
clientSecret = application.get("client_secret").getAsString();
|
||||||
|
String headerValue = clientId+ ':' + clientSecret;
|
||||||
|
encodedClientCredentials = Base64.getEncoder().encodeToString(headerValue.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Register client application
|
||||||
|
* @return {@link JsonObject} Json object contain registered application data
|
||||||
|
* @throws JITEnrollmentException throws when error occurred while application registration
|
||||||
|
*/
|
||||||
|
private JsonObject registerApplication() throws JITEnrollmentException {
|
||||||
|
try {
|
||||||
|
ProxyResponse proxyResponse = HandlerUtil.execute(buildApplicationRegistrationRequest());
|
||||||
|
if (proxyResponse.getCode() == HttpStatus.SC_CREATED ||
|
||||||
|
proxyResponse.getCode() == HttpStatus.SC_OK) {
|
||||||
|
return parseResponseData(proxyResponse.getData());
|
||||||
|
}
|
||||||
|
throw new JITEnrollmentException("Unexpected response status return for application registration request");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new JITEnrollmentException("Error occurred while executing application registration request", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Acquire token
|
||||||
|
* @return {@link JsonObject} Json object containing token data
|
||||||
|
* @throws JITEnrollmentException throws when error occurred while acquiring token
|
||||||
|
*/
|
||||||
|
private JsonObject getToken() throws JITEnrollmentException {
|
||||||
|
try {
|
||||||
|
ProxyResponse proxyResponse = HandlerUtil.execute(buildTokenAcquireRequest());
|
||||||
|
if (proxyResponse.getCode() == org.apache.http.HttpStatus.SC_CREATED ||
|
||||||
|
proxyResponse.getCode() == org.apache.http.HttpStatus.SC_OK) {
|
||||||
|
return parseResponseData(proxyResponse.getData());
|
||||||
|
}
|
||||||
|
throw new JITEnrollmentException("Unexpected response status return for token acquiring request");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new JITEnrollmentException("Error occurred while executing token acquiring request", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Build token acquire request
|
||||||
|
* @return {@link HttpPost} Token acquire request
|
||||||
|
*/
|
||||||
|
private HttpPost buildTokenAcquireRequest() {
|
||||||
|
HttpPost tokenAcquiringRequest = new HttpPost(keyManagerUrl + HandlerConstants.OAUTH2_TOKEN_ENDPOINT);
|
||||||
|
tokenAcquiringRequest.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString());
|
||||||
|
tokenAcquiringRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BASIC
|
||||||
|
+ encodedClientCredentials);
|
||||||
|
StringEntity payload = new StringEntity(
|
||||||
|
"grant_type=" + HandlerConstants.CLIENT_CREDENTIAL_GRANT_TYPE + "&scope=" + scope,
|
||||||
|
ContentType.APPLICATION_FORM_URLENCODED);
|
||||||
|
tokenAcquiringRequest.setEntity(payload);
|
||||||
|
return tokenAcquiringRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Persists auth data in session
|
||||||
|
* @param session - {@link HttpSession}
|
||||||
|
* @param token - Json object containing token data
|
||||||
|
*/
|
||||||
|
private void persistAuthData(HttpSession session, JsonObject token) {
|
||||||
|
AuthData authData = new AuthData();
|
||||||
|
authData.setAccessToken(token.get("access_token").getAsString());
|
||||||
|
authData.setClientId(clientId);
|
||||||
|
authData.setClientSecret(clientSecret);
|
||||||
|
authData.setEncodedClientApp(encodedClientCredentials);
|
||||||
|
authData.setScope(token.get("scope").getAsString());
|
||||||
|
session.setAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY, authData);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.ui.request.interceptor;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.beans.JITEnrollmentData;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.exceptions.JITEnrollmentException;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerConstants;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerUtil;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@WebServlet(
|
||||||
|
name = "JIT enrollment handler",
|
||||||
|
description = "Handle jit enrollment request",
|
||||||
|
urlPatterns = {
|
||||||
|
"/jit-enrollment"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public class JITEnrollmentHandler extends HttpServlet {
|
||||||
|
private static final Log log = LogFactory.getLog(JITEnrollmentHandler.class);
|
||||||
|
private String username;
|
||||||
|
private String ownershipType;
|
||||||
|
private String os;
|
||||||
|
private String redirectUrl;
|
||||||
|
private String tenantDomain;
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
HttpSession session = request.getSession(true);
|
||||||
|
String JITProvisionHandlerUrl = request.getScheme() + HandlerConstants.SCHEME_SEPARATOR
|
||||||
|
+ System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
|
||||||
|
+ HandlerConstants.COLON + HandlerUtil.getCorePort(request.getScheme())
|
||||||
|
+ request.getContextPath()
|
||||||
|
+ HandlerConstants.JIT_PROVISION_HANDLER;
|
||||||
|
String onCompletionUrl = request.getScheme() + HandlerConstants.SCHEME_SEPARATOR
|
||||||
|
+ System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
|
||||||
|
+ HandlerConstants.COLON + HandlerUtil.getCorePort(request.getScheme())
|
||||||
|
+ request.getContextPath()
|
||||||
|
+ "/jit-enrollment-callback";
|
||||||
|
username = request.getParameter("username");
|
||||||
|
ownershipType = request.getParameter("ownershipType");
|
||||||
|
os = request.getParameter("os");
|
||||||
|
redirectUrl = request.getParameter("redirectUrl");
|
||||||
|
tenantDomain = request.getParameter("tenantDomain");
|
||||||
|
String sp = request.getParameter("sp");
|
||||||
|
persistJITData(session);
|
||||||
|
response.sendRedirect(JITProvisionHandlerUrl + "?tenantDomain=" + tenantDomain
|
||||||
|
+ "&sp=" + sp + "&redirectUrl=" + onCompletionUrl);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error("Error occurred while handling JIT enrollment request");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Persists JIT data in session
|
||||||
|
* @param session - {@link HttpSession}
|
||||||
|
*/
|
||||||
|
private void persistJITData(HttpSession session) {
|
||||||
|
JITEnrollmentData JITEnrollmentInfo = new JITEnrollmentData();
|
||||||
|
JITEnrollmentInfo.setOwnershipType(ownershipType);
|
||||||
|
JITEnrollmentInfo.setOs(os);
|
||||||
|
JITEnrollmentInfo.setUsername(username);
|
||||||
|
JITEnrollmentInfo.setRedirectUrl(redirectUrl);
|
||||||
|
JITEnrollmentInfo.setTenantDomain(tenantDomain);
|
||||||
|
session.setAttribute(HandlerConstants.SESSION_JIT_ENROLLMENT_DATA_KEY, JITEnrollmentInfo);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.ui.request.interceptor;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.beans.JITData;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.beans.JITEnrollmentData;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerConstants;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerUtil;
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@WebServlet(
|
||||||
|
name = "JIT callback handler",
|
||||||
|
description = "Call token endpoint and retrieve token",
|
||||||
|
urlPatterns = {
|
||||||
|
"/jit-provision-callback"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public class JITProvisionCallbackHandler extends HttpServlet {
|
||||||
|
private static final Log log = LogFactory.getLog(JITProvisionCallbackHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
String state = request.getParameter("state");
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
String JITProvisionCallbackURL = request.getScheme() + HandlerConstants.SCHEME_SEPARATOR
|
||||||
|
+ System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
|
||||||
|
+ HandlerConstants.COLON + HandlerUtil.getCorePort(request.getScheme())
|
||||||
|
+ request.getContextPath()
|
||||||
|
+ HandlerConstants.JIT_PROVISION_CALLBACK_URL;
|
||||||
|
try {
|
||||||
|
if (session == null) {
|
||||||
|
response.sendError(HttpStatus.SC_UNAUTHORIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state == null || !Objects.equals(state, session.getAttribute("state").toString())) {
|
||||||
|
response.sendError(org.apache.http.HttpStatus.SC_BAD_REQUEST, "MismatchingStateError: CSRF Warning! " +
|
||||||
|
"State not equal in request and response");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JITData JITInfo = (JITData) session.getAttribute(HandlerConstants.SESSION_JIT_DATA_KEY);
|
||||||
|
if (JITInfo == null) {
|
||||||
|
response.sendError(HttpStatus.SC_UNAUTHORIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.sendRedirect(JITInfo.getRedirectUrl() + "?code=" + request.getParameter("code")
|
||||||
|
+ "&redirectUrl=" + JITProvisionCallbackURL);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error("Error occurred while processing JIT provisioning callback request", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,198 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.ui.request.interceptor;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.beans.JITData;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.beans.ProxyResponse;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.exceptions.JITEnrollmentException;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.exceptions.JITProvisionException;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerConstants;
|
||||||
|
import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerUtil;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.HttpHeaders;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
|
@WebServlet(
|
||||||
|
name = "JITProvisionRequestHandlerServlet",
|
||||||
|
description = "Handle Just In Time Provisioning requests",
|
||||||
|
urlPatterns = {
|
||||||
|
"/jit-provision"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public class JITProvisionHandler extends HttpServlet {
|
||||||
|
private static final Log log = LogFactory.getLog(JITProvisionHandler.class);
|
||||||
|
private String tenantDomain;
|
||||||
|
private String clientId;
|
||||||
|
private String JITServiceProviderName;
|
||||||
|
private String encodedClientCredentials;
|
||||||
|
private String JITConfigurationPath;
|
||||||
|
private String redirectUrl;
|
||||||
|
private String state;
|
||||||
|
private static final Map<String, Element> tenantConfigs = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
String keyManagerUrl = request.getScheme() + HandlerConstants.SCHEME_SEPARATOR
|
||||||
|
+ System.getProperty(HandlerConstants.IOT_KM_HOST_ENV_VAR)
|
||||||
|
+ HandlerConstants.COLON + HandlerUtil.getKeyManagerPort(request.getScheme());
|
||||||
|
String JITCallbackUrl = request.getScheme() + HandlerConstants.SCHEME_SEPARATOR
|
||||||
|
+ System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
|
||||||
|
+ HandlerConstants.COLON + HandlerUtil.getCorePort(request.getScheme())
|
||||||
|
+ request.getContextPath()
|
||||||
|
+ HandlerConstants.JIT_PROVISION_CALLBACK_URL;
|
||||||
|
JITConfigurationPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "jit-config.xml";
|
||||||
|
String scope = "openid";
|
||||||
|
state = HandlerUtil.generateStateToken();
|
||||||
|
tenantDomain = request.getParameter("tenantDomain");
|
||||||
|
redirectUrl = request.getParameter("redirectUrl");
|
||||||
|
JITServiceProviderName = request.getParameter("sp");
|
||||||
|
try {
|
||||||
|
if (tenantDomain == null || JITServiceProviderName == null) {
|
||||||
|
HandlerUtil.handleError(response, HttpStatus.SC_BAD_REQUEST);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!initializeJITConfigurations()) {
|
||||||
|
HandlerUtil.handleError(response, HttpStatus.SC_SERVICE_UNAVAILABLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
persistJITData(request.getSession(true));
|
||||||
|
response.sendRedirect(keyManagerUrl + HandlerConstants.AUTHORIZATION_ENDPOINT +
|
||||||
|
"?response_type=code" +
|
||||||
|
"&client_id=" + clientId +
|
||||||
|
"&state=" + state +
|
||||||
|
"&scope=" + scope +
|
||||||
|
"&redirect_uri=" + JITCallbackUrl);
|
||||||
|
} catch (JITProvisionException | IOException ex) {
|
||||||
|
log.error("Error occurred while processing JIT provisioning request", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Retrieve JIT data from current session if session exists, otherwise build and return
|
||||||
|
* @param session - {@link HttpSession}
|
||||||
|
* @return {@link JITData}
|
||||||
|
*/
|
||||||
|
private JITData getJITData(HttpSession session) {
|
||||||
|
return (session.getAttribute(HandlerConstants.SESSION_JIT_DATA_KEY) != null) ?
|
||||||
|
(JITData) session.getAttribute(HandlerConstants.SESSION_JIT_DATA_KEY) : new JITData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Persists JIT data in session
|
||||||
|
* @param session {@link HttpSession}
|
||||||
|
*/
|
||||||
|
private void persistJITData(HttpSession session) {
|
||||||
|
JITData JITInfo = getJITData(session);
|
||||||
|
JITInfo.setEncodedClientCredentials(encodedClientCredentials);
|
||||||
|
JITInfo.setTenantDomain(tenantDomain);
|
||||||
|
JITInfo.setRedirectUrl(redirectUrl);
|
||||||
|
JITInfo.setSp(JITServiceProviderName);
|
||||||
|
session.setMaxInactiveInterval(3600);
|
||||||
|
session.setAttribute("state", state);
|
||||||
|
session.setAttribute(HandlerConstants.SESSION_JIT_DATA_KEY, JITInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Find the tenant based configurations and return
|
||||||
|
* @param tenantDomain - Domain of the tenant
|
||||||
|
* @param document - Config doc
|
||||||
|
* @return {@link Element} If config found return configuration element, otherwise null
|
||||||
|
*/
|
||||||
|
private Element findServiceProvider(String tenantDomain, Document document) {
|
||||||
|
NodeList serviceProviderConfiguration = document.getElementsByTagName("ServiceProvider");
|
||||||
|
for (int idx = 0; idx < serviceProviderConfiguration.getLength(); idx++) {
|
||||||
|
Node configNode = serviceProviderConfiguration.item(idx);
|
||||||
|
if (configNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
|
Element configElement = (Element) configNode;
|
||||||
|
if (Objects.equals(configElement.getAttributes().
|
||||||
|
getNamedItem("tenantDomain").getNodeValue(), tenantDomain) &&
|
||||||
|
Objects.equals(configElement.getAttributes().getNamedItem("name").getNodeValue(),
|
||||||
|
JITServiceProviderName)) {
|
||||||
|
return configElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Initialize JIT configurations
|
||||||
|
* @return boolean true when successful initialization, otherwise false
|
||||||
|
* @throws JITProvisionException throws when error occurred
|
||||||
|
*/
|
||||||
|
private boolean initializeJITConfigurations() throws JITProvisionException {
|
||||||
|
try {
|
||||||
|
Element serviceProvider = tenantConfigs.get(tenantDomain);
|
||||||
|
if (serviceProvider == null) {
|
||||||
|
File JITConfigurationFile = new File(JITConfigurationPath);
|
||||||
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||||
|
Document JITConfigurationDoc = documentBuilder.parse(JITConfigurationFile);
|
||||||
|
JITConfigurationDoc.getDocumentElement().normalize();
|
||||||
|
serviceProvider = findServiceProvider(tenantDomain, JITConfigurationDoc);
|
||||||
|
if (serviceProvider == null) return false;
|
||||||
|
tenantConfigs.put(tenantDomain, serviceProvider);
|
||||||
|
}
|
||||||
|
clientId = serviceProvider.getElementsByTagName("ClientId").item(0).getTextContent();
|
||||||
|
String clientSecret = serviceProvider.getElementsByTagName("ClientSecret").item(0).getTextContent();
|
||||||
|
String headerValue = clientId + ":" + clientSecret;
|
||||||
|
encodedClientCredentials = Base64.getEncoder().encodeToString(headerValue.getBytes());
|
||||||
|
return true;
|
||||||
|
} catch (ParserConfigurationException ex) {
|
||||||
|
String msg = "Error occurred when document builder creating the file configuration";
|
||||||
|
throw new JITProvisionException(msg, ex);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
String msg = "IO error occurred while parsing the JIT config file";
|
||||||
|
throw new JITProvisionException(msg, ex);
|
||||||
|
} catch (SAXException ex) {
|
||||||
|
String msg = "Parse error occurred while parsing the JIT config document";
|
||||||
|
throw new JITProvisionException(msg, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||||
|
*
|
||||||
|
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://entgra.io/licenses/entgra-commercial/1.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.ui.request.interceptor.beans;
|
||||||
|
|
||||||
|
public class JITData {
|
||||||
|
private String username;
|
||||||
|
private String tenantDomain;
|
||||||
|
private String redirectUrl;
|
||||||
|
private String sp;
|
||||||
|
private String encodedClientCredentials;
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTenantDomain() {
|
||||||
|
return tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantDomain(String tenantDomain) {
|
||||||
|
this.tenantDomain = tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRedirectUrl() {
|
||||||
|
return redirectUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRedirectUrl(String redirectUrl) {
|
||||||
|
this.redirectUrl = redirectUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSp() {
|
||||||
|
return sp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSp(String sp) {
|
||||||
|
this.sp = sp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEncodedClientCredentials() {
|
||||||
|
return encodedClientCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEncodedClientCredentials(String encodedClientCredentials) {
|
||||||
|
this.encodedClientCredentials = encodedClientCredentials;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||||
|
*
|
||||||
|
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://entgra.io/licenses/entgra-commercial/1.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.ui.request.interceptor.beans;
|
||||||
|
|
||||||
|
public class JITEnrollmentData {
|
||||||
|
private String username;
|
||||||
|
private String tenantDomain;
|
||||||
|
private String ownershipType;
|
||||||
|
private String os;
|
||||||
|
private String redirectUrl;
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTenantDomain() {
|
||||||
|
return tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantDomain(String tenantDomain) {
|
||||||
|
this.tenantDomain = tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwnershipType() {
|
||||||
|
return ownershipType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnershipType(String ownershipType) {
|
||||||
|
this.ownershipType = ownershipType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOs() {
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOs(String os) {
|
||||||
|
this.os = os;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRedirectUrl() {
|
||||||
|
return redirectUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRedirectUrl(String redirectUrl) {
|
||||||
|
this.redirectUrl = redirectUrl;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||||
|
*
|
||||||
|
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://entgra.io/licenses/entgra-commercial/1.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.ui.request.interceptor.exceptions;
|
||||||
|
|
||||||
|
public class JITEnrollmentException extends Exception {
|
||||||
|
public JITEnrollmentException(String msg, Throwable t) {
|
||||||
|
super(msg, t);
|
||||||
|
}
|
||||||
|
public JITEnrollmentException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||||
|
*
|
||||||
|
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://entgra.io/licenses/entgra-commercial/1.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.ui.request.interceptor.exceptions;
|
||||||
|
|
||||||
|
public class JITProvisionException extends Exception {
|
||||||
|
public JITProvisionException(String msg, Throwable t) {
|
||||||
|
super(msg, t);
|
||||||
|
}
|
||||||
|
public JITProvisionException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
~ Version 2.0 (the "License"); you may not use this file except
|
||||||
|
~ in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
|
~ software distributed under the License is distributed on an
|
||||||
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
~ KIND, either express or implied. See the License for the
|
||||||
|
~ specific language governing permissions and limitations
|
||||||
|
~ under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<JITConfiguration>
|
||||||
|
<EnrollmentConfiguration>
|
||||||
|
<AndroidEnrollmentScopes>
|
||||||
|
<Scope>dm:metadata:view</Scope>
|
||||||
|
<Scope>dm:metadata:create</Scope>
|
||||||
|
<Scope>dm:metadata:update</Scope>
|
||||||
|
<Scope>and:devices:enroll</Scope>
|
||||||
|
<Scope>dm:device:enroll</Scope>
|
||||||
|
<Scope>and:conf:view</Scope>
|
||||||
|
</AndroidEnrollmentScopes>
|
||||||
|
<IOSEnrollmentScopes>
|
||||||
|
<!-- <Scope></Scope> -->
|
||||||
|
</IOSEnrollmentScopes>
|
||||||
|
<WindowsEnrollmentScopes>
|
||||||
|
<!-- <Scope></Scope> -->
|
||||||
|
</WindowsEnrollmentScopes>
|
||||||
|
</EnrollmentConfiguration>
|
||||||
|
<ServiceProviderConfiguration>
|
||||||
|
<!--<ServiceProvider tenantDomain="" name="">
|
||||||
|
<ClientId></ClientId>
|
||||||
|
<ClientSecret></ClientSecret>
|
||||||
|
</ServiceProvider>-->
|
||||||
|
</ServiceProviderConfiguration>
|
||||||
|
</JITConfiguration>
|
@ -0,0 +1,61 @@
|
|||||||
|
#*
|
||||||
|
Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||||
|
|
||||||
|
Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||||
|
|
||||||
|
Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
https://entgra.io/licenses/entgra-commercial/1.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.
|
||||||
|
*#
|
||||||
|
<EmailConfig>
|
||||||
|
<Subject>You have been invited to enroll your $device-type device in Entgra IoT</Subject>
|
||||||
|
<Body>
|
||||||
|
<![CDATA[
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Entgra IoT Server</title>
|
||||||
|
</head>
|
||||||
|
<body style="color: #666666; background-color:#cdcdcd; padding: 0px; margin: 0px;">
|
||||||
|
<div style="background-color:#cdcdcd; font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; padding: 20px 0px; margin: 0px;">
|
||||||
|
<div style="width: 86%; max-width: 650px; padding: 2%; background-color: #ffffff; margin: auto; border-radius: 14px;">
|
||||||
|
<div style="line-height: 0px; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: 10px;">
|
||||||
|
<div style="display: inline-block; line-height: 0px;">
|
||||||
|
<img alt="entgra" src="https://storage.googleapis.com/cdn-entgra/logo.png" height="50px" width="143px" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="background-color: #ffffff; line-height: 170%; color: #666666; padding: 20px 25px;">
|
||||||
|
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px 20px;">
|
||||||
|
Hi $username,
|
||||||
|
</p>
|
||||||
|
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||||
|
You have been invited by $invite-by to enrol your $device-type device in Entgra IoT Server.
|
||||||
|
Click <a href="$base-url-https/enroll-web-agent/$device-type/provision?username=$username&sp=$sp&tenantDomain=$tenant-domain&ownershipType=$ownership-type&os=$device-type">here</a> to begin device
|
||||||
|
enrolment.</p>
|
||||||
|
|
||||||
|
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||||
|
Should you need assistance, please contact your administrator.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p style="font-length: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
|
||||||
|
Regards,
|
||||||
|
</p>
|
||||||
|
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||||
|
Entgra IoT Administrator
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
]]>
|
||||||
|
</Body>
|
||||||
|
</EmailConfig>
|
Loading…
Reference in new issue