Removed the use of web-app context in permission.xml of webapps

4.x.x
harshanl 9 years ago
parent 9fca18ae90
commit 9a68aa92bc

@ -31,6 +31,16 @@ import java.util.List;
public class PermissionConfiguration { public class PermissionConfiguration {
private List<Permission> permissions; private List<Permission> permissions;
private String apiVersion;
public String getApiVersion() {
return apiVersion;
}
@XmlElement (name = "APIVersion", required = true)
public void setApiVersion(String apiVersion) {
this.apiVersion = apiVersion;
}
public List<Permission> getPermissions() { public List<Permission> getPermissions() {
return permissions; return permissions;

@ -24,9 +24,11 @@ import org.apache.catalina.LifecycleListener;
import org.apache.catalina.core.StandardContext; import org.apache.catalina.core.StandardContext;
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.device.mgt.common.permission.mgt.Permission;
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException; import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException;
import org.wso2.carbon.device.mgt.core.config.permission.PermissionConfiguration; import org.wso2.carbon.device.mgt.core.config.permission.PermissionConfiguration;
import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceImpl; import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceImpl;
import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
@ -34,6 +36,7 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.util.List;
/** /**
* This listener class will initiate the permission addition of permissions defined in * This listener class will initiate the permission addition of permissions defined in
@ -50,6 +53,7 @@ public class WebAppDeploymentLifecycleListener implements LifecycleListener {
if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType())) { if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType())) {
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle(); StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
ServletContext servletContext = context.getServletContext(); ServletContext servletContext = context.getServletContext();
String contextPath = servletContext.getContextPath();
try { try {
InputStream permissionStream = servletContext.getResourceAsStream(PERMISSION_CONFIG_PATH); InputStream permissionStream = servletContext.getResourceAsStream(PERMISSION_CONFIG_PATH);
if (permissionStream != null) { if (permissionStream != null) {
@ -58,10 +62,16 @@ public class WebAppDeploymentLifecycleListener implements LifecycleListener {
Unmarshaller unmarshaller = cdmContext.createUnmarshaller(); Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
PermissionConfiguration permissionConfiguration = (PermissionConfiguration) PermissionConfiguration permissionConfiguration = (PermissionConfiguration)
unmarshaller.unmarshal(permissionStream); unmarshaller.unmarshal(permissionStream);
if (permissionConfiguration != null && List<Permission> permissions = permissionConfiguration.getPermissions();
permissionConfiguration.getPermissions() != null) { String apiVersion = permissionConfiguration.getApiVersion();
PermissionManagerServiceImpl.getInstance().addPermissions( if (permissionConfiguration != null && permissions != null) {
permissionConfiguration.getPermissions()); for (Permission permission : permissions) {
// update the permission path to absolute permission path
permission.setPath(PermissionUtils.getAbsolutePermissionPath(permission.getPath()));
permission.setUrl(PermissionUtils.getAbsoluteContextPathOfAPI(contextPath, apiVersion,
permission.getUrl()));
PermissionManagerServiceImpl.getInstance().addPermission(permission);
}
} }
} }
} catch (JAXBException e) { } catch (JAXBException e) {

@ -51,17 +51,8 @@ public class PermissionManagerServiceImpl implements PermissionManagerService {
return registryBasedPermissionManager; return registryBasedPermissionManager;
} }
public boolean addPermissions(List<Permission> permissions) throws PermissionManagementException {
for (Permission permission : permissions) {
this.addPermission(permission);
}
return true;
}
@Override @Override
public boolean addPermission(Permission permission) throws PermissionManagementException { public boolean addPermission(Permission permission) throws PermissionManagementException {
// update the permission path to absolute permission path
permission.setPath(PermissionUtils.getAbsolutePermissionPath(permission.getPath()));
// adding a permission to the tree // adding a permission to the tree
permissionTree.addPermission(permission); permissionTree.addPermission(permission);
return PermissionUtils.putPermission(permission); return PermissionUtils.putPermission(permission);

@ -59,6 +59,13 @@ public class PermissionUtils {
return PermissionUtils.ADMIN_PERMISSION_REGISTRY_PATH + permissionPath; return PermissionUtils.ADMIN_PERMISSION_REGISTRY_PATH + permissionPath;
} }
public static String getAbsoluteContextPathOfAPI(String contextPath, String version, String url) {
if((version != null) && !version.isEmpty()) {
return contextPath + "/" + version + url;
}
return contextPath + url;
}
public static Permission getPermission(String path) throws PermissionManagementException { public static Permission getPermission(String path) throws PermissionManagementException {
try { try {
Resource resource = PermissionUtils.getGovernanceRegistry().get(path); Resource resource = PermissionUtils.getGovernanceRegistry().get(path);

@ -120,10 +120,9 @@ public class DynamicClientWebAppRegistrationManager {
String requiredDynamicClientRegistration, webAppName; String requiredDynamicClientRegistration, webAppName;
ServletContext servletContext; ServletContext servletContext;
RegistrationProfile registrationProfile; RegistrationProfile registrationProfile;
OAuthAppDetails oAuthAppDetails = null; OAuthAppDetails oAuthAppDetails;
DynamicClientWebAppRegistrationManager dynamicClientWebAppRegistrationManager = DynamicClientWebAppRegistrationManager dynamicClientWebAppRegistrationManager =
DynamicClientWebAppRegistrationManager.getInstance(); DynamicClientWebAppRegistrationManager.getInstance();
//todo move enumeration to while loop
Enumeration enumeration = new IteratorEnumeration(DynamicClientWebAppRegistrationManager. Enumeration enumeration = new IteratorEnumeration(DynamicClientWebAppRegistrationManager.
webAppContexts.keySet().iterator()); webAppContexts.keySet().iterator());
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -51,6 +51,7 @@ public class PermissionBasedScopeValidator extends OAuth2ScopeValidator {
public static final String WRITE = "write"; public static final String WRITE = "write";
public static final String DELETE = "delete"; public static final String DELETE = "delete";
public static final String ACTION = "action"; public static final String ACTION = "action";
public static final String UI_EXECUTE = "ui.execute";
} }
private static final Log log = LogFactory.getLog(PermissionBasedScopeValidator.class); private static final Log log = LogFactory.getLog(PermissionBasedScopeValidator.class);
@ -77,7 +78,7 @@ public class PermissionBasedScopeValidator extends OAuth2ScopeValidator {
if (userRealm != null && userRealm.getAuthorizationManager() != null) { if (userRealm != null && userRealm.getAuthorizationManager() != null) {
status = userRealm.getAuthorizationManager() status = userRealm.getAuthorizationManager()
.isUserAuthorized(username, permission.getPath(), .isUserAuthorized(username, permission.getPath(),
PermissionMethod.READ); PermissionMethod.UI_EXECUTE);
} }
} }
} catch (PermissionManagementException e) { } catch (PermissionManagementException e) {

@ -81,8 +81,8 @@ public class OAuthAuthenticator implements WebappAuthenticator {
authenticationInfo.setStatus(Status.CONTINUE); authenticationInfo.setStatus(Status.CONTINUE);
} }
String apiVersion = tokenizer.nextToken(); String apiVersion = tokenizer.nextToken();
String authLevel = authenticator.getResourceAuthenticationScheme(context, apiVersion, requestUri, requestMethod); //String authLevel = authenticator.getResourceAuthenticationScheme(context, apiVersion, requestUri, requestMethod);
//String authLevel = "any"; String authLevel = "any";
try { try {
if (Constants.NO_MATCHING_AUTH_SCHEME.equals(authLevel)) { if (Constants.NO_MATCHING_AUTH_SCHEME.equals(authLevel)) {
AuthenticationFrameworkUtil.handleNoMatchAuthScheme(request, response, requestMethod, apiVersion, AuthenticationFrameworkUtil.handleNoMatchAuthScheme(request, response, requestMethod, apiVersion,

Loading…
Cancel
Save