|
|
@ -1,5 +1,7 @@
|
|
|
|
package org.wso2.carbon.device.application.mgt.core.lifecycle;
|
|
|
|
package org.wso2.carbon.device.application.mgt.core.lifecycle;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
|
|
|
@ -23,6 +25,7 @@ import java.util.Set;
|
|
|
|
public class LifecycleStateManger {
|
|
|
|
public class LifecycleStateManger {
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, State> lifecycleStates;
|
|
|
|
private Map<String, State> lifecycleStates;
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(LifecycleStateManger.class);
|
|
|
|
|
|
|
|
|
|
|
|
public void init(List<LifecycleState> states) throws LifecycleManagementException {
|
|
|
|
public void init(List<LifecycleState> states) throws LifecycleManagementException {
|
|
|
|
lifecycleStates = new HashMap<>();
|
|
|
|
lifecycleStates = new HashMap<>();
|
|
|
@ -33,11 +36,11 @@ public class LifecycleStateManger {
|
|
|
|
lifecycleStates.put(s.getName().toUpperCase(), new State(s.getName().toUpperCase(),
|
|
|
|
lifecycleStates.put(s.getName().toUpperCase(), new State(s.getName().toUpperCase(),
|
|
|
|
s.getProceedingStates(), s.getPermission(),s.isAppUpdatable(),s.isAppInstallable(),
|
|
|
|
s.getProceedingStates(), s.getPermission(),s.isAppUpdatable(),s.isAppInstallable(),
|
|
|
|
s.isInitialState(),s.isEndState()));
|
|
|
|
s.isInitialState(),s.isEndState()));
|
|
|
|
Permission permissionOfState = new Permission();
|
|
|
|
|
|
|
|
permissionOfState.setPath(s.getPermission());
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PermissionUtils.putPermission(permissionOfState);
|
|
|
|
PermissionUtils.putPermission(s.getPermission());
|
|
|
|
} catch (PermissionManagementException e) {
|
|
|
|
} catch (PermissionManagementException e) {
|
|
|
|
|
|
|
|
log.error("Error when adding permission " + s.getPermission() + " related to the state: "
|
|
|
|
|
|
|
|
+ s.getName(), e);
|
|
|
|
throw new LifecycleManagementException (
|
|
|
|
throw new LifecycleManagementException (
|
|
|
|
"Error when adding permission " + s.getPermission() + " related to the state: "
|
|
|
|
"Error when adding permission " + s.getPermission() + " related to the state: "
|
|
|
|
+ s.getName(), e);
|
|
|
|
+ s.getName(), e);
|
|
|
@ -54,26 +57,31 @@ public class LifecycleStateManger {
|
|
|
|
|
|
|
|
|
|
|
|
UserRealm userRealm = null;
|
|
|
|
UserRealm userRealm = null;
|
|
|
|
String permission = getPermissionForStateChange(nextState);
|
|
|
|
String permission = getPermissionForStateChange(nextState);
|
|
|
|
try {
|
|
|
|
if(permission != null) {
|
|
|
|
userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
|
|
|
try {
|
|
|
|
if(userRealm != null && userRealm.getAuthorizationManager() != null &&
|
|
|
|
userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
|
|
|
userRealm.getAuthorizationManager().isUserAuthorized(username,
|
|
|
|
if (userRealm != null && userRealm.getAuthorizationManager() != null &&
|
|
|
|
PermissionUtils.getAbsolutePermissionPath(permission),
|
|
|
|
userRealm.getAuthorizationManager().isUserAuthorized(username,
|
|
|
|
Constants.UI_EXECUTE)){
|
|
|
|
PermissionUtils.getAbsolutePermissionPath(permission),
|
|
|
|
if (currentState.equalsIgnoreCase(nextState)) {
|
|
|
|
Constants.UI_EXECUTE)) {
|
|
|
|
return true;
|
|
|
|
if (currentState.equalsIgnoreCase(nextState)) {
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
State state = getMatchingState(currentState);
|
|
|
|
}
|
|
|
|
if (state != null) {
|
|
|
|
State state = getMatchingState(currentState);
|
|
|
|
return getMatchingNextState(state.getProceedingStates(), nextState);
|
|
|
|
if (state != null) {
|
|
|
|
|
|
|
|
return getMatchingNextState(state.getProceedingStates(), nextState);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
throw new LifecycleManagementException(
|
|
|
|
|
|
|
|
"UserStoreException exception from changing the state from : " + currentState + " to: "
|
|
|
|
|
|
|
|
+ nextState + " with username : " + username + " and tenant Id : " + tenantId, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}else{
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
throw new LifecycleManagementException(
|
|
|
|
throw new LifecycleManagementException (
|
|
|
|
"Required permissions cannot be found for the state : "+nextState);
|
|
|
|
"UserStoreException exception from changing the state from : " + currentState + " to: "
|
|
|
|
|
|
|
|
+ nextState+" with username : "+ username+" and tenant Id : "+tenantId, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|