mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://gitlab.com/entgra/carbon-device-mgt
This commit is contained in:
commit
573a9e598c
@ -417,5 +417,11 @@
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity.framework</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.claim.metadata.mgt</artifactId>
|
||||
<version>${carbon.identity.framework.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -14,24 +14,28 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics.reporting;
|
||||
|
||||
package org.wso2.carbon.device.mgt.common.policy.mgt.ui;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
public class Stream {
|
||||
|
||||
@XmlRootElement(name = "NotificationList")
|
||||
public class NotificationList {
|
||||
String deviceIdentifier;
|
||||
Map<String, String> events;
|
||||
|
||||
List<Notification> notification;
|
||||
|
||||
@XmlElement(name = "Notification")
|
||||
public List<Notification> getConditions() {
|
||||
return notification;
|
||||
public String getDeviceIdentifier() {
|
||||
return deviceIdentifier;
|
||||
}
|
||||
|
||||
public void setConditions(List<Notification> notification) {
|
||||
this.notification = notification;
|
||||
public void setDeviceIdentifier(String deviceIdentifier) {
|
||||
this.deviceIdentifier = deviceIdentifier;
|
||||
}
|
||||
|
||||
public Map<String, String> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
public void setEvents(Map<String, String> events) {
|
||||
this.events = events;
|
||||
}
|
||||
}
|
||||
@ -67,6 +67,11 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementAdminService;
|
||||
import org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO;
|
||||
import org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO;
|
||||
import org.wso2.carbon.identity.claim.metadata.mgt.dto.LocalClaimDTO;
|
||||
import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException;
|
||||
import org.wso2.carbon.identity.user.store.count.UserStoreCountRetriever;
|
||||
import org.wso2.carbon.identity.user.store.count.exception.UserStoreCounterException;
|
||||
import org.wso2.carbon.user.api.Permission;
|
||||
@ -934,6 +939,12 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
@PathParam("username") String username,
|
||||
JsonArray deviceList) {
|
||||
try {
|
||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
if (!userStoreManager.isExistingUser(username)) {
|
||||
String msg = "User by username: " + username + " does not exist.";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
}
|
||||
RealmConfiguration realmConfiguration = PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||
.getUserRealm()
|
||||
.getRealmConfiguration();
|
||||
@ -942,14 +953,31 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
if (!StringUtils.isBlank(domain)) {
|
||||
username = domain + Constants.FORWARD_SLASH + username;
|
||||
}
|
||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
if (!userStoreManager.isExistingUser(username)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("User by username: " + username + " does not exist.");
|
||||
}
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(
|
||||
"User doesn't exist.").build()).build();
|
||||
ClaimMetadataManagementAdminService
|
||||
claimMetadataManagementAdminService = new ClaimMetadataManagementAdminService();
|
||||
//Get all available claim URIs
|
||||
String[] allUserClaims = userStoreManager.getClaimManager().getAllClaimUris();
|
||||
//Check they contains a claim attribute for external devices
|
||||
if (!Arrays.asList(allUserClaims).contains(Constants.USER_CLAIM_DEVICES)) {
|
||||
List<ClaimPropertyDTO> claimPropertyDTOList = new ArrayList<>();
|
||||
claimPropertyDTOList
|
||||
.add(DeviceMgtAPIUtils.buildClaimPropertyDTO
|
||||
(Constants.ATTRIBUTE_DISPLAY_NAME, Constants.EXTERNAL_DEVICE_CLAIM_DISPLAY_NAME));
|
||||
claimPropertyDTOList
|
||||
.add(DeviceMgtAPIUtils.buildClaimPropertyDTO
|
||||
(Constants.ATTRIBUTE_DESCRIPTION, Constants.EXTERNAL_DEVICE_CLAIM_DESCRIPTION));
|
||||
|
||||
LocalClaimDTO localClaimDTO = new LocalClaimDTO();
|
||||
localClaimDTO.setLocalClaimURI(Constants.USER_CLAIM_DEVICES);
|
||||
localClaimDTO.setClaimProperties(claimPropertyDTOList.toArray(
|
||||
new ClaimPropertyDTO[claimPropertyDTOList.size()]));
|
||||
|
||||
AttributeMappingDTO attributeMappingDTO = new AttributeMappingDTO();
|
||||
attributeMappingDTO.setAttributeName(Constants.DEVICES);
|
||||
attributeMappingDTO.setUserStoreDomain(domain);
|
||||
localClaimDTO.setAttributeMappings(new AttributeMappingDTO[]{attributeMappingDTO});
|
||||
|
||||
claimMetadataManagementAdminService.addLocalClaim(localClaimDTO);
|
||||
}
|
||||
Map<String, String> userClaims =
|
||||
this.buildExternalDevicesUserClaims(username, domain, deviceList, userStoreManager);
|
||||
@ -958,8 +986,11 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error occurred while updating external device claims of the user '" + username + "'";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (ClaimMetadataException e) {
|
||||
String msg = "Error occurred while adding claim attribute";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -969,6 +1000,13 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
public Response getUserClaimsForDevices(
|
||||
@PathParam("username") String username) {
|
||||
try {
|
||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
Map<String, String> claims = new HashMap<>();
|
||||
if (!userStoreManager.isExistingUser(username)) {
|
||||
String msg = "User by username: " + username + " does not exist.";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
}
|
||||
RealmConfiguration realmConfiguration = PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||
.getUserRealm()
|
||||
.getRealmConfiguration();
|
||||
@ -977,23 +1015,20 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
if (!StringUtils.isBlank(domain)) {
|
||||
username = domain + Constants.FORWARD_SLASH + username;
|
||||
}
|
||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
if (!userStoreManager.isExistingUser(username)) {
|
||||
String[] allUserClaims = userStoreManager.getClaimManager().getAllClaimUris();
|
||||
if (!Arrays.asList(allUserClaims).contains(Constants.USER_CLAIM_DEVICES)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("User by username: " + username + " does not exist.");
|
||||
log.debug("Claim attribute for external device doesn't exist.");
|
||||
}
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(
|
||||
"User doesn't exist.").build()).build();
|
||||
return Response.status(Response.Status.OK).entity(claims).build();
|
||||
}
|
||||
String[] claimArray = {Constants.USER_CLAIM_DEVICES};
|
||||
Map<String, String> claims = userStoreManager.getUserClaimValues(username, claimArray, domain);
|
||||
claims = userStoreManager.getUserClaimValues(username, claimArray, domain);
|
||||
return Response.status(Response.Status.OK).entity(claims).build();
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error occurred while retrieving external device claims of the user '" + username + "'";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1003,6 +1038,13 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
public Response deleteUserClaimsForDevices(
|
||||
@PathParam("username") String username) {
|
||||
try {
|
||||
String[] claimArray = new String[1];
|
||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
if (!userStoreManager.isExistingUser(username)) {
|
||||
String msg = "User by username: " + username + " does not exist.";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
}
|
||||
RealmConfiguration realmConfiguration = PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||
.getUserRealm()
|
||||
.getRealmConfiguration();
|
||||
@ -1011,16 +1053,14 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
if (!StringUtils.isBlank(domain)) {
|
||||
username = domain + Constants.FORWARD_SLASH + username;
|
||||
}
|
||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
if (!userStoreManager.isExistingUser(username)) {
|
||||
String[] allUserClaims = userStoreManager.getClaimManager().getAllClaimUris();
|
||||
if (!Arrays.asList(allUserClaims).contains(Constants.USER_CLAIM_DEVICES)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("User by username: " + username + " does not exist.");
|
||||
log.debug("Claim attribute for external device doesn't exist.");
|
||||
}
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(
|
||||
"User doesn't exist.").build()).build();
|
||||
return Response.status(Response.Status.OK).entity(claimArray).build();
|
||||
}
|
||||
String[] claimArray = {Constants.USER_CLAIM_DEVICES};
|
||||
claimArray[0] = Constants.USER_CLAIM_DEVICES;
|
||||
userStoreManager.deleteUserClaimValues(
|
||||
username,
|
||||
claimArray,
|
||||
@ -1029,8 +1069,7 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error occurred while deleting external device claims of the user '" + username + "'";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -361,35 +361,30 @@ public class RequestValidationUtil {
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
|
||||
.setMessage(msg).build());
|
||||
} catch (InstantiationException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
String msg = "Error when creating an instance of validator related to deviceType " + deviceType;
|
||||
log.error(msg, e);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
|
||||
.setMessage(msg).build());
|
||||
log.debug(msg, e);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
String msg = "Error when accessing an instance of validator related to deviceType " + deviceType;
|
||||
log.error(msg, e);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
|
||||
.setMessage(msg).build());
|
||||
log.debug(msg, e);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
String msg = "Error when loading an instance of validator related to deviceType " + deviceType;
|
||||
log.error(msg, e);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
|
||||
.setMessage(msg).build());
|
||||
log.debug(msg, e);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
String msg = "Error occurred while constructing validator related to deviceType " + deviceType;
|
||||
log.error(msg, e);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
|
||||
.setMessage(msg).build());
|
||||
log.debug(msg, e);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
String msg = "Error occurred while instantiating validator related to deviceType " + deviceType;
|
||||
log.error(msg, e);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
|
||||
.setMessage(msg).build());
|
||||
log.debug(msg, e);
|
||||
}
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
@ -69,6 +69,11 @@ public class Constants {
|
||||
public static final String NOTNOW = "notnow";
|
||||
public static final String REPEATED = "repeated";
|
||||
}
|
||||
public static final String DEVICES = "devices";
|
||||
public static final String ATTRIBUTE_DISPLAY_NAME = "DisplayName";
|
||||
public static final String ATTRIBUTE_DESCRIPTION = "Description";
|
||||
public static final String EXTERNAL_DEVICE_CLAIM_DISPLAY_NAME = "Devices";
|
||||
public static final String EXTERNAL_DEVICE_CLAIM_DESCRIPTION = "Device list";
|
||||
|
||||
public final class ErrorMessages {
|
||||
private ErrorMessages () { throw new AssertionError(); }
|
||||
|
||||
@ -67,6 +67,7 @@ import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub;
|
||||
import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub;
|
||||
import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceStub;
|
||||
import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub;
|
||||
import org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
|
||||
@ -863,4 +864,18 @@ public class DeviceMgtAPIUtils {
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to set property name and value to ClaimPropertyDTO
|
||||
*
|
||||
* @param propertyName Name of the property
|
||||
* @param propertyValue Value of the property
|
||||
* @return {@link ClaimPropertyDTO}
|
||||
*/
|
||||
public static ClaimPropertyDTO buildClaimPropertyDTO(String propertyName, String propertyValue) {
|
||||
ClaimPropertyDTO claimPropertyDTO = new ClaimPropertyDTO();
|
||||
claimPropertyDTO.setPropertyName(propertyName);
|
||||
claimPropertyDTO.setPropertyValue(propertyValue);
|
||||
return claimPropertyDTO;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeviceDetailsWrapper {
|
||||
|
||||
@ -30,6 +31,7 @@ public class DeviceDetailsWrapper {
|
||||
Device device;
|
||||
List<Application> applications;
|
||||
DeviceLocation location;
|
||||
String events;
|
||||
int tenantId;
|
||||
|
||||
List<DeviceGroup> groups;
|
||||
@ -91,6 +93,14 @@ public class DeviceDetailsWrapper {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
public void setEvents(String events) {
|
||||
this.events = events;
|
||||
}
|
||||
|
||||
public String getJSONString() {
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(this).toString();
|
||||
|
||||
@ -18,20 +18,24 @@
|
||||
package org.wso2.carbon.device.mgt.common.policy.mgt.ui;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "ConditionList")
|
||||
public class ConditionList {
|
||||
@XmlRootElement(name = "Condition")
|
||||
public class Condition {
|
||||
|
||||
List<Key> conditions;
|
||||
String key;
|
||||
List<String> values;
|
||||
|
||||
@XmlElement(name = "Key")
|
||||
public List<Key> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
public String getKey() { return key; }
|
||||
|
||||
public void setConditions(List<Key> conditions) {
|
||||
this.conditions = conditions;
|
||||
}
|
||||
public void setKey(String key) { this.key = key; }
|
||||
|
||||
@XmlElementWrapper(name = "Values")
|
||||
@XmlElement(name = "Value")
|
||||
public List<String> getValues() { return values; }
|
||||
|
||||
public void setValues(List<String> values) { this.values = values; }
|
||||
}
|
||||
@ -29,7 +29,6 @@ public class Content {
|
||||
private String key;
|
||||
private List<Item> items;
|
||||
private List<SubContent> subContents;
|
||||
private ConditionList conditionList;
|
||||
|
||||
@XmlAttribute(name = "key", required = true)
|
||||
public String getKey() {
|
||||
@ -56,12 +55,4 @@ public class Content {
|
||||
|
||||
public void setSubContents(List<SubContent> subContents) { this.subContents = subContents; }
|
||||
|
||||
@XmlElement(name = "ConditionList")
|
||||
public ConditionList getConditionList() {
|
||||
return conditionList;
|
||||
}
|
||||
|
||||
public void setConditionList(ConditionList conditionList) {
|
||||
this.conditionList = conditionList;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,15 +18,16 @@
|
||||
package org.wso2.carbon.device.mgt.common.policy.mgt.ui;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "Input")
|
||||
public class Input {
|
||||
|
||||
private String type;
|
||||
private String placeholderValue;
|
||||
private String regEx;
|
||||
private String validationMessage;
|
||||
private List<Rule> rules;
|
||||
|
||||
@XmlElement(name = "Type")
|
||||
public String getType() {
|
||||
@ -46,21 +47,9 @@ public class Input {
|
||||
this.placeholderValue = placeholderValue;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Regex")
|
||||
public String getRegEx() {
|
||||
return regEx;
|
||||
}
|
||||
@XmlElementWrapper(name = "Rules")
|
||||
@XmlElement(name = "Rule")
|
||||
public List<Rule> getRules() { return rules; }
|
||||
|
||||
public void setRegEx(String regEx) {
|
||||
this.regEx = regEx;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ValidationMsg")
|
||||
public String getValidationMessage() {
|
||||
return validationMessage;
|
||||
}
|
||||
|
||||
public void setValidationMessage(String validationMessage) {
|
||||
this.validationMessage = validationMessage;
|
||||
}
|
||||
public void setRules(List<Rule> rules) { this.rules = rules; }
|
||||
}
|
||||
|
||||
@ -18,7 +18,9 @@
|
||||
package org.wso2.carbon.device.mgt.common.policy.mgt.ui;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "Item")
|
||||
public class Item {
|
||||
@ -29,14 +31,14 @@ public class Item {
|
||||
private String value;
|
||||
private boolean isRequired;
|
||||
private String subTitle;
|
||||
private ConditionList conditionList;
|
||||
private List<Condition> conditions;
|
||||
private Checkbox checkbox;
|
||||
private Select select;
|
||||
private Input input;
|
||||
private TimeSelector timeSelector;
|
||||
private Table table;
|
||||
private RadioGroup radioGroup;
|
||||
private NotificationList notificationList;
|
||||
private List<Notification> notifications;
|
||||
|
||||
@XmlElement(name = "Label")
|
||||
public String getLabel() {
|
||||
@ -88,10 +90,11 @@ public class Item {
|
||||
|
||||
public void setSubTitle(String subTitle) { this.subTitle = subTitle; }
|
||||
|
||||
@XmlElement(name = "ConditionList")
|
||||
public ConditionList getConditionList() { return conditionList; }
|
||||
@XmlElementWrapper(name = "Conditions")
|
||||
@XmlElement(name = "Condition")
|
||||
public List<Condition> getConditions() { return conditions; }
|
||||
|
||||
public void setConditionList(ConditionList conditionList) { this.conditionList = conditionList; }
|
||||
public void setConditions(List<Condition> conditions) { this.conditions = conditions; }
|
||||
|
||||
@XmlElement(name = "Checkbox")
|
||||
public Checkbox getCheckbox() {
|
||||
@ -139,8 +142,9 @@ public class Item {
|
||||
this.radioGroup = radioGroup;
|
||||
}
|
||||
|
||||
@XmlElement(name = "NotificationList")
|
||||
public NotificationList getNotificationList() { return notificationList; }
|
||||
@XmlElementWrapper(name = "Notifications")
|
||||
@XmlElement(name = "Notification")
|
||||
public List<Notification> getNotifications() { return notifications; }
|
||||
|
||||
public void setNotificationList(NotificationList notificationList) { this.notificationList = notificationList; }
|
||||
public void setNotifications(List<Notification> notifications) { this.notifications = notifications; }
|
||||
}
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
/* Copyright (c) 2020, 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 org.wso2.carbon.device.mgt.common.policy.mgt.ui;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "Key")
|
||||
public class Key {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
@XmlAttribute(name = "name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlAttribute(name = "value")
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package org.wso2.carbon.device.mgt.common.policy.mgt.ui;/* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
public class Rule {
|
||||
|
||||
private String type;
|
||||
private String logic;
|
||||
private String validationMessage;
|
||||
|
||||
@XmlElement(name = "Type")
|
||||
public String getType() { return type; }
|
||||
|
||||
public void setType(String type) { this.type = type; }
|
||||
|
||||
@XmlElement(name = "Logic")
|
||||
public String getLogic() { return logic; }
|
||||
|
||||
public void setLogic(String logic) { this.logic = logic; }
|
||||
|
||||
@XmlElement(name = "ValidationMsg")
|
||||
public String getValidationMessage() { return validationMessage; }
|
||||
|
||||
public void setValidationMessage(String validationMessage) { this.validationMessage = validationMessage; }
|
||||
}
|
||||
@ -28,7 +28,7 @@ public class SubContent {
|
||||
|
||||
private String key;
|
||||
private List<Item> items;
|
||||
private ConditionList conditionList;
|
||||
private List<Condition> conditions;
|
||||
private List<SubContent> subContents;
|
||||
|
||||
@XmlAttribute(name = "key", required = true)
|
||||
@ -50,13 +50,14 @@ public class SubContent {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ConditionList")
|
||||
public ConditionList getConditionList() {
|
||||
return conditionList;
|
||||
@XmlElementWrapper(name = "Conditions")
|
||||
@XmlElement(name = "Condition")
|
||||
public List<Condition> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
public void setConditionList(ConditionList conditionList) {
|
||||
this.conditionList = conditionList;
|
||||
public void setConditions(List<Condition> conditions) {
|
||||
this.conditions = conditions;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "SubContents")
|
||||
|
||||
@ -43,6 +43,7 @@ public final class DeviceManagementConstants {
|
||||
public static final String DM_CACHE_MANAGER = "DM_CACHE_MANAGER";
|
||||
public static final String DEVICE_CACHE = "DEVICE_CACHE";
|
||||
public static final String ENROLLMENT_NOTIFICATION_API_ENDPOINT = "/api/device-mgt/enrollment-notification";
|
||||
public static final String URL_SEPERATOR = "/";
|
||||
|
||||
public static final class ConfigurationManagement {
|
||||
private ConfigurationManagement(){
|
||||
@ -164,8 +165,8 @@ public final class DeviceManagementConstants {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static final String REPORTING_EVENT_HOST = "iot.reporting.event.host";
|
||||
public static final String REPORTING_CONTEXT = "/event";
|
||||
public static final String DEVICE_INFO_ENDPOINT = REPORTING_CONTEXT + "/device-info";
|
||||
public static final String REPORTING_CONTEXT = "/reporting/api/analyticsadmin/v1.0/event";
|
||||
public static final String DEVICE_INFO_PARAM = "device-info";
|
||||
public static final String APP_USAGE_ENDPOINT = REPORTING_CONTEXT + "/app-usage";
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,6 +96,18 @@ public interface DeviceInformationManager {
|
||||
*/
|
||||
List<DeviceLocation> getDeviceLocations(List<DeviceIdentifier> deviceIdentifiers) throws DeviceDetailsMgtException;
|
||||
|
||||
/**
|
||||
* Send events to reporting backend
|
||||
* @param deviceId device identifier of the reporting device
|
||||
* @param deviceType device type of an device
|
||||
* @param payload payload of the event
|
||||
* @param eventType Event type being sent
|
||||
* @return Http status code if a call is made and if failed to make a call 0
|
||||
* @throws DeviceDetailsMgtException
|
||||
*/
|
||||
int publishEvents(String deviceId, String deviceType, String payload, String eventType)
|
||||
throws DeviceDetailsMgtException;
|
||||
|
||||
// /**
|
||||
// * This method will manage the storing of device application list.
|
||||
// * @param deviceApplication - Device application list.
|
||||
|
||||
@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublish
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceData;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceDetailsWrapper;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.EventPublishingException;
|
||||
@ -91,7 +92,10 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
||||
public void addDeviceInfo(Device device, DeviceInfo deviceInfo) throws DeviceDetailsMgtException {
|
||||
try {
|
||||
|
||||
publishEvents(device, deviceInfo);
|
||||
DeviceDetailsWrapper deviceDetailsWrapper = new DeviceDetailsWrapper();
|
||||
deviceDetailsWrapper.setDeviceInfo(deviceInfo);
|
||||
publishEvents(device, deviceDetailsWrapper, DeviceManagementConstants.Report.DEVICE_INFO_PARAM);
|
||||
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
DeviceInfo newDeviceInfo;
|
||||
DeviceInfo previousDeviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId(),
|
||||
@ -180,14 +184,37 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void publishEvents(Device device, DeviceInfo deviceInfo) {
|
||||
public int publishEvents(String deviceId, String deviceType, String payload, String eventType)
|
||||
throws DeviceDetailsMgtException {
|
||||
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType);
|
||||
|
||||
try {
|
||||
Device device = DeviceManagementDataHolder.getInstance().
|
||||
getDeviceManagementProvider().getDevice(deviceIdentifier, false);
|
||||
DeviceDetailsWrapper deviceDetailsWrapper = new DeviceDetailsWrapper();
|
||||
deviceDetailsWrapper.setEvents(payload);
|
||||
return publishEvents(device, deviceDetailsWrapper, eventType);
|
||||
} catch (DeviceManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Event publishing error. Could not get device " + deviceId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceDetailsMgtException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send device details from core to reporting backend
|
||||
* @param device Device that is sending event
|
||||
* @param deviceDetailsWrapper Payload to send(example, deviceinfo, applist, raw events)
|
||||
*/
|
||||
private int publishEvents(Device device, DeviceDetailsWrapper deviceDetailsWrapper, String
|
||||
eventType) {
|
||||
String reportingHost = HttpReportingUtil.getReportingHost();
|
||||
if (!StringUtils.isBlank(reportingHost)
|
||||
&& HttpReportingUtil.isPublishingEnabledForTenant()) {
|
||||
try {
|
||||
DeviceDetailsWrapper deviceDetailsWrapper = new DeviceDetailsWrapper();
|
||||
deviceDetailsWrapper.setDevice(device);
|
||||
deviceDetailsWrapper.setDeviceInfo(deviceInfo);
|
||||
deviceDetailsWrapper.setTenantId(DeviceManagerUtil.getTenantId());
|
||||
GroupManagementProviderService groupManagementService = DeviceManagementDataHolder
|
||||
.getInstance().getGroupManagementProviderService();
|
||||
@ -197,14 +224,16 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
||||
deviceDetailsWrapper.setGroups(groups);
|
||||
}
|
||||
|
||||
String[] rolesOfUser = getRolesOfUser(CarbonContext.getThreadLocalCarbonContext()
|
||||
String[] rolesOfUser = DeviceManagerUtil.getRolesOfUser(CarbonContext
|
||||
.getThreadLocalCarbonContext()
|
||||
.getUsername());
|
||||
if (rolesOfUser != null && rolesOfUser.length > 0) {
|
||||
deviceDetailsWrapper.setRole(rolesOfUser);
|
||||
}
|
||||
|
||||
HttpReportingUtil.invokeApi(deviceDetailsWrapper.getJSONString(),
|
||||
reportingHost + DeviceManagementConstants.Report.DEVICE_INFO_ENDPOINT);
|
||||
String eventUrl = reportingHost + DeviceManagementConstants.Report
|
||||
.REPORTING_CONTEXT + DeviceManagementConstants.URL_SEPERATOR + eventType;
|
||||
return HttpReportingUtil.invokeApi(deviceDetailsWrapper.getJSONString(), eventUrl);
|
||||
} catch (EventPublishingException e) {
|
||||
log.error("Error occurred while sending events", e);
|
||||
} catch (GroupManagementException e) {
|
||||
@ -218,6 +247,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
||||
+ DeviceManagerUtil.getTenantId());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -524,19 +554,5 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getRolesOfUser(String userName) throws UserStoreException {
|
||||
UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
|
||||
String[] roleList;
|
||||
if (userRealm != null) {
|
||||
userRealm.getUserStoreManager().getRoleNames();
|
||||
roleList = userRealm.getUserStoreManager().getRoleListOfUser(userName);
|
||||
} else {
|
||||
String msg = "User realm is not initiated. Logged in user: " + userName;
|
||||
log.error(msg);
|
||||
throw new UserStoreException(msg);
|
||||
}
|
||||
return roleList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ import org.apache.http.protocol.HTTP;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.caching.impl.CacheImpl;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
||||
import org.wso2.carbon.device.mgt.common.AppRegistrationCredentials;
|
||||
@ -76,6 +77,7 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
|
||||
import org.wso2.carbon.user.api.TenantManager;
|
||||
import org.wso2.carbon.user.api.UserRealm;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
@ -1005,4 +1007,18 @@ public final class DeviceManagerUtil {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String[] getRolesOfUser(String userName) throws UserStoreException {
|
||||
UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
|
||||
String[] roleList;
|
||||
if (userRealm != null) {
|
||||
userRealm.getUserStoreManager().getRoleNames();
|
||||
roleList = userRealm.getUserStoreManager().getRoleListOfUser(userName);
|
||||
} else {
|
||||
String msg = "User realm is not initiated. Logged in user: " + userName;
|
||||
log.error(msg);
|
||||
throw new UserStoreException(msg);
|
||||
}
|
||||
return roleList;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user