|
|
@ -17,10 +17,11 @@ package org.wso2.carbon.device.mgt.iot.androidsense.service.impl.listener;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
|
|
import org.wso2.carbon.CarbonConstants;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.AndroidSenseServiceImpl;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.constants.AndroidSenseConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.constants.AndroidSenseConstants;
|
|
|
|
import org.wso2.carbon.user.api.AuthorizationManager;
|
|
|
|
import org.wso2.carbon.user.api.AuthorizationManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.user.api.Permission;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
import org.wso2.carbon.user.core.service.RealmService;
|
|
|
|
import org.wso2.carbon.user.core.service.RealmService;
|
|
|
@ -28,11 +29,9 @@ import org.wso2.carbon.user.core.service.RealmService;
|
|
|
|
import javax.servlet.ServletContextEvent;
|
|
|
|
import javax.servlet.ServletContextEvent;
|
|
|
|
import javax.servlet.ServletContextListener;
|
|
|
|
import javax.servlet.ServletContextListener;
|
|
|
|
|
|
|
|
|
|
|
|
public class PermissionUpdateListener implements ServletContextListener {
|
|
|
|
public class AndroidSensePermissionUpdateListener implements ServletContextListener {
|
|
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(AndroidSenseServiceImpl.class);
|
|
|
|
private static Log log = LogFactory.getLog(AndroidSensePermissionUpdateListener.class);
|
|
|
|
|
|
|
|
|
|
|
|
private static final String ROLE_NAME = "internal/devicemgt-user";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
|
|
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
|
|
@ -40,16 +39,16 @@ public class PermissionUpdateListener implements ServletContextListener {
|
|
|
|
UserStoreManager userStoreManager = getUserStoreManager();
|
|
|
|
UserStoreManager userStoreManager = getUserStoreManager();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (userStoreManager != null) {
|
|
|
|
if (userStoreManager != null) {
|
|
|
|
if (!userStoreManager.isExistingRole(ROLE_NAME)) {
|
|
|
|
if (!userStoreManager.isExistingRole(AndroidSenseConstants.ROLE_NAME)) {
|
|
|
|
userStoreManager.addRole(ROLE_NAME, null, AndroidSenseConstants.permissions);
|
|
|
|
userStoreManager.addRole(AndroidSenseConstants.ROLE_NAME, null, getPermissions());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
getAuthorizationManager().authorizeRole(ROLE_NAME,
|
|
|
|
getAuthorizationManager().authorizeRole(AndroidSenseConstants.ROLE_NAME,
|
|
|
|
"/permission/admin/device-mgt/devices/enroll/android-sense", "ui.execute");
|
|
|
|
AndroidSenseConstants.PERM_ENROLL_ANDROID_SENSE, CarbonConstants.UI_PERMISSION_ACTION);
|
|
|
|
getAuthorizationManager().authorizeRole(ROLE_NAME,
|
|
|
|
getAuthorizationManager().authorizeRole(AndroidSenseConstants.ROLE_NAME,
|
|
|
|
"/permission/admin/device-mgt/devices/owning-device/view", "ui.execute");
|
|
|
|
AndroidSenseConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} } catch (UserStoreException e) {
|
|
|
|
} } catch (UserStoreException e) {
|
|
|
|
//
|
|
|
|
log.error("Error while creating a role and adding a user for Android Sense.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -101,25 +100,14 @@ public class PermissionUpdateListener implements ServletContextListener {
|
|
|
|
return authorizationManager;
|
|
|
|
return authorizationManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Permission[] getPermissions() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Permission androidSense = new Permission(AndroidSenseConstants.PERM_ENROLL_ANDROID_SENSE,
|
|
|
|
|
|
|
|
CarbonConstants.UI_PERMISSION_ACTION);
|
|
|
|
|
|
|
|
Permission view = new Permission(AndroidSenseConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants
|
|
|
|
|
|
|
|
.UI_PERMISSION_ACTION);
|
|
|
|
|
|
|
|
|
|
|
|
// public static void registerApiAccessRoles(String user) {
|
|
|
|
return new Permission[]{androidSense, view};
|
|
|
|
// UserStoreManager userStoreManager = null;
|
|
|
|
}
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// userStoreManager = getUserStoreManager();
|
|
|
|
|
|
|
|
// String[] userList = new String[]{user};
|
|
|
|
|
|
|
|
// if (userStoreManager != null) {
|
|
|
|
|
|
|
|
// String rolesOfUser[] = userStoreManager.getRoleListOfUser(user);
|
|
|
|
|
|
|
|
// if (!userStoreManager.isExistingRole(Constants.DEFAULT_ROLE_NAME)) {
|
|
|
|
|
|
|
|
// userStoreManager.addRole(Constants.DEFAULT_ROLE_NAME, userList, Constants.DEFAULT_PERMISSION);
|
|
|
|
|
|
|
|
// } else if (rolesOfUser != null && Arrays.asList(rolesOfUser).contains(Constants.DEFAULT_ROLE_NAME)) {
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// userStoreManager.updateUserListOfRole(Constants.DEFAULT_ROLE_NAME, new String[0], userList);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } catch (UserStoreException e) {
|
|
|
|
|
|
|
|
// log.error("Error while creating a role and adding a user for virtual_firealarm.", e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|