mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Add new method to put permission taking String parameters
This commit is contained in:
parent
6ba46facb1
commit
3bb2e8a5bf
@ -106,7 +106,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
application.setUser(new User(userName, tenantId));
|
application.setUser(new User(userName, tenantId));
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Create Application received for the tenant : " + tenantId + " From" + " the user : " + userName);
|
log.debug("Create Application received for the tenant : " + tenantId + " From" + " the user : " +
|
||||||
|
userName);
|
||||||
}
|
}
|
||||||
validateAppCreatingRequest(application, tenantId);
|
validateAppCreatingRequest(application, tenantId);
|
||||||
//todo throw different exception
|
//todo throw different exception
|
||||||
@ -576,7 +577,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
LifecycleState newAppLifecycleState = getLifecycleStateInstant(AppLifecycleState.REMOVED.toString(),
|
LifecycleState newAppLifecycleState = getLifecycleStateInstant(AppLifecycleState.REMOVED.toString(),
|
||||||
appLifecycleState.getCurrentState());
|
appLifecycleState.getCurrentState());
|
||||||
if (lifecycleStateManger.isValidStateChange(newAppLifecycleState.getPreviousState(),
|
if (lifecycleStateManger.isValidStateChange(newAppLifecycleState.getPreviousState(),
|
||||||
newAppLifecycleState.getCurrentState())) {
|
newAppLifecycleState.getCurrentState(),userName,tenantId)) {
|
||||||
this.lifecycleStateDAO
|
this.lifecycleStateDAO
|
||||||
.addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(),
|
.addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(),
|
||||||
tenantId);
|
tenantId);
|
||||||
@ -621,8 +622,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
(currentState)) {
|
(currentState)) {
|
||||||
LifecycleState newAppLifecycleState = getLifecycleStateInstant(AppLifecycleState.REMOVED.toString(),
|
LifecycleState newAppLifecycleState = getLifecycleStateInstant(AppLifecycleState.REMOVED.toString(),
|
||||||
appLifecycleState.getCurrentState());
|
appLifecycleState.getCurrentState());
|
||||||
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
if (lifecycleStateManger.isValidStateChange(newAppLifecycleState.getPreviousState(),
|
if (lifecycleStateManger.isValidStateChange(newAppLifecycleState.getPreviousState(),
|
||||||
newAppLifecycleState.getCurrentState())) {
|
newAppLifecycleState.getCurrentState(),userName,tenantId)) {
|
||||||
this.lifecycleStateDAO
|
this.lifecycleStateDAO
|
||||||
.addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(),
|
.addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(),
|
||||||
tenantId);
|
tenantId);
|
||||||
@ -979,12 +981,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
+ " and application release UUID: " + releaseUuid);
|
+ " and application release UUID: " + releaseUuid);
|
||||||
}
|
}
|
||||||
state.setPreviousState(currentState.getCurrentState());
|
state.setPreviousState(currentState.getCurrentState());
|
||||||
|
|
||||||
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
state.setUpdatedBy(userName);
|
state.setUpdatedBy(userName);
|
||||||
|
|
||||||
if (state.getCurrentState() != null && state.getPreviousState() != null) {
|
if (state.getCurrentState() != null && state.getPreviousState() != null) {
|
||||||
if (lifecycleStateManger.isValidStateChange(state.getPreviousState(), state.getCurrentState(),userName,tenantId)) {
|
if (lifecycleStateManger.isValidStateChange(state.getPreviousState(), state.getCurrentState(),userName,
|
||||||
|
tenantId)) {
|
||||||
//todo if current state of the adding lifecycle state is PUBLISHED, need to check whether is there
|
//todo if current state of the adding lifecycle state is PUBLISHED, need to check whether is there
|
||||||
//todo any other application release in PUBLISHED state for the application( i.e for the appid)
|
//todo any other application release in PUBLISHED state for the application( i.e for the appid)
|
||||||
this.lifecycleStateDAO.addLifecycleState(state, applicationId, releaseUuid, tenantId);
|
this.lifecycleStateDAO.addLifecycleState(state, applicationId, releaseUuid, tenantId);
|
||||||
|
|||||||
@ -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,6 +57,7 @@ public class LifecycleStateManger {
|
|||||||
|
|
||||||
UserRealm userRealm = null;
|
UserRealm userRealm = null;
|
||||||
String permission = getPermissionForStateChange(nextState);
|
String permission = getPermissionForStateChange(nextState);
|
||||||
|
if(permission != null) {
|
||||||
try {
|
try {
|
||||||
userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
||||||
if (userRealm != null && userRealm.getAuthorizationManager() != null &&
|
if (userRealm != null && userRealm.getAuthorizationManager() != null &&
|
||||||
@ -75,6 +79,10 @@ public class LifecycleStateManger {
|
|||||||
"UserStoreException exception from changing the state from : " + currentState + " to: "
|
"UserStoreException exception from changing the state from : " + currentState + " to: "
|
||||||
+ nextState + " with username : " + username + " and tenant Id : " + tenantId, e);
|
+ nextState + " with username : " + username + " and tenant Id : " + tenantId, e);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
throw new LifecycleManagementException(
|
||||||
|
"Required permissions cannot be found for the state : "+nextState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private State getMatchingState(String currentState) {
|
private State getMatchingState(String currentState) {
|
||||||
|
|||||||
@ -159,7 +159,6 @@ public class APIUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return configManager;
|
return configManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package org.wso2.carbon.device.application.mgt.core;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
|
||||||
import org.wso2.carbon.device.application.mgt.core.config.Configuration;
|
import org.wso2.carbon.device.application.mgt.core.config.Configuration;
|
||||||
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||||
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
|
||||||
@ -22,7 +23,7 @@ public class LifecycleManagementTest {
|
|||||||
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public void init() {
|
public void init() throws LifecycleManagementException {
|
||||||
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
|
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
|
||||||
Configuration configuration = configurationManager.getConfiguration();
|
Configuration configuration = configurationManager.getConfiguration();
|
||||||
lifecycleStates = configuration.getLifecycleStates();
|
lifecycleStates = configuration.getLifecycleStates();
|
||||||
@ -44,16 +45,4 @@ public class LifecycleManagementTest {
|
|||||||
proceedingStates.contains(BOGUS_STATE.toUpperCase()));
|
proceedingStates.contains(BOGUS_STATE.toUpperCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Test
|
|
||||||
public void checkValidStateChange() {
|
|
||||||
Assert.assertTrue("Invalid state transition from: " + CURRENT_STATE + " to: " + NEXT_STATE,
|
|
||||||
lifecycleStateManger.isValidStateChange(CURRENT_STATE, NEXT_STATE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void checkInvalidStateChange() {
|
|
||||||
Assert.assertFalse("Invalid state transition from: " + CURRENT_STATE + " to: " + BOGUS_STATE,
|
|
||||||
lifecycleStateManger.isValidStateChange(CURRENT_STATE, BOGUS_STATE,));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,9 +80,13 @@ public class PermissionUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean putPermission(Permission permission) throws PermissionManagementException {
|
public static boolean putPermission(Permission permission) throws PermissionManagementException {
|
||||||
|
return putPermission(permission.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean putPermission(String permissionPath) throws PermissionManagementException {
|
||||||
boolean status;
|
boolean status;
|
||||||
try {
|
try {
|
||||||
StringTokenizer tokenizer = new StringTokenizer(permission.getPath(), "/");
|
StringTokenizer tokenizer = new StringTokenizer(permissionPath, "/");
|
||||||
String lastToken = "", currentToken, tempPath;
|
String lastToken = "", currentToken, tempPath;
|
||||||
while (tokenizer.hasMoreTokens()) {
|
while (tokenizer.hasMoreTokens()) {
|
||||||
currentToken = tokenizer.nextToken();
|
currentToken = tokenizer.nextToken();
|
||||||
@ -95,7 +99,7 @@ public class PermissionUtils {
|
|||||||
status = true;
|
status = true;
|
||||||
} catch (RegistryException e) {
|
} catch (RegistryException e) {
|
||||||
throw new PermissionManagementException("Error occurred while persisting permission : " +
|
throw new PermissionManagementException("Error occurred while persisting permission : " +
|
||||||
permission.getName(), e);
|
permissionPath, e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user