|
|
|
@ -19,6 +19,16 @@
|
|
|
|
|
package io.entgra.device.mgt.core.application.mgt.core.impl;
|
|
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.*;
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.core.dao.SPApplicationDAO;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstaller;
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes;
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.LifecycleChanger;
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.Pagination;
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.config.RatingConfiguration;
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.dto.*;
|
|
|
|
|
import io.entgra.device.mgt.core.application.mgt.common.exception.*;
|
|
|
|
@ -57,6 +67,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
|
import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
@ -1669,6 +1680,31 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check whether valid metaData value or not
|
|
|
|
|
*
|
|
|
|
|
* @return true or false
|
|
|
|
|
* @throws MetadataManagementException If it is unable to load metaData
|
|
|
|
|
*/
|
|
|
|
|
private boolean isUserAbleToViewAllRoles() throws MetadataManagementException {
|
|
|
|
|
List<Metadata> allMetadata;
|
|
|
|
|
allMetadata = APIUtil.getMetadataManagementService().retrieveAllMetadata();
|
|
|
|
|
if (allMetadata != null && !allMetadata.isEmpty()) {
|
|
|
|
|
for(Metadata metadata : allMetadata){
|
|
|
|
|
if(Constants.SHOW_ALL_ROLES.equals(metadata.getMetaKey())){
|
|
|
|
|
String metaValue = metadata.getMetaValue();
|
|
|
|
|
if (metaValue != null) {
|
|
|
|
|
JSONObject jsonObject;
|
|
|
|
|
jsonObject = new JSONObject(metaValue);
|
|
|
|
|
boolean isUserAbleToViewAllRoles = jsonObject.getBoolean(Constants.IS_USER_ABLE_TO_VIEW_ALL_ROLES);
|
|
|
|
|
return isUserAbleToViewAllRoles;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get assigned role list of the given user.
|
|
|
|
|
*
|
|
|
|
@ -3442,7 +3478,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <T> void validateAppCreatingRequest(T param) throws ApplicationManagementException, RequestValidatingException {
|
|
|
|
|
public <T> void validateAppCreatingRequest(T param)
|
|
|
|
|
throws ApplicationManagementException, RequestValidatingException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
int deviceTypeId = -1;
|
|
|
|
@ -3614,6 +3651,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
}
|
|
|
|
|
if (!isUserAbleToViewAllRoles()) {
|
|
|
|
|
if (!hasUserRole(unrestrictedRoles, userName)) {
|
|
|
|
|
String msg = "You are trying to restrict the visibility of the application for a role set, but "
|
|
|
|
|
+ "in order to perform the action at least one role should be assigned to user: "
|
|
|
|
|
+ userName;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Filter filter = new Filter();
|
|
|
|
@ -3665,6 +3711,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
String msg = "Error occurred when validating the unrestricted roles given for the web clip";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
} catch (MetadataManagementException e) {
|
|
|
|
|
String msg = "Error occurred while retrieving metadata list";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|