mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding Indexes upon tables that involve in expensive SQL operations
This commit is contained in:
commit
b28ed6803e
@ -28,18 +28,24 @@ import java.lang.annotation.Target;
|
|||||||
*/
|
*/
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface Permission {
|
public @interface Scope {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the scope key which should be unique.
|
||||||
|
* @return Returns scope key.
|
||||||
|
*/
|
||||||
|
String key();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the scope name.
|
* Represents the scope name.
|
||||||
* @return Returns scope name.
|
* @return Returns scope name.
|
||||||
*/
|
*/
|
||||||
String scope();
|
String name();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the associated permissions.
|
* Represents the scope description.
|
||||||
* @return Returns list of permissions.
|
* @return Returns scope description.
|
||||||
*/
|
*/
|
||||||
String[] permissions();
|
String description();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -161,6 +161,10 @@
|
|||||||
<artifactId>org.wso2.carbon.user.api</artifactId>
|
<artifactId>org.wso2.carbon.user.api</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -18,20 +18,19 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.apimgt.application.extension.api;
|
package org.wso2.carbon.apimgt.application.extension.api;
|
||||||
|
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.apimgt.application.extension.api.util.RegistrationProfile;
|
import org.wso2.carbon.apimgt.application.extension.api.util.RegistrationProfile;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the application registration service that exposed for apimApplicationRegistration
|
* This is the application registration service that exposed for apimApplicationRegistration
|
||||||
*/
|
*/
|
||||||
|
@API(name = "API Registration Service", version = "1.0.0",
|
||||||
|
context = "api-application-registration",
|
||||||
|
tags = {"devicemgt_admin"})
|
||||||
public interface ApiApplicationRegistrationService {
|
public interface ApiApplicationRegistrationService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,6 +39,7 @@ public interface ApiApplicationRegistrationService {
|
|||||||
@POST
|
@POST
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("register/tenants")
|
||||||
Response register(@PathParam("tenantDomain") String tenantDomain,
|
Response register(@PathParam("tenantDomain") String tenantDomain,
|
||||||
@QueryParam("applicationName") String applicationName);
|
@QueryParam("applicationName") String applicationName);
|
||||||
|
|
||||||
@ -51,6 +51,7 @@ public interface ApiApplicationRegistrationService {
|
|||||||
@POST
|
@POST
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("register")
|
||||||
Response register(RegistrationProfile registrationProfile);
|
Response register(RegistrationProfile registrationProfile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,5 +60,6 @@ public interface ApiApplicationRegistrationService {
|
|||||||
* @return the response status of request.
|
* @return the response status of request.
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
|
@Path("unregister")
|
||||||
Response unregister(@QueryParam("applicationName") String applicationName);
|
Response unregister(@QueryParam("applicationName") String applicationName);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,11 @@
|
|||||||
<!--publish to apim-->
|
<!--publish to apim-->
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>managed-api-enabled</param-name>
|
<param-name>managed-api-enabled</param-name>
|
||||||
<param-value>false</param-value>
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>managed-api-owner</param-name>
|
||||||
|
<param-value>admin</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
|
|
||||||
<filter>
|
<filter>
|
||||||
|
|||||||
@ -107,6 +107,10 @@
|
|||||||
<groupId>javax.ws.rs</groupId>
|
<groupId>javax.ws.rs</groupId>
|
||||||
<artifactId>javax.ws.rs-api</artifactId>
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.apimgt.webapp.publisher;
|
package org.wso2.carbon.apimgt.webapp.publisher;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
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.apimgt.api.APIManagementException;
|
import org.wso2.carbon.apimgt.api.APIManagementException;
|
||||||
@ -30,6 +29,10 @@ import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
|
|||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig;
|
import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig;
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
import org.wso2.carbon.base.MultitenantConstants;
|
||||||
import org.wso2.carbon.core.util.Utils;
|
import org.wso2.carbon.core.util.Utils;
|
||||||
|
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementService;
|
||||||
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -121,16 +124,18 @@ public class APIPublisherUtil {
|
|||||||
if (scope != null) {
|
if (scope != null) {
|
||||||
if (apiScopes.get(scope.getKey()) == null) {
|
if (apiScopes.get(scope.getKey()) == null) {
|
||||||
apiScopes.put(scope.getKey(), scope);
|
apiScopes.put(scope.getKey(), scope);
|
||||||
} else {
|
|
||||||
existingScope = apiScopes.get(scope.getKey());
|
|
||||||
existingPermissions = existingScope.getRoles();
|
|
||||||
existingPermissions = getDistinctPermissions(existingPermissions + "," + scope.getRoles());
|
|
||||||
existingScope.setRoles(existingPermissions);
|
|
||||||
apiScopes.put(scope.getKey(), existingScope);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Set<Scope> scopes = new HashSet<>(apiScopes.values());
|
Set<Scope> scopes = new HashSet<>(apiScopes.values());
|
||||||
|
// adding existing persisted roles to the scopes
|
||||||
|
try {
|
||||||
|
setExistingRoles(scopes);
|
||||||
|
} catch (ScopeManagementException | UserStoreException e) {
|
||||||
|
throw new APIManagementException("Error occurred while retrieving roles for the existing scopes");
|
||||||
|
}
|
||||||
|
|
||||||
|
// set current scopes to API
|
||||||
api.setScopes(scopes);
|
api.setScopes(scopes);
|
||||||
|
|
||||||
// this has to be done because of the use of pass by reference
|
// this has to be done because of the use of pass by reference
|
||||||
@ -307,9 +312,34 @@ public class APIPublisherUtil {
|
|||||||
return apiConfig;
|
return apiConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getDistinctPermissions(String permissions) {
|
/**
|
||||||
String[] unique = new HashSet<String>(Arrays.asList(permissions.split(","))).toArray(new String[0]);
|
* This method is used to set the existing roles of the given scope.
|
||||||
return StringUtils.join(unique, ",");
|
*
|
||||||
|
* @param scopes List of scopes.
|
||||||
|
* @throws ScopeManagementException
|
||||||
|
*/
|
||||||
|
private static void setExistingRoles(Set<Scope> scopes) throws ScopeManagementException, UserStoreException {
|
||||||
|
String scopeKey;
|
||||||
|
String roles;
|
||||||
|
ScopeManagementService scopeManagementService = WebappPublisherUtil.getScopeManagementService();
|
||||||
|
UserRealm userRealm = WebappPublisherUtil.getUserRealm();
|
||||||
|
|
||||||
|
if (scopeManagementService == null) {
|
||||||
|
throw new ScopeManagementException("Error occurred while initializing scope management service");
|
||||||
|
} else if (userRealm == null) {
|
||||||
|
throw new UserStoreException("Error occurred while initializing realm service");
|
||||||
|
} else {
|
||||||
|
String adminRole = userRealm.getRealmConfiguration().getAdminRoleName();
|
||||||
|
for (Scope scope : scopes) {
|
||||||
|
scopeKey = scope.getKey();
|
||||||
|
roles = scopeManagementService.getRolesOfScope(scopeKey);
|
||||||
|
if (roles == null) {
|
||||||
|
roles = adminRole;
|
||||||
|
}
|
||||||
|
scope.setRoles(roles);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,16 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.apimgt.webapp.publisher;
|
package org.wso2.carbon.apimgt.webapp.publisher;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementService;
|
||||||
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
@ -31,6 +40,10 @@ import java.io.File;
|
|||||||
*/
|
*/
|
||||||
public class WebappPublisherUtil {
|
public class WebappPublisherUtil {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(WebappPublisherUtil.class);
|
||||||
|
private static final int CARBON_SUPER = -1234;
|
||||||
|
|
||||||
|
|
||||||
public static Document convertToDocument(File file) throws WebappPublisherConfigurationFailedException {
|
public static Document convertToDocument(File file) throws WebappPublisherConfigurationFailedException {
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
factory.setNamespaceAware(true);
|
factory.setNamespaceAware(true);
|
||||||
@ -44,4 +57,32 @@ public class WebappPublisherUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ScopeManagementService getScopeManagementService() {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
ScopeManagementService scopeManagementService =
|
||||||
|
(ScopeManagementService) ctx.getOSGiService(ScopeManagementService.class, null);
|
||||||
|
if (scopeManagementService == null) {
|
||||||
|
String msg = "Scope Management Service has not been initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
return scopeManagementService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting the current tenant's user realm
|
||||||
|
*/
|
||||||
|
public static UserRealm getUserRealm() throws UserStoreException {
|
||||||
|
RealmService realmService;
|
||||||
|
UserRealm realm;
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||||
|
|
||||||
|
if (realmService == null) {
|
||||||
|
throw new IllegalStateException("Realm service not initialized");
|
||||||
|
}
|
||||||
|
realm = realmService.getTenantUserRealm(CARBON_SUPER);
|
||||||
|
return realm;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* you may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.apimgt.webapp.publisher.config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom exception class of Permission related operations.
|
|
||||||
*/
|
|
||||||
public class PermissionManagementException extends Exception {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -3151279311929070298L;
|
|
||||||
|
|
||||||
private String errorMessage;
|
|
||||||
|
|
||||||
public String getErrorMessage() {
|
|
||||||
return errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorMessage(String errorMessage) {
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PermissionManagementException(String msg, Exception nestedEx) {
|
|
||||||
super(msg, nestedEx);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PermissionManagementException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
setErrorMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PermissionManagementException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PermissionManagementException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PermissionManagementException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -19,20 +19,13 @@
|
|||||||
package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util;
|
package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util;
|
||||||
|
|
||||||
import org.apache.catalina.core.StandardContext;
|
import org.apache.catalina.core.StandardContext;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
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.scannotation.AnnotationDB;
|
|
||||||
import org.scannotation.WarUrlFinder;
|
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
|
||||||
import org.wso2.carbon.apimgt.api.model.Scope;
|
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil;
|
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource;
|
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
|
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.PermissionConfiguration;
|
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.PermissionManagementException;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
@ -61,11 +54,9 @@ public class AnnotationProcessor {
|
|||||||
private static final String WILD_CARD = "/*";
|
private static final String WILD_CARD = "/*";
|
||||||
|
|
||||||
private static final String AUTH_TYPE = "Any";
|
private static final String AUTH_TYPE = "Any";
|
||||||
private static final String PROTOCOL_HTTP = "http";
|
|
||||||
private static final String SERVER_HOST = "carbon.local.ip";
|
|
||||||
private static final String HTTP_PORT = "httpPort";
|
|
||||||
private static final String STRING_ARR = "string_arr";
|
private static final String STRING_ARR = "string_arr";
|
||||||
private static final String STRING = "string";
|
private static final String STRING = "string";
|
||||||
|
|
||||||
Class<API> apiClazz;
|
Class<API> apiClazz;
|
||||||
private StandardContext context;
|
private StandardContext context;
|
||||||
private Method[] pathClazzMethods;
|
private Method[] pathClazzMethods;
|
||||||
@ -75,7 +66,6 @@ public class AnnotationProcessor {
|
|||||||
|
|
||||||
|
|
||||||
public AnnotationProcessor(final StandardContext context) {
|
public AnnotationProcessor(final StandardContext context) {
|
||||||
this.context = context;
|
|
||||||
servletContext = context.getServletContext();
|
servletContext = context.getServletContext();
|
||||||
classLoader = servletContext.getClassLoader();
|
classLoader = servletContext.getClassLoader();
|
||||||
}
|
}
|
||||||
@ -141,7 +131,7 @@ public class AnnotationProcessor {
|
|||||||
pathClazzMethods = pathClazz.getMethods();
|
pathClazzMethods = pathClazz.getMethods();
|
||||||
|
|
||||||
Annotation rootContectAnno = clazz.getAnnotation(pathClazz);
|
Annotation rootContectAnno = clazz.getAnnotation(pathClazz);
|
||||||
String subContext = "";
|
String subContext;
|
||||||
if (rootContectAnno != null) {
|
if (rootContectAnno != null) {
|
||||||
subContext = invokeMethod(pathClazzMethods[0], rootContectAnno, STRING);
|
subContext = invokeMethod(pathClazzMethods[0], rootContectAnno, STRING);
|
||||||
if (subContext != null && !subContext.isEmpty()) {
|
if (subContext != null && !subContext.isEmpty()) {
|
||||||
@ -150,8 +140,6 @@ public class AnnotationProcessor {
|
|||||||
} else {
|
} else {
|
||||||
rootContext = rootContext + "/" + subContext;
|
rootContext = rootContext + "/" + subContext;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
subContext = "";
|
|
||||||
}
|
}
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("API Root Context = " + rootContext);
|
log.debug("API Root Context = " + rootContext);
|
||||||
@ -166,7 +154,7 @@ public class AnnotationProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
log.error("Error when passing the api annotation for device type apis.");
|
log.error("Error when passing the api annotation for device type apis.", e);
|
||||||
}
|
}
|
||||||
return apiResourceConfig;
|
return apiResourceConfig;
|
||||||
}
|
}
|
||||||
@ -251,15 +239,9 @@ public class AnnotationProcessor {
|
|||||||
Annotation producesAnno = method.getAnnotation(producesClass);
|
Annotation producesAnno = method.getAnnotation(producesClass);
|
||||||
resource.setProduces(invokeMethod(producesClassMethods[0], producesAnno, STRING_ARR));
|
resource.setProduces(invokeMethod(producesClassMethods[0], producesAnno, STRING_ARR));
|
||||||
}
|
}
|
||||||
if (annotations[i].annotationType().getName().equals(Permission.class.getName())) {
|
if (annotations[i].annotationType().getName().equals(org.wso2.carbon.apimgt.annotations.api.Scope.class.getName())) {
|
||||||
PermissionConfiguration permissionConf = this.getPermission(method);
|
org.wso2.carbon.apimgt.api.model.Scope scope = this.getScope(method);
|
||||||
if (permissionConf != null) {
|
if (scope != null) {
|
||||||
Scope scope = new Scope();
|
|
||||||
scope.setKey(permissionConf.getScopeName());
|
|
||||||
scope.setDescription(permissionConf.getScopeName());
|
|
||||||
scope.setName(permissionConf.getScopeName());
|
|
||||||
String roles = StringUtils.join(permissionConf.getPermissions(), ",");
|
|
||||||
scope.setRoles(roles);
|
|
||||||
resource.setScope(scope);
|
resource.setScope(scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,35 +339,32 @@ public class AnnotationProcessor {
|
|||||||
return ((String[]) methodHandler.invoke(annotation, method, null));
|
return ((String[]) methodHandler.invoke(annotation, method, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
private PermissionConfiguration getPermission(Method currentMethod) throws Throwable {
|
private org.wso2.carbon.apimgt.api.model.Scope getScope(Method currentMethod) throws Throwable {
|
||||||
Class<Permission> permissionClass = (Class<Permission>) classLoader.loadClass(Permission.class.getName());
|
Class<org.wso2.carbon.apimgt.annotations.api.Scope> scopeClass =
|
||||||
Annotation permissionAnnotation = currentMethod.getAnnotation(permissionClass);
|
(Class<org.wso2.carbon.apimgt.annotations.api.Scope>) classLoader.
|
||||||
if (permissionClass != null) {
|
loadClass(org.wso2.carbon.apimgt.annotations.api.Scope.class.getName());
|
||||||
Method[] permissionClassMethods = permissionClass.getMethods();
|
Annotation permissionAnnotation = currentMethod.getAnnotation(scopeClass);
|
||||||
PermissionConfiguration permissionConf = new PermissionConfiguration();
|
if (scopeClass != null) {
|
||||||
|
Method[] permissionClassMethods = scopeClass.getMethods();
|
||||||
|
org.wso2.carbon.apimgt.api.model.Scope scope = new org.wso2.carbon.apimgt.api.model.Scope();
|
||||||
for (Method method : permissionClassMethods) {
|
for (Method method : permissionClassMethods) {
|
||||||
switch (method.getName()) {
|
switch (method.getName()) {
|
||||||
case "scope":
|
case "key":
|
||||||
permissionConf.setScopeName(invokeMethod(method, permissionAnnotation, STRING));
|
scope.setKey(invokeMethod(method, permissionAnnotation, STRING));
|
||||||
break;
|
break;
|
||||||
case "permissions":
|
case "name":
|
||||||
String permissions[] = invokeMethod(method, permissionAnnotation);
|
scope.setName(invokeMethod(method, permissionAnnotation, STRING));
|
||||||
this.addPermission(permissions);
|
break;
|
||||||
permissionConf.setPermissions(permissions);
|
case "description":
|
||||||
|
scope.setDescription(invokeMethod(method, permissionAnnotation, STRING));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return permissionConf;
|
return scope;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPermission(String[] permissions) throws PermissionManagementException {
|
|
||||||
for (String permission : permissions) {
|
|
||||||
PermissionUtils.addPermission(permission);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory
|
* Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory
|
||||||
* if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
|
* if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util;
|
package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util;
|
||||||
|
|
||||||
|
|
||||||
import org.scannotation.archiveiterator.DirectoryIteratorFactory;
|
import org.scannotation.archiveiterator.DirectoryIteratorFactory;
|
||||||
import org.scannotation.archiveiterator.Filter;
|
import org.scannotation.archiveiterator.Filter;
|
||||||
import org.scannotation.archiveiterator.JarIterator;
|
import org.scannotation.archiveiterator.JarIterator;
|
||||||
|
|||||||
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* you may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util;
|
|
||||||
|
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.PermissionManagementException;
|
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.registry.api.RegistryException;
|
|
||||||
import org.wso2.carbon.registry.api.Resource;
|
|
||||||
import org.wso2.carbon.registry.core.Registry;
|
|
||||||
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class which holds necessary utility methods required for persisting permissions in
|
|
||||||
* registry.
|
|
||||||
*/
|
|
||||||
public class PermissionUtils {
|
|
||||||
|
|
||||||
public static final String ADMIN_PERMISSION_REGISTRY_PATH = "/permission/admin";
|
|
||||||
public static final String PERMISSION_PROPERTY_NAME = "name";
|
|
||||||
|
|
||||||
public static Registry getGovernanceRegistry() throws PermissionManagementException {
|
|
||||||
try {
|
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
return APIPublisherDataHolder.getInstance().getRegistryService()
|
|
||||||
.getGovernanceSystemRegistry(
|
|
||||||
tenantId);
|
|
||||||
} catch (RegistryException e) {
|
|
||||||
throw new PermissionManagementException(
|
|
||||||
"Error in retrieving governance registry instance: " +
|
|
||||||
e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addPermission(String permission) throws PermissionManagementException {
|
|
||||||
String resourcePermission = getAbsolutePermissionPath(permission);
|
|
||||||
try {
|
|
||||||
StringTokenizer tokenizer = new StringTokenizer(resourcePermission, "/");
|
|
||||||
String lastToken = "", currentToken, tempPath;
|
|
||||||
while (tokenizer.hasMoreTokens()) {
|
|
||||||
currentToken = tokenizer.nextToken();
|
|
||||||
tempPath = lastToken + "/" + currentToken;
|
|
||||||
if (!checkResourceExists(tempPath)) {
|
|
||||||
createRegistryCollection(tempPath, currentToken);
|
|
||||||
}
|
|
||||||
lastToken = tempPath;
|
|
||||||
}
|
|
||||||
} catch (RegistryException e) {
|
|
||||||
throw new PermissionManagementException("Error occurred while persisting permission : " +
|
|
||||||
resourcePermission, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void createRegistryCollection(String path, String resourceName)
|
|
||||||
throws PermissionManagementException,
|
|
||||||
RegistryException {
|
|
||||||
Resource resource = PermissionUtils.getGovernanceRegistry().newCollection();
|
|
||||||
resource.addProperty(PERMISSION_PROPERTY_NAME, resourceName);
|
|
||||||
PermissionUtils.getGovernanceRegistry().beginTransaction();
|
|
||||||
PermissionUtils.getGovernanceRegistry().put(path, resource);
|
|
||||||
PermissionUtils.getGovernanceRegistry().commitTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkResourceExists(String path)
|
|
||||||
throws PermissionManagementException,
|
|
||||||
org.wso2.carbon.registry.core.exceptions.RegistryException {
|
|
||||||
return PermissionUtils.getGovernanceRegistry().resourceExists(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getAbsolutePermissionPath(String permissionPath) {
|
|
||||||
return PermissionUtils.ADMIN_PERMISSION_REGISTRY_PATH + permissionPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -76,7 +76,7 @@
|
|||||||
<tasks>
|
<tasks>
|
||||||
<copy todir="${basedir}/../../../repository/deployment/server/webapps" overwrite="true">
|
<copy todir="${basedir}/../../../repository/deployment/server/webapps" overwrite="true">
|
||||||
<fileset dir="${basedir}/target">
|
<fileset dir="${basedir}/target">
|
||||||
<include name="api#scep-mgt#v1.0.war" />
|
<include name="api-scep-mgt-v1.0.war"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
</tasks>
|
</tasks>
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import io.swagger.annotations.ApiOperation;
|
|||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import io.swagger.annotations.ApiResponse;
|
import io.swagger.annotations.ApiResponse;
|
||||||
import io.swagger.annotations.ApiResponses;
|
import io.swagger.annotations.ApiResponses;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.certificate.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.certificate.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
@ -46,7 +46,7 @@ public interface CertificateMgtService {
|
|||||||
message = "Internal Server Error. \n Error occurred while retrieving signed certificate.",
|
message = "Internal Server Error. \n Error occurred while retrieving signed certificate.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "sign-csr", permissions = {"/permission/admin/device-mgt/scep/sign-csr"})
|
@Scope(key = "certificate:sign-csr", name = "Sign CSR", description = "")
|
||||||
Response getSignedCertFromCSR(
|
Response getSignedCertFromCSR(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
package org.wso2.carbon.certificate.mgt.cert.jaxrs.api;
|
package org.wso2.carbon.certificate.mgt.cert.jaxrs.api;
|
||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.CertificateList;
|
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.CertificateList;
|
||||||
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.EnrollmentCertificate;
|
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.EnrollmentCertificate;
|
||||||
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.ErrorResponse;
|
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.ErrorResponse;
|
||||||
@ -11,6 +12,10 @@ import javax.ws.rs.*;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@API(name = "Certificate Management", version = "1.0.0",
|
||||||
|
context = "api/certificate-mgt/v1.0/admin/certificates",
|
||||||
|
tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
@Api(value = "Certificate Management", description = "This API carries all certificate management related operations " +
|
@Api(value = "Certificate Management", description = "This API carries all certificate management related operations " +
|
||||||
"such as get all the available devices, etc.")
|
"such as get all the available devices, etc.")
|
||||||
@Path("/admin/certificates")
|
@Path("/admin/certificates")
|
||||||
@ -72,7 +77,7 @@ public interface CertificateManagementAdminService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while adding certificates.",
|
message = "Internal Server Error. \n Server error occurred while adding certificates.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "certificate-modify", permissions = {"/permission/admin/device-mgt/certificate/save"})
|
@Scope(key = "certificate:manage", name = "Add certificates", description = "")
|
||||||
Response addCertificate(
|
Response addCertificate(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "enrollmentCertificates",
|
name = "enrollmentCertificates",
|
||||||
@ -130,7 +135,7 @@ public interface CertificateManagementAdminService {
|
|||||||
"Server error occurred while retrieving information requested certificate.",
|
"Server error occurred while retrieving information requested certificate.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "certificate-view", permissions = {"/permission/admin/device-mgt/certificate/view"})
|
@Scope(key = "certificate:view", name = "View certificates", description = "")
|
||||||
Response getCertificate(
|
Response getCertificate(
|
||||||
@ApiParam(name = "serialNumber",
|
@ApiParam(name = "serialNumber",
|
||||||
value = "Provide the serial number of the certificate that you wish to get the details of",
|
value = "Provide the serial number of the certificate that you wish to get the details of",
|
||||||
@ -202,7 +207,7 @@ public interface CertificateManagementAdminService {
|
|||||||
"Server error occurred while retrieving all certificates enrolled in the system.",
|
"Server error occurred while retrieving all certificates enrolled in the system.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "certificate-view", permissions = {"/permission/admin/device-mgt/certificate/view"})
|
@Scope(key = "certificate:view", name = "View certificates", description = "")
|
||||||
Response getAllCertificates(
|
Response getAllCertificates(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "offset",
|
name = "offset",
|
||||||
@ -245,7 +250,7 @@ public interface CertificateManagementAdminService {
|
|||||||
message = "Internal Server Error. \n " +
|
message = "Internal Server Error. \n " +
|
||||||
"Server error occurred while removing the certificate.",
|
"Server error occurred while removing the certificate.",
|
||||||
response = ErrorResponse.class)})
|
response = ErrorResponse.class)})
|
||||||
@Permission(scope = "certificate-modify", permissions = {"/permission/admin/device-mgt/certificate/remove"})
|
@Scope(key = "certificate:manage", name = "Add certificates", description = "")
|
||||||
Response removeCertificate(
|
Response removeCertificate(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "serialNumber",
|
name = "serialNumber",
|
||||||
|
|||||||
@ -122,11 +122,14 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem
|
|||||||
try {
|
try {
|
||||||
boolean status = certificateService.removeCertificate(serialNumber);
|
boolean status = certificateService.removeCertificate(serialNumber);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
Response.status(Response.Status.NOT_FOUND).entity("No certificate is found with the given " +
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
"serial number '" + serialNumber + "'");
|
"No certificate is found with the given " +
|
||||||
}
|
"serial number '" + serialNumber + "'").build();
|
||||||
return Response.status(Response.Status.OK).entity("Certificate that carries the serial number '" +
|
} else {
|
||||||
|
return Response.status(Response.Status.OK).entity(
|
||||||
|
"Certificate that carries the serial number '" +
|
||||||
serialNumber + "' has been removed").build();
|
serialNumber + "' has been removed").build();
|
||||||
|
}
|
||||||
} catch (CertificateManagementException e) {
|
} catch (CertificateManagementException e) {
|
||||||
String msg = "Error occurred while converting PEM file to X509Certificate";
|
String msg = "Error occurred while converting PEM file to X509Certificate";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
|
|||||||
@ -44,7 +44,7 @@
|
|||||||
<property name="version" value="1.0.0"/>
|
<property name="version" value="1.0.0"/>
|
||||||
<property name="host" value="localhost:9443"/>
|
<property name="host" value="localhost:9443"/>
|
||||||
<property name="schemes" value="https" />
|
<property name="schemes" value="https" />
|
||||||
<property name="basePath" value="/api/certificate-mgt/v1.0"/>
|
<property name="basePath" value="/api-certificate-mgt-v1.0"/>
|
||||||
<property name="title" value="Certificate Management Admin Service API Definitions"/>
|
<property name="title" value="Certificate Management Admin Service API Definitions"/>
|
||||||
<property name="contact" value="dev@wso2.org"/>
|
<property name="contact" value="dev@wso2.org"/>
|
||||||
<property name="license" value="Apache 2.0"/>
|
<property name="license" value="Apache 2.0"/>
|
||||||
|
|||||||
@ -110,14 +110,17 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.cxf</groupId>
|
<groupId>org.apache.cxf</groupId>
|
||||||
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.cxf</groupId>
|
<groupId>org.apache.cxf</groupId>
|
||||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.cxf</groupId>
|
<groupId>org.apache.cxf</groupId>
|
||||||
<artifactId>cxf-rt-transports-http</artifactId>
|
<artifactId>cxf-rt-transports-http</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
@ -237,6 +240,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
@ -248,6 +252,14 @@
|
|||||||
<artifactId>jackson-annotations</artifactId>
|
<artifactId>jackson-annotations</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-validator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public class ErrorResponse {
|
|||||||
private String moreInfo = null;
|
private String moreInfo = null;
|
||||||
private List<ErrorListItem> errorItems = new ArrayList<>();
|
private List<ErrorListItem> errorItems = new ArrayList<>();
|
||||||
|
|
||||||
private ErrorResponse() {
|
public ErrorResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty(value = "code")
|
@JsonProperty(value = "code")
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel;
|
|||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ApiModel(value = "PolicyWrapper", description = "This class carries all information related to Policy "
|
@ApiModel(value = "PolicyWrapper", description = "This class carries all information related to Policy "
|
||||||
@ -29,9 +30,11 @@ import java.util.List;
|
|||||||
public class PolicyWrapper {
|
public class PolicyWrapper {
|
||||||
|
|
||||||
@ApiModelProperty(name = "policyName", value = "The name of the policy", required = true)
|
@ApiModelProperty(name = "policyName", value = "The name of the policy", required = true)
|
||||||
|
@Size(max = 45)
|
||||||
private String policyName;
|
private String policyName;
|
||||||
|
|
||||||
@ApiModelProperty(name = "description", value = "Gives a description on the policy", required = true)
|
@ApiModelProperty(name = "description", value = "Gives a description on the policy", required = true)
|
||||||
|
@Size(max = 1000)
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@ApiModelProperty(name = "compliance", value = "Provides the non-compliance rules. WSO2 EMM provides the"
|
@ApiModelProperty(name = "compliance", value = "Provides the non-compliance rules. WSO2 EMM provides the"
|
||||||
@ -41,6 +44,7 @@ public class PolicyWrapper {
|
|||||||
+ "Monitor - If the device does not adhere to the given policies the server is notified of the "
|
+ "Monitor - If the device does not adhere to the given policies the server is notified of the "
|
||||||
+ "violation unknown to the user and the administrator can take the necessary actions with regard"
|
+ "violation unknown to the user and the administrator can take the necessary actions with regard"
|
||||||
+ " to the reported", required = true)
|
+ " to the reported", required = true)
|
||||||
|
@Size(max = 100)
|
||||||
private String compliance;
|
private String compliance;
|
||||||
|
|
||||||
@ApiModelProperty(name = "ownershipType", value = "The policy ownership type. It can be any of the "
|
@ApiModelProperty(name = "ownershipType", value = "The policy ownership type. It can be any of the "
|
||||||
@ -49,6 +53,7 @@ public class PolicyWrapper {
|
|||||||
+ "BYOD (Bring Your Own Device) - The policy will only be applied on the BYOD device type\n"
|
+ "BYOD (Bring Your Own Device) - The policy will only be applied on the BYOD device type\n"
|
||||||
+ "COPE (Corporate-Owned, Personally-Enabled) - The policy will only be applied on the COPE "
|
+ "COPE (Corporate-Owned, Personally-Enabled) - The policy will only be applied on the COPE "
|
||||||
+ "device type", required = true)
|
+ "device type", required = true)
|
||||||
|
@Size(max = 45)
|
||||||
private String ownershipType;
|
private String ownershipType;
|
||||||
|
|
||||||
@ApiModelProperty(name = "active", value = "If the value is true it indicates that the policy is active. "
|
@ApiModelProperty(name = "active", value = "If the value is true it indicates that the policy is active. "
|
||||||
|
|||||||
@ -20,7 +20,6 @@ package org.wso2.carbon.device.mgt.jaxrs.beans;
|
|||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|||||||
@ -20,7 +20,8 @@ package org.wso2.carbon.device.mgt.jaxrs.beans;
|
|||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@ApiModel(value = "RoleInfo", description = "Role details including permission and the users in the roles are " +
|
@ApiModel(value = "RoleInfo", description = "Role details including permission and the users in the roles are " +
|
||||||
"wrapped here.")
|
"wrapped here.")
|
||||||
@ -28,19 +29,12 @@ public class RoleInfo {
|
|||||||
|
|
||||||
@ApiModelProperty(name = "roleName", value = "The name of the role.", required = true)
|
@ApiModelProperty(name = "roleName", value = "The name of the role.", required = true)
|
||||||
private String roleName;
|
private String roleName;
|
||||||
@ApiModelProperty(name = "permissions", value = "Lists out all the permissions associated with roles.",
|
@ApiModelProperty(name = "scopes", value = "Lists out all the scopes associated with roles.",
|
||||||
required = true, dataType = "List[java.lang.String]")
|
required = true, dataType = "List[org.wso2.carbon.device.mgt.jaxrs.beans.Scope]")
|
||||||
private String[] permissions;
|
private List<Scope> scopes;
|
||||||
@ApiModelProperty(name = "users", value = "The list of users assigned to the selected role.",
|
@ApiModelProperty(name = "users", value = "The list of users assigned to the selected role.",
|
||||||
required = true, dataType = "List[java.lang.String]")
|
required = true, dataType = "List[java.lang.String]")
|
||||||
private String[] users;
|
private String[] users;
|
||||||
@ApiModelProperty(name = "permissionList", value = "This contain the following, " +
|
|
||||||
"\n resourcePath\tThe path related to the API.\n " +
|
|
||||||
"displayName\tThe name of the permission that is shown " +
|
|
||||||
"in the UI.\n" +
|
|
||||||
"nodeList\tLists out the nested permissions.",
|
|
||||||
required = true)
|
|
||||||
private UIPermissionNode permissionList;
|
|
||||||
|
|
||||||
public String getRoleName() {
|
public String getRoleName() {
|
||||||
return roleName;
|
return roleName;
|
||||||
@ -50,12 +44,12 @@ public class RoleInfo {
|
|||||||
this.roleName = roleName;
|
this.roleName = roleName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getPermissions() {
|
public List<Scope> getScopes() {
|
||||||
return permissions;
|
return scopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPermissions(String[] permissions) {
|
public void setScopes(List<Scope> scopes) {
|
||||||
this.permissions = permissions;
|
this.scopes = scopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getUsers() {
|
public String[] getUsers() {
|
||||||
@ -66,11 +60,4 @@ public class RoleInfo {
|
|||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UIPermissionNode getPermissionList() {
|
|
||||||
return permissionList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermissionList(UIPermissionNode permissionList) {
|
|
||||||
this.permissionList = permissionList;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
@ApiModel(value = "Scope", description = "Template of the authorization scope")
|
||||||
|
public class Scope {
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "scope key", value = "An unique string as a key.", required = true)
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "scope name", value = "Scope name.", required = true)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "roles", value = "List of roles to be associated with the scope", required = true)
|
||||||
|
private String roles;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "scope description", value = "A description of the scope", required = true)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public Scope() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return this.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoles() {
|
||||||
|
return this.roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoles(String roles) {
|
||||||
|
this.roles = roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -16,30 +16,19 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.apimgt.webapp.publisher.config;
|
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the information related to permissions.
|
* Custom exception class for wrapping BadRequest related exceptions.
|
||||||
*/
|
*/
|
||||||
public class PermissionConfiguration {
|
public class BadRequestException extends WebApplicationException {
|
||||||
|
|
||||||
private String scopeName;
|
public BadRequestException(ErrorResponse error) {
|
||||||
private String[] permissions;
|
super(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
|
||||||
|
|
||||||
public String getScopeName() {
|
|
||||||
return scopeName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScopeName(String scope) {
|
|
||||||
this.scopeName = scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getPermissions() {
|
|
||||||
return permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermissions(String[] permissions) {
|
|
||||||
this.permissions = permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ConstraintViolationException extends WebApplicationException {
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public <T> ConstraintViolationException(Set<ConstraintViolation<T>> violations) {
|
||||||
|
super(Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(DeviceMgtUtil.getConstraintViolationErrorDTO(violations))
|
||||||
|
.header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
//Set the error message
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (ConstraintViolation violation : violations) {
|
||||||
|
stringBuilder.append(violation.getRootBeanClass().getSimpleName());
|
||||||
|
stringBuilder.append(".");
|
||||||
|
stringBuilder.append(violation.getPropertyPath());
|
||||||
|
stringBuilder.append(": ");
|
||||||
|
stringBuilder.append(violation.getMessage());
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
}
|
||||||
|
message = stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ErrorDTO {
|
||||||
|
|
||||||
|
private Long code = null;
|
||||||
|
private String message = null;
|
||||||
|
private String description = null;
|
||||||
|
|
||||||
|
public void setMoreInfo(String moreInfo) {
|
||||||
|
this.moreInfo = moreInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(Long code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setError(List<ErrorDTO> error) {
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String moreInfo = null;
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMoreInfo() {
|
||||||
|
return moreInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ErrorDTO> getError() {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append("class ErrorDTO {\n");
|
||||||
|
stringBuilder.append(" code: ").append(code).append("\n");
|
||||||
|
stringBuilder.append(" message: ").append(message).append("\n");
|
||||||
|
stringBuilder.append(" description: ").append(description).append("\n");
|
||||||
|
stringBuilder.append(" moreInfo: ").append(moreInfo).append("\n");
|
||||||
|
stringBuilder.append(" error: ").append(error).append("\n");
|
||||||
|
stringBuilder.append("}\n");
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ErrorDTO> error = new ArrayList<>();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||||
|
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception class that is corresponding to 401 Forbidden response
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ForbiddenException extends WebApplicationException {
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public ForbiddenException() {
|
||||||
|
super(Response.status(Response.Status.FORBIDDEN)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ForbiddenException(ErrorDTO errorDTO) {
|
||||||
|
super(Response.status(Response.Status.FORBIDDEN)
|
||||||
|
.entity(errorDTO)
|
||||||
|
.header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
|
||||||
|
.build());
|
||||||
|
message = errorDTO.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||||
|
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
|
||||||
|
|
||||||
|
import javax.naming.AuthenticationException;
|
||||||
|
import javax.ws.rs.ClientErrorException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.ext.ExceptionMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the cxf level exceptions.
|
||||||
|
*/
|
||||||
|
public class GlobalThrowableMapper implements ExceptionMapper {
|
||||||
|
private static final Log log = LogFactory.getLog(GlobalThrowableMapper.class);
|
||||||
|
|
||||||
|
private ErrorDTO e500 = new ErrorDTO();
|
||||||
|
|
||||||
|
GlobalThrowableMapper() {
|
||||||
|
e500.setCode((long) 500);
|
||||||
|
e500.setMessage("Internal server error.");
|
||||||
|
e500.setMoreInfo("");
|
||||||
|
e500.setDescription("The server encountered an internal error. Please contact administrator.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response toResponse(Throwable e) {
|
||||||
|
|
||||||
|
if (e instanceof JsonParseException) {
|
||||||
|
String errorMessage = "Malformed request body.";
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error(errorMessage, e);
|
||||||
|
}
|
||||||
|
return DeviceMgtUtil.buildBadRequestException(errorMessage).getResponse();
|
||||||
|
}
|
||||||
|
if (e instanceof NotFoundException) {
|
||||||
|
return ((NotFoundException) e).getResponse();
|
||||||
|
}
|
||||||
|
if (e instanceof UnexpectedServerErrorException) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Unexpected server error.", e);
|
||||||
|
}
|
||||||
|
return ((UnexpectedServerErrorException) e).getResponse();
|
||||||
|
}
|
||||||
|
if (e instanceof ConstraintViolationException) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Constraint violation.", e);
|
||||||
|
}
|
||||||
|
return ((ConstraintViolationException) e).getResponse();
|
||||||
|
}
|
||||||
|
if (e instanceof IllegalArgumentException) {
|
||||||
|
ErrorDTO errorDetail = new ErrorDTO();
|
||||||
|
errorDetail.setCode((long) 400);
|
||||||
|
errorDetail.setMoreInfo("");
|
||||||
|
errorDetail.setMessage("");
|
||||||
|
errorDetail.setDescription(e.getMessage());
|
||||||
|
return Response
|
||||||
|
.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(errorDetail)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
if (e instanceof ClientErrorException) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Client error.", e);
|
||||||
|
}
|
||||||
|
return ((ClientErrorException) e).getResponse();
|
||||||
|
}
|
||||||
|
if (e instanceof AuthenticationException) {
|
||||||
|
ErrorDTO errorDetail = new ErrorDTO();
|
||||||
|
errorDetail.setCode((long) 401);
|
||||||
|
errorDetail.setMoreInfo("");
|
||||||
|
errorDetail.setMessage("");
|
||||||
|
errorDetail.setDescription(e.getMessage());
|
||||||
|
return Response
|
||||||
|
.status(Response.Status.UNAUTHORIZED)
|
||||||
|
.entity(errorDetail)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
if (e instanceof ForbiddenException) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Resource forbidden.", e);
|
||||||
|
}
|
||||||
|
return ((ForbiddenException) e).getResponse();
|
||||||
|
}
|
||||||
|
//unknown exception log and return
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("An Unknown exception has been captured by global exception mapper.", e);
|
||||||
|
}
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).header("Content-Type", "application/json")
|
||||||
|
.entity(e500).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||||
|
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
public class NotFoundException extends WebApplicationException {
|
||||||
|
private String message;
|
||||||
|
private static final long serialVersionUID = 147943572342342340L;
|
||||||
|
|
||||||
|
public NotFoundException(ErrorResponse error) {
|
||||||
|
super(Response.status(Response.Status.NOT_FOUND).entity(error).build());
|
||||||
|
}
|
||||||
|
public NotFoundException(ErrorDTO errorDTO) {
|
||||||
|
super(Response.status(Response.Status.NOT_FOUND)
|
||||||
|
.entity(errorDTO)
|
||||||
|
.header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
|
||||||
|
.build());
|
||||||
|
message = errorDTO.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||||
|
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
public class UnexpectedServerErrorException extends WebApplicationException {
|
||||||
|
private String message;
|
||||||
|
private static final long serialVersionUID = 147943579458906890L;
|
||||||
|
|
||||||
|
public UnexpectedServerErrorException(ErrorResponse error) {
|
||||||
|
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build());
|
||||||
|
}
|
||||||
|
public UnexpectedServerErrorException(ErrorDTO errorDTO) {
|
||||||
|
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
|
.entity(errorDTO)
|
||||||
|
.header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
|
||||||
|
.build());
|
||||||
|
message = errorDTO.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.cxf.interceptor.Fault;
|
||||||
|
import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
|
||||||
|
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
|
||||||
|
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
|
||||||
|
import org.apache.cxf.message.Message;
|
||||||
|
import org.apache.cxf.message.MessageContentsList;
|
||||||
|
import org.apache.cxf.phase.AbstractPhaseInterceptor;
|
||||||
|
import org.apache.cxf.phase.Phase;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.Validation;
|
||||||
|
import javax.validation.Validator;
|
||||||
|
import javax.validation.ValidatorFactory;
|
||||||
|
import javax.validation.executable.ExecutableValidator;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ValidationInterceptor extends AbstractPhaseInterceptor<Message> {
|
||||||
|
private Log log = LogFactory.getLog(getClass());
|
||||||
|
private Validator validator = null; //validator interface is thread-safe
|
||||||
|
|
||||||
|
public ValidationInterceptor() {
|
||||||
|
super(Phase.PRE_INVOKE);
|
||||||
|
ValidatorFactory defaultFactory = Validation.buildDefaultValidatorFactory();
|
||||||
|
validator = defaultFactory.getValidator();
|
||||||
|
if (validator == null) {
|
||||||
|
log.warn("Bean Validation provider could not be found, no validation will be performed");
|
||||||
|
} else {
|
||||||
|
log.debug("Validation In-Interceptor initialized successfully");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message message) throws Fault {
|
||||||
|
final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
|
||||||
|
if (operationResource == null) {
|
||||||
|
log.info("OperationResourceInfo is not available, skipping validation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
|
||||||
|
if (classResource == null) {
|
||||||
|
log.info("ClassResourceInfo is not available, skipping validation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ResourceProvider resourceProvider = classResource.getResourceProvider();
|
||||||
|
if (resourceProvider == null) {
|
||||||
|
log.info("ResourceProvider is not available, skipping validation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<Object> arguments = MessageContentsList.getContentsList(message);
|
||||||
|
final Method method = operationResource.getAnnotatedMethod();
|
||||||
|
final Object instance = resourceProvider.getInstance(message);
|
||||||
|
if (method != null && arguments != null) {
|
||||||
|
//validate the parameters(arguments) over the invoked method
|
||||||
|
validate(method, arguments.toArray(), instance);
|
||||||
|
|
||||||
|
//validate the fields of each argument
|
||||||
|
for (Object arg : arguments) {
|
||||||
|
if (arg != null)
|
||||||
|
validate(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void validate(final Method method, final Object[] arguments, final T instance) {
|
||||||
|
if (validator == null) {
|
||||||
|
log.warn("Bean Validation provider could not be found, no validation will be performed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExecutableValidator methodValidator = validator.forExecutables();
|
||||||
|
Set<ConstraintViolation<T>> violations = methodValidator.validateParameters(instance,
|
||||||
|
method, arguments);
|
||||||
|
|
||||||
|
if (!violations.isEmpty()) {
|
||||||
|
throw new ConstraintViolationException(violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void validate(final T object) {
|
||||||
|
if (validator == null) {
|
||||||
|
log.warn("Bean Validation provider could be found, no validation will be performed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<ConstraintViolation<T>> violations = validator.validate(object);
|
||||||
|
|
||||||
|
if (!violations.isEmpty()) {
|
||||||
|
throw new ConstraintViolationException(violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleFault(org.apache.cxf.message.Message messageParam) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,11 +20,12 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
|||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ActivityList;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ActivityList;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -32,7 +33,7 @@ import javax.ws.rs.core.Response;
|
|||||||
/**
|
/**
|
||||||
* Activity related REST-API implementation.
|
* Activity related REST-API implementation.
|
||||||
*/
|
*/
|
||||||
@API(name = "Activities", version = "1.0.0", context = "/devicemgt_admin/activities", tags = {"devicemgt_admin"})
|
@API(name = "Activity Info Provider", version = "1.0.0", context = "/api/device-mgt/v1.0/activities", tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
@Path("/activities")
|
@Path("/activities")
|
||||||
@Api(value = "Activity Info Provider", description = "Activity related information manipulation. For example operation details " +
|
@Api(value = "Activity Info Provider", description = "Activity related information manipulation. For example operation details " +
|
||||||
@ -91,16 +92,15 @@ public interface ActivityInfoProviderService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while fetching activity data.",
|
message = "Internal Server Error. \n Server error occurred while fetching activity data.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(
|
@Scope(key = "activity:view", name = "View Activities", description = "")
|
||||||
scope = "activity-view",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/activities/view"}
|
|
||||||
)
|
|
||||||
Response getActivity(
|
Response getActivity(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "id",
|
name = "id",
|
||||||
value = "Activity id of the operation/activity to be retrieved.",
|
value = "Activity id of the operation/activity to be retrieved.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("id") String id,
|
@PathParam("id")
|
||||||
|
@Size(max = 45)
|
||||||
|
String id,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
value = "Validates if the requested variant has not been modified since the time specified",
|
value = "Validates if the requested variant has not been modified since the time specified",
|
||||||
@ -153,10 +153,7 @@ public interface ActivityInfoProviderService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while fetching activity data.",
|
message = "Internal Server Error. \n Server error occurred while fetching activity data.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(
|
@Scope(key = "activity:view", name = "View Activities", description = "")
|
||||||
scope = "activity-view",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/activities/view"}
|
|
||||||
)
|
|
||||||
Response getActivities(
|
Response getActivities(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "since",
|
name = "since",
|
||||||
|
|||||||
@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
|||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ import javax.ws.rs.core.Response;
|
|||||||
/**
|
/**
|
||||||
* General Tenant Configuration REST-API.
|
* General Tenant Configuration REST-API.
|
||||||
*/
|
*/
|
||||||
@API(name = "Configuration", version = "1.0.0", context = "/devicemgt_admin/configuration", tags = {"devicemgt_admin"})
|
@API(name = "Configuration Management", version = "1.0.0", context = "/api/device-mgt/v1.0/configuration", tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
@Path("/configuration")
|
@Path("/configuration")
|
||||||
@Api(value = "Configuration Management", description = "General Tenant Configuration management capabilities are exposed " +
|
@Api(value = "Configuration Management", description = "General Tenant Configuration management capabilities are exposed " +
|
||||||
@ -80,12 +80,8 @@ public interface ConfigurationManagementService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while fetching the general " +
|
message = "Internal Server Error. \n Server error occurred while fetching the general " +
|
||||||
"platform configuration.",
|
"platform configuration.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "configuration:view", name = "View Configurations", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "configuration-view",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"}
|
|
||||||
)
|
|
||||||
Response getConfiguration(
|
Response getConfiguration(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
@ -130,12 +126,8 @@ public interface ConfigurationManagementService {
|
|||||||
message = "Internal Server Error. \n " +
|
message = "Internal Server Error. \n " +
|
||||||
"Server error occurred while modifying general platform configuration.",
|
"Server error occurred while modifying general platform configuration.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "configuration:modify", name = "Modify Configurations", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "configuration-modify",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"}
|
|
||||||
)
|
|
||||||
Response updateConfiguration(
|
Response updateConfiguration(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "configuration",
|
name = "configuration",
|
||||||
|
|||||||
@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
|||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
|||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -38,7 +39,7 @@ import javax.ws.rs.core.Response;
|
|||||||
/**
|
/**
|
||||||
* Device related REST-API. This can be used to manipulated device related details.
|
* Device related REST-API. This can be used to manipulated device related details.
|
||||||
*/
|
*/
|
||||||
@API(name = "Device", version = "1.0.0", context = "/api/device-mgt/admin/devices", tags = {"devicemgt_admin"})
|
@API(name = "Device Management", version = "1.0.0", context = "/api/device-mgt/v1.0/devices", tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
@Path("/devices")
|
@Path("/devices")
|
||||||
@Api(value = "Device Management", description = "This API carries all device management related operations " +
|
@Api(value = "Device Management", description = "This API carries all device management related operations " +
|
||||||
@ -91,33 +92,34 @@ public interface DeviceManagementService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while fetching the device list.",
|
message = "Internal Server Error. \n Server error occurred while fetching the device list.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(
|
@Scope(key = "device:view", name = "View Devices", description = "")
|
||||||
scope = "device-list",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/devices/list"}
|
|
||||||
)
|
|
||||||
Response getDevices(
|
Response getDevices(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "name",
|
name = "name",
|
||||||
value = "The device name, such as shamu, bullhead or angler.",
|
value = "The device name, such as shamu, bullhead or angler.",
|
||||||
required = false)
|
required = false)
|
||||||
|
@Size(max = 45)
|
||||||
String name,
|
String name,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "type",
|
name = "type",
|
||||||
value = "The device type, such as ios, android or windows.",
|
value = "The device type, such as ios, android or windows.",
|
||||||
required = false)
|
required = false)
|
||||||
@QueryParam("type")
|
@QueryParam("type")
|
||||||
|
@Size(max = 45)
|
||||||
String type,
|
String type,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "user",
|
name = "user",
|
||||||
value = "Username of owner of the devices.",
|
value = "Username of owner of the devices.",
|
||||||
required = false)
|
required = false)
|
||||||
@QueryParam("user")
|
@QueryParam("user")
|
||||||
|
@Size(max = 45)
|
||||||
String user,
|
String user,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "roleName",
|
name = "roleName",
|
||||||
value = "Role name of the devices to be fetched.",
|
value = "Role name of the devices to be fetched.",
|
||||||
required = false)
|
required = false)
|
||||||
@QueryParam("roleName")
|
@QueryParam("roleName")
|
||||||
|
@Size(max = 45)
|
||||||
String roleName,
|
String roleName,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "ownership",
|
name = "ownership",
|
||||||
@ -125,12 +127,14 @@ public interface DeviceManagementService {
|
|||||||
value = "Ownership of the devices to be fetched registered under.",
|
value = "Ownership of the devices to be fetched registered under.",
|
||||||
required = false)
|
required = false)
|
||||||
@QueryParam("ownership")
|
@QueryParam("ownership")
|
||||||
|
@Size(max = 45)
|
||||||
String ownership,
|
String ownership,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "status",
|
name = "status",
|
||||||
value = "Enrollment status of devices to be fetched.",
|
value = "Enrollment status of devices to be fetched.",
|
||||||
required = false)
|
required = false)
|
||||||
@QueryParam("status")
|
@QueryParam("status")
|
||||||
|
@Size(max = 45)
|
||||||
String status,
|
String status,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "since",
|
name = "since",
|
||||||
@ -203,25 +207,21 @@ public interface DeviceManagementService {
|
|||||||
"Server error occurred while retrieving information requested device.",
|
"Server error occurred while retrieving information requested device.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(
|
@Scope(key = "device:view", name = "View Devices", description = "")
|
||||||
scope = "device-view",
|
|
||||||
permissions = {
|
|
||||||
"/permission/admin/device-mgt/admin/devices/view",
|
|
||||||
"/permission/admin/device-mgt/user/devices/view"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Response getDevice(
|
Response getDevice(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "type",
|
name = "type",
|
||||||
value = "The device type, such as ios, android or windows.",
|
value = "The device type, such as ios, android or windows.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("type")
|
@PathParam("type")
|
||||||
|
@Size(max = 45)
|
||||||
String type,
|
String type,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "id",
|
name = "id",
|
||||||
value = "The device identifier of the device.",
|
value = "The device identifier of the device.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("id")
|
@PathParam("id")
|
||||||
|
@Size(max = 45)
|
||||||
String id,
|
String id,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
@ -289,24 +289,21 @@ public interface DeviceManagementService {
|
|||||||
"Server error occurred while retrieving feature list of the device.",
|
"Server error occurred while retrieving feature list of the device.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(
|
@Scope(key = "device:view", name = "View Devices", description = "")
|
||||||
scope = "device-search",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/devices/view",
|
|
||||||
"/permission/admin/device-mgt/user/devices/view"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Response getFeaturesOfDevice(
|
Response getFeaturesOfDevice(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "type",
|
name = "type",
|
||||||
value = "The device type, such as ios, android or windows.",
|
value = "The device type, such as ios, android or windows.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("type")
|
@PathParam("type")
|
||||||
|
@Size(max = 45)
|
||||||
String type,
|
String type,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "id",
|
name = "id",
|
||||||
value = "The device identifier of the device.",
|
value = "The device identifier of the device.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("id")
|
@PathParam("id")
|
||||||
|
@Size(max = 45)
|
||||||
String id,
|
String id,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
@ -368,10 +365,7 @@ public interface DeviceManagementService {
|
|||||||
"Server error occurred while enrolling the device.",
|
"Server error occurred while enrolling the device.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(
|
@Scope(key = "device:view", name = "View Devices", description = "")
|
||||||
scope = "device-search",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/devices/list" }
|
|
||||||
)
|
|
||||||
Response searchDevices(
|
Response searchDevices(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "offset",
|
name = "offset",
|
||||||
@ -450,24 +444,21 @@ public interface DeviceManagementService {
|
|||||||
"Server error occurred while retrieving installed application list of the device.",
|
"Server error occurred while retrieving installed application list of the device.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(
|
@Scope(key = "device:view", name = "View Devices", description = "")
|
||||||
scope = "operation-view",
|
|
||||||
permissions = {
|
|
||||||
"/permission/admin/device-mgt/admin/devices/view",
|
|
||||||
"/permission/admin/device-mgt/user/devices/view"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Response getInstalledApplications(
|
Response getInstalledApplications(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "type",
|
name = "type",
|
||||||
value = "The device type, such as ios, android or windows.", required = true)
|
value = "The device type, such as ios, android or windows.", required = true)
|
||||||
@PathParam("type")
|
@PathParam("type")
|
||||||
|
@Size(max = 45)
|
||||||
String type,
|
String type,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "id",
|
name = "id",
|
||||||
value = "The device identifier of the device.",
|
value = "The device identifier of the device.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("id")
|
@PathParam("id")
|
||||||
|
@Size(max = 45)
|
||||||
String id,
|
String id,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
@ -550,25 +541,21 @@ public interface DeviceManagementService {
|
|||||||
"Server error occurred while retrieving operation list scheduled for the device.",
|
"Server error occurred while retrieving operation list scheduled for the device.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(
|
@Scope(key = "device:view", name = "View Devices", description = "")
|
||||||
scope = "operation-view",
|
|
||||||
permissions = {
|
|
||||||
"/permission/admin/device-mgt/admin/devices/view",
|
|
||||||
"/permission/admin/device-mgt/user/devices/view"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Response getDeviceOperations(
|
Response getDeviceOperations(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "type",
|
name = "type",
|
||||||
value = "The device type, such as ios, android or windows.",
|
value = "The device type, such as ios, android or windows.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("type")
|
@PathParam("type")
|
||||||
|
@Size(max = 45)
|
||||||
String type,
|
String type,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "id",
|
name = "id",
|
||||||
value = "The device identifier of the device.",
|
value = "The device identifier of the device.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("id")
|
@PathParam("id")
|
||||||
|
@Size(max = 45)
|
||||||
String id,
|
String id,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
@ -652,18 +639,21 @@ public interface DeviceManagementService {
|
|||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@Scope(key = "device:view", name = "View Devices", description = "")
|
||||||
Response getEffectivePolicyOfDevice(
|
Response getEffectivePolicyOfDevice(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "type",
|
name = "type",
|
||||||
value = "The device type, such as ios, android or windows.",
|
value = "The device type, such as ios, android or windows.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("type")
|
@PathParam("type")
|
||||||
|
@Size(max = 45)
|
||||||
String type,
|
String type,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "id",
|
name = "id",
|
||||||
value = "Device Identifier",
|
value = "Device Identifier",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("id")
|
@PathParam("id")
|
||||||
|
@Size(max = 45)
|
||||||
String id,
|
String id,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
@ -674,7 +664,6 @@ public interface DeviceManagementService {
|
|||||||
String ifModifiedSince);
|
String ifModifiedSince);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{type}/{id}/compliance-data")
|
@Path("{type}/{id}/compliance-data")
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
@ -702,16 +691,20 @@ public interface DeviceManagementService {
|
|||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@Scope(key = "device:view", name = "View Devices", description = "")
|
||||||
Response getComplianceDataOfDevice(
|
Response getComplianceDataOfDevice(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "type",
|
name = "type",
|
||||||
value = "The device type, such as ios, android or windows.",
|
value = "The device type, such as ios, android or windows.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("type")
|
@PathParam("type")
|
||||||
|
@Size(max = 45)
|
||||||
String type,
|
String type,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "id",
|
name = "id",
|
||||||
value = "Device Identifier",
|
value = "Device Identifier",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("id") String id);
|
@PathParam("id")
|
||||||
|
@Size(max = 45)
|
||||||
|
String id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
||||||
|
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||||
|
|
||||||
|
|||||||
@ -20,13 +20,13 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
|||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.NotificationContext;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.NotificationList;
|
import org.wso2.carbon.device.mgt.jaxrs.NotificationList;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Max;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -34,7 +34,7 @@ import javax.ws.rs.core.Response;
|
|||||||
/**
|
/**
|
||||||
* Notifications related REST-API.
|
* Notifications related REST-API.
|
||||||
*/
|
*/
|
||||||
@API(name = "Device Notification Management API", version = "1.0.0", context = "/devicemgt_admin/notifications",
|
@API(name = "Device Notification Management", version = "1.0.0", context = "/api/device-mgt/v1.0/notifications",
|
||||||
tags = {"devicemgt_admin"})
|
tags = {"devicemgt_admin"})
|
||||||
@Api(value = "Device Notification Management", description = "Device notification related operations can be found here.")
|
@Api(value = "Device Notification Management", description = "Device notification related operations can be found here.")
|
||||||
@Path("/notifications")
|
@Path("/notifications")
|
||||||
@ -89,21 +89,15 @@ public interface NotificationManagementService {
|
|||||||
message = "Internal Server Error. " +
|
message = "Internal Server Error. " +
|
||||||
"\n Server error occurred while fetching the notification list.",
|
"\n Server error occurred while fetching the notification list.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "notification:view", name = "View and manage notifications", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "device-notification-view",
|
|
||||||
permissions = {
|
|
||||||
"/permission/admin/device-mgt/admin/notifications/view",
|
|
||||||
"/permission/admin/device-mgt/user/notifications/view" }
|
|
||||||
)
|
|
||||||
Response getNotifications(
|
Response getNotifications(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "status",
|
name = "status",
|
||||||
value = "Status of the notification.",
|
value = "Status of the notification.",
|
||||||
allowableValues = "NEW, CHECKED",
|
allowableValues = "NEW, CHECKED",
|
||||||
required = false)
|
required = false)
|
||||||
@QueryParam("status")
|
@QueryParam("status") @Size(max = 45)
|
||||||
String status,
|
String status,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
@ -148,15 +142,12 @@ public interface NotificationManagementService {
|
|||||||
message = "Error occurred while updating notification status.")
|
message = "Error occurred while updating notification status.")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@Permission(
|
@Scope(key = "notification:view", name = "View and manage notifications", description = "")
|
||||||
scope = "",
|
|
||||||
permissions = { "" }
|
|
||||||
)
|
|
||||||
Response updateNotificationStatus(
|
Response updateNotificationStatus(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "id",
|
name = "id",
|
||||||
value = "Notification ID.",
|
value = "Notification ID.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("id")
|
@PathParam("id") @Max(45)
|
||||||
int id);
|
int id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,12 +19,14 @@
|
|||||||
package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -34,6 +36,9 @@ import java.util.List;
|
|||||||
* Policy related REST-API. This can be used to manipulated policies and associate them with devices, users, roles,
|
* Policy related REST-API. This can be used to manipulated policies and associate them with devices, users, roles,
|
||||||
* groups.
|
* groups.
|
||||||
*/
|
*/
|
||||||
|
@API(name = "Device Policy Management", version = "1.0.0", context = "/api/device-mgt/v1.0/policies",
|
||||||
|
tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
@Api(value = "Device Policy Management", description = "This API carries all the necessary functionalities " +
|
@Api(value = "Device Policy Management", description = "This API carries all the necessary functionalities " +
|
||||||
"around device policy management")
|
"around device policy management")
|
||||||
@Path("/policies")
|
@Path("/policies")
|
||||||
@ -94,18 +99,14 @@ public interface PolicyManagementService {
|
|||||||
message = "Internal Server Error. \n " +
|
message = "Internal Server Error. \n " +
|
||||||
"Server error occurred while adding a new policy.",
|
"Server error occurred while adding a new policy.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "policy:manage", name = "Add policies", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "policy-modify",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/policies/add"}
|
|
||||||
)
|
|
||||||
Response addPolicy(
|
Response addPolicy(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "policy",
|
name = "policy",
|
||||||
value = "Policy details related to the operation.",
|
value = "Policy details related to the operation.",
|
||||||
required = true)
|
required = true)
|
||||||
PolicyWrapper policy);
|
@Valid PolicyWrapper policy);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
@ -152,12 +153,8 @@ public interface PolicyManagementService {
|
|||||||
message = ("Internal Server Error. \n Server error occurred while fetching " +
|
message = ("Internal Server Error. \n Server error occurred while fetching " +
|
||||||
"policies."),
|
"policies."),
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "policy:view", name = "Views policies", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "policy-view",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/policies/list"}
|
|
||||||
)
|
|
||||||
Response getPolicies(
|
Response getPolicies(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
@ -223,10 +220,7 @@ public interface PolicyManagementService {
|
|||||||
"policy.",
|
"policy.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(
|
@Scope(key = "policy:view", name = "View policies", description = "")
|
||||||
scope = "policy-view",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/policies/list"}
|
|
||||||
)
|
|
||||||
Response getPolicy(
|
Response getPolicy(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "id",
|
name = "id",
|
||||||
@ -289,12 +283,8 @@ public interface PolicyManagementService {
|
|||||||
message = "Internal Server Error. \n " +
|
message = "Internal Server Error. \n " +
|
||||||
"Server error occurred while updating the policy.",
|
"Server error occurred while updating the policy.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "policy:manage", name = "Add policies", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "policy-modify",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/policies/update"}
|
|
||||||
)
|
|
||||||
Response updatePolicy(
|
Response updatePolicy(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "id",
|
name = "id",
|
||||||
@ -306,7 +296,7 @@ public interface PolicyManagementService {
|
|||||||
name = "policy",
|
name = "policy",
|
||||||
value = "Policy details related to the operation.",
|
value = "Policy details related to the operation.",
|
||||||
required = true)
|
required = true)
|
||||||
PolicyWrapper policy);
|
@Valid PolicyWrapper policy);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/remove-policy")
|
@Path("/remove-policy")
|
||||||
@ -339,12 +329,8 @@ public interface PolicyManagementService {
|
|||||||
message = "Internal Server Error. \n " +
|
message = "Internal Server Error. \n " +
|
||||||
"Server error occurred while bulk removing policies.",
|
"Server error occurred while bulk removing policies.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "policy:manage", name = "Add policies", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "policy-modify",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/policies/remove"}
|
|
||||||
)
|
|
||||||
Response removePolicies(
|
Response removePolicies(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "policyIds",
|
name = "policyIds",
|
||||||
@ -379,13 +365,8 @@ public interface PolicyManagementService {
|
|||||||
code = 500,
|
code = 500,
|
||||||
message = "ErrorResponse in activating policies.",
|
message = "ErrorResponse in activating policies.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "policy:manage", name = "Add policies", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "policy-modify", permissions = {
|
|
||||||
"/permission/admin/device-mgt/admin/policies/update",
|
|
||||||
"/permission/admin/device-mgt/admin/policies/add"}
|
|
||||||
)
|
|
||||||
Response activatePolicies(
|
Response activatePolicies(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "policyIds",
|
name = "policyIds",
|
||||||
@ -420,14 +401,8 @@ public interface PolicyManagementService {
|
|||||||
code = 500,
|
code = 500,
|
||||||
message = "ErrorResponse in deactivating policies.",
|
message = "ErrorResponse in deactivating policies.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "policy:manage", name = "Add policies", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "policy-modify",
|
|
||||||
permissions = {
|
|
||||||
"/permission/admin/device-mgt/admin/policies/update",
|
|
||||||
"/permission/admin/device-mgt/admin/policies/add"}
|
|
||||||
)
|
|
||||||
Response deactivatePolicies(
|
Response deactivatePolicies(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "policyIds",
|
name = "policyIds",
|
||||||
@ -459,12 +434,8 @@ public interface PolicyManagementService {
|
|||||||
code = 500,
|
code = 500,
|
||||||
message = "ErrorResponse in deactivating policies.",
|
message = "ErrorResponse in deactivating policies.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "policy:manage", name = "Add policies", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "policy-modify",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/policies/update"}
|
|
||||||
)
|
|
||||||
Response applyChanges();
|
Response applyChanges();
|
||||||
|
|
||||||
|
|
||||||
@ -492,11 +463,8 @@ public interface PolicyManagementService {
|
|||||||
code = 500,
|
code = 500,
|
||||||
message = "Exception in updating policy priorities.",
|
message = "Exception in updating policy priorities.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
})
|
||||||
)
|
@Scope(key = "policy:manage", name = "Add policies", description = "")
|
||||||
@Permission(
|
|
||||||
scope = "",
|
|
||||||
permissions = {})
|
|
||||||
Response updatePolicyPriorities(
|
Response updatePolicyPriorities(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "priorityUpdatedPolicies",
|
name = "priorityUpdatedPolicies",
|
||||||
|
|||||||
@ -20,18 +20,17 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
|||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
|
||||||
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.Scope;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@API(name = "Role", version = "1.0.0", context = "/devicemgt_admin/roles", tags = {"devicemgt_admin"})
|
@API(name = "Role Management", version = "1.0.0", context = "/api/device-mgt/v1.0/roles", tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
@Path("/roles")
|
@Path("/roles")
|
||||||
@Api(value = "Role Management", description = "Role management related operations can be found here.")
|
@Api(value = "Role Management", description = "Role management related operations can be found here.")
|
||||||
@ -77,11 +76,7 @@ public interface RoleManagementService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while fetching requested list of roles.",
|
message = "Internal Server Error. \n Server error occurred while fetching requested list of roles.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "roles-view", permissions = {
|
@org.wso2.carbon.apimgt.annotations.api.Scope(key = "role:view", name = "View roles", description = "")
|
||||||
"/permission/admin/device-mgt/admin/roles/list",
|
|
||||||
"/permission/admin/device-mgt/admin/users/view",
|
|
||||||
"/permission/admin/device-mgt/admin/policies/add",
|
|
||||||
"/permission/admin/device-mgt/admin/policies/update"})
|
|
||||||
Response getRoles(
|
Response getRoles(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "filter",
|
name = "filter",
|
||||||
@ -110,16 +105,16 @@ public interface RoleManagementService {
|
|||||||
@QueryParam("limit") int limit);
|
@QueryParam("limit") int limit);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{roleName}/permissions")
|
@Path("/scopes")
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
produces = MediaType.APPLICATION_JSON,
|
produces = MediaType.APPLICATION_JSON,
|
||||||
httpMethod = "GET",
|
httpMethod = "GET",
|
||||||
value = "Getting permission details of a role.",
|
value = "Getting authorization scopes.",
|
||||||
notes = "In an organization an individual is associated a with set of responsibilities based on their " +
|
notes = "In an organization an individual is associated a with set of responsibilities based on their " +
|
||||||
"role. In EMM you are able to configure permissions based on the responsibilities carried " +
|
"role. In EMM you are able to configure scopes based on the responsibilities carried " +
|
||||||
"out by a role. Therefore if you wish to retrieve the permission details of a role, you can do " +
|
"out by a role. Therefore if you wish to retrieve the scopes details of roles, you can do " +
|
||||||
"so using this REST API.",
|
"so using this REST API.",
|
||||||
response = UIPermissionNode.class,
|
response = List.class,
|
||||||
responseContainer = "List",
|
responseContainer = "List",
|
||||||
tags = "Role Management"
|
tags = "Role Management"
|
||||||
)
|
)
|
||||||
@ -127,8 +122,8 @@ public interface RoleManagementService {
|
|||||||
value = {
|
value = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 200,
|
code = 200,
|
||||||
message = "OK. \n Successfully fetched the permission list of the given role.",
|
message = "OK. \n Successfully fetched the scopes list.",
|
||||||
response = UIPermissionNode.class,
|
response = List.class,
|
||||||
responseContainer = "List",
|
responseContainer = "List",
|
||||||
responseHeaders = {
|
responseHeaders = {
|
||||||
@ResponseHeader(
|
@ResponseHeader(
|
||||||
@ -163,19 +158,63 @@ public interface RoleManagementService {
|
|||||||
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the permission list of the requested role.",
|
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the permission list of the requested role.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"})
|
@org.wso2.carbon.apimgt.annotations.api.Scope(key = "role:view", name = "View roles", description = "")
|
||||||
Response getPermissionsOfRole(
|
Response getScopes(
|
||||||
@ApiParam(
|
|
||||||
name = "roleName",
|
|
||||||
value = "Name of the role.",
|
|
||||||
required = true)
|
|
||||||
@PathParam("roleName") String roleName,
|
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
value = "Validates if the requested variant has not been modified since the time specified",
|
value = "Validates if the requested variant has not been modified since the time specified",
|
||||||
required = false)
|
required = false)
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince);
|
@HeaderParam("If-Modified-Since") String ifModifiedSince);
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/scopes")
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "PUT",
|
||||||
|
value = "Updating authorization scopes.",
|
||||||
|
notes = "This REST API can be used to update the associated roles of the scopes",
|
||||||
|
tags = "Role Management"
|
||||||
|
)
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Scopes has been updated successfully",
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "Content type of the body"),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "ETag",
|
||||||
|
description = "Entity Tag of the response resource.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Last-Modified",
|
||||||
|
description = "Date and time the resource has been modified the last time.\n" +
|
||||||
|
"Used by caches, or in conditional requests.")}),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 400,
|
||||||
|
message = "Bad Request. \n Invalid request or validation error.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 404,
|
||||||
|
message = "Not Found. \n Scopes to be updated does not exist.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 415,
|
||||||
|
message = "Unsupported media type. \n The entity of the request was in a not supported format.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Server error occurred while updating the scopes.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
@org.wso2.carbon.apimgt.annotations.api.Scope(key = "role:manage", name = "Add roles", description = "")
|
||||||
|
Response updateScopes(
|
||||||
|
@ApiParam(
|
||||||
|
name = "Scopes",
|
||||||
|
value = "List of scopes to be updated",
|
||||||
|
required = true) List<Scope> scopes);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{roleName}")
|
@Path("/{roleName}")
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
@ -226,7 +265,7 @@ public interface RoleManagementService {
|
|||||||
"requested role.",
|
"requested role.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"})
|
@org.wso2.carbon.apimgt.annotations.api.Scope(key = "role:view", name = "View roles", description = "")
|
||||||
Response getRole(
|
Response getRole(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "roleName",
|
name = "roleName",
|
||||||
@ -286,7 +325,7 @@ public interface RoleManagementService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while adding a new role.",
|
message = "Internal Server Error. \n Server error occurred while adding a new role.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/add"})
|
@org.wso2.carbon.apimgt.annotations.api.Scope(key = "role:manage", name = "Add roles", description = "")
|
||||||
Response addRole(
|
Response addRole(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "role",
|
name = "role",
|
||||||
@ -336,7 +375,7 @@ public interface RoleManagementService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while updating the role.",
|
message = "Internal Server Error. \n Server error occurred while updating the role.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/update"})
|
@org.wso2.carbon.apimgt.annotations.api.Scope(key = "role:manage", name = "Add roles", description = "")
|
||||||
Response updateRole(
|
Response updateRole(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "roleName",
|
name = "roleName",
|
||||||
@ -373,13 +412,17 @@ public interface RoleManagementService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while removing the role.",
|
message = "Internal Server Error. \n Server error occurred while removing the role.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/remove"})
|
@org.wso2.carbon.apimgt.annotations.api.Scope(key = "role:manage", name = "Add roles", description = "")
|
||||||
Response deleteRole(
|
Response deleteRole(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "roleName",
|
name = "roleName",
|
||||||
value = "Name of the role to de deleted.",
|
value = "Name of the role to de deleted.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("roleName") String roleName);
|
@PathParam("roleName") String roleName,
|
||||||
|
@ApiParam(
|
||||||
|
name = "role",
|
||||||
|
value = "Details about the role to be added.",
|
||||||
|
required = true) RoleInfo role);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{roleName}/users")
|
@Path("/{roleName}/users")
|
||||||
@ -431,7 +474,7 @@ public interface RoleManagementService {
|
|||||||
"Server error occurred while updating the user list of the role.",
|
"Server error occurred while updating the user list of the role.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/update"})
|
@org.wso2.carbon.apimgt.annotations.api.Scope(key = "role:manage", name = "Add roles", description = "")
|
||||||
Response updateUsersOfRole(
|
Response updateUsersOfRole(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "roleName",
|
name = "roleName",
|
||||||
|
|||||||
@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
|||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.*;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.*;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
@ -29,7 +29,7 @@ import javax.ws.rs.core.Response;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@API(name = "User Management API", version = "1.0.0", context = "/devicemgt_admin/users", tags = {"devicemgt_admin"})
|
@API(name = "User Management", version = "1.0.0", context = "/api/device-mgt/v1.0/users", tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
@Path("/users")
|
@Path("/users")
|
||||||
@Api(value = "User Management", description = "User management related operations can be found here.")
|
@Api(value = "User Management", description = "User management related operations can be found here.")
|
||||||
@ -83,7 +83,7 @@ public interface UserManagementService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while adding a new user.",
|
message = "Internal Server Error. \n Server error occurred while adding a new user.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/add"})
|
@Scope(key = "user:manage", name = "Add users", description = "")
|
||||||
Response addUser(
|
Response addUser(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "user",
|
name = "user",
|
||||||
@ -135,7 +135,7 @@ public interface UserManagementService {
|
|||||||
" fetching the requested user.",
|
" fetching the requested user.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"})
|
@Scope(key = "user:view", name = "View users", description = "")
|
||||||
Response getUser(
|
Response getUser(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "username",
|
name = "username",
|
||||||
@ -192,7 +192,7 @@ public interface UserManagementService {
|
|||||||
"Server error occurred while updating the user.",
|
"Server error occurred while updating the user.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/update"})
|
@Scope(key = "user:manage", name = "Add users", description = "")
|
||||||
Response updateUser(
|
Response updateUser(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "username",
|
name = "username",
|
||||||
@ -227,7 +227,7 @@ public interface UserManagementService {
|
|||||||
response = ErrorResponse.class
|
response = ErrorResponse.class
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/remove"})
|
@Scope(key = "user:manage", name = "Add users", description = "")
|
||||||
Response removeUser(
|
Response removeUser(
|
||||||
@ApiParam(name = "username", value = "Username of the user to be deleted.", required = true)
|
@ApiParam(name = "username", value = "Username of the user to be deleted.", required = true)
|
||||||
@PathParam("username") String username);
|
@PathParam("username") String username);
|
||||||
@ -276,7 +276,7 @@ public interface UserManagementService {
|
|||||||
" assigned to the user.",
|
" assigned to the user.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"})
|
@Scope(key = "user:view", name = "View users", description = "")
|
||||||
Response getRolesOfUser(
|
Response getRolesOfUser(
|
||||||
@ApiParam(name = "username", value = "Username of the user.", required = true)
|
@ApiParam(name = "username", value = "Username of the user.", required = true)
|
||||||
@PathParam("username") String username);
|
@PathParam("username") String username);
|
||||||
@ -319,7 +319,7 @@ public interface UserManagementService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while fetching the user list.",
|
message = "Internal Server Error. \n Server error occurred while fetching the user list.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"})
|
@Scope(key = "user:view", name = "View users", description = "")
|
||||||
Response getUsers(
|
Response getUsers(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "filter",
|
name = "filter",
|
||||||
@ -386,7 +386,7 @@ public interface UserManagementService {
|
|||||||
"list that matches the given filter.",
|
"list that matches the given filter.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"})
|
@Scope(key = "user:view", name = "View users", description = "")
|
||||||
Response getUserNames(
|
Response getUserNames(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "filter",
|
name = "filter",
|
||||||
@ -440,7 +440,7 @@ public interface UserManagementService {
|
|||||||
"Server error occurred while updating credentials of the user.",
|
"Server error occurred while updating credentials of the user.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "user-modify", permissions = {"/permission/admin/login"})
|
@Scope(key = "user:view", name = "View users", description = "")
|
||||||
Response resetPassword(
|
Response resetPassword(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "username",
|
name = "username",
|
||||||
@ -483,7 +483,7 @@ public interface UserManagementService {
|
|||||||
"Server error occurred while updating credentials of the user.",
|
"Server error occurred while updating credentials of the user.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "user-invite", permissions = {"/permission/admin/device-mgt/admin/user/invite"})
|
@Scope(key = "user:manage", name = "Add users", description = "")
|
||||||
Response inviteExistingUsersToEnrollDevice(
|
Response inviteExistingUsersToEnrollDevice(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "users",
|
name = "users",
|
||||||
|
|||||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
|
|||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
@ -31,7 +32,7 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
@API(name = "Application", version = "1.0.0", context = "/devicemgt_admin/applications", tags = {"devicemgt_admin"})
|
@API(name = "Application Management Admin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/applications", tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
@Path("/admin/applications")
|
@Path("/admin/applications")
|
||||||
@Api(value = "Application Management Administrative Service", description = "This an API intended to be used by " +
|
@Api(value = "Application Management Administrative Service", description = "This an API intended to be used by " +
|
||||||
@ -73,6 +74,7 @@ public interface ApplicationManagementAdminService {
|
|||||||
"a given set of devices.",
|
"a given set of devices.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
|
@Scope(key = "application:manage", name = "Install/Uninstall applications", description = "")
|
||||||
Response installApplication(
|
Response installApplication(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "applicationWrapper",
|
name = "applicationWrapper",
|
||||||
@ -111,6 +113,7 @@ public interface ApplicationManagementAdminService {
|
|||||||
"a given set of devices.",
|
"a given set of devices.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
|
@Scope(key = "application:manage", name = "Install/Uninstall applications", description = "")
|
||||||
Response uninstallApplication(
|
Response uninstallApplication(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "applicationWrapper",
|
name = "applicationWrapper",
|
||||||
|
|||||||
@ -20,14 +20,16 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
|
|||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
@API(name = "DeviceManagementAdmin", version = "1.0.0", context = "/devicemgt_admin/applications",
|
@API(name = "Device Management Admin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/devices",
|
||||||
tags = {"devicemgt_admin"})
|
tags = {"devicemgt_admin"})
|
||||||
@Path("/admin/devices")
|
@Path("/admin/devices")
|
||||||
@Api(value = "Device Management Administrative Service", description = "This an API intended to be used by " +
|
@Api(value = "Device Management Administrative Service", description = "This an API intended to be used by " +
|
||||||
@ -83,17 +85,22 @@ public interface DeviceManagementAdminService {
|
|||||||
message = "Internal Server Error. \n Server error occurred while fetching the device list.",
|
message = "Internal Server Error. \n Server error occurred while fetching the device list.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
|
@Scope(key = "device:admin:view", name = "View Devices", description = "")
|
||||||
Response getDevicesByName(
|
Response getDevicesByName(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "name",
|
name = "name",
|
||||||
value = "Name of the device.",
|
value = "Name of the device.",
|
||||||
required = true)
|
required = true)
|
||||||
@QueryParam("name") String name,
|
@QueryParam("name")
|
||||||
|
@Size(max = 45)
|
||||||
|
String name,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "type",
|
name = "type",
|
||||||
value = "Type of the device.",
|
value = "Type of the device.",
|
||||||
required = true)
|
required = true)
|
||||||
@QueryParam("type") String type,
|
@QueryParam("type")
|
||||||
|
@Size(min = 2, max = 45)
|
||||||
|
String type,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "tenant-domain",
|
name = "tenant-domain",
|
||||||
value = "Name of the tenant.",
|
value = "Name of the tenant.",
|
||||||
|
|||||||
@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
|
|||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ import javax.ws.rs.*;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
@API(name = "Device Type Management", version = "1.0.0", context = "/admin/device-types", tags = {"devicemgt_admin"})
|
@API(name = "Device Type Management", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/device-types", tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
@Path("/admin/device-types")
|
@Path("/admin/device-types")
|
||||||
@Api(value = "Device Type Management", description = "This API corresponds to all tasks related to device " +
|
@Api(value = "Device Type Management", description = "This API corresponds to all tasks related to device " +
|
||||||
@ -78,10 +78,7 @@ public interface DeviceTypeManagementService {
|
|||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@Permission(
|
@Scope(key = "device-type:admin:view", name = "View device types", description = "")
|
||||||
scope = "read:device-types",
|
|
||||||
permissions = {"/permission/admin/device-mgt/admin/device-types/view"}
|
|
||||||
)
|
|
||||||
Response getDeviceTypes(
|
Response getDeviceTypes(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
|
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
|
||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
|
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
|
|||||||
@ -19,14 +19,18 @@
|
|||||||
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
|
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
|
||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@API(name = "User Management Admin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/users", tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
@Path("/admin/users")
|
@Path("/admin/users")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ -64,13 +68,15 @@ public interface UserManagementAdminService {
|
|||||||
"Server error occurred while updating credentials of the user.",
|
"Server error occurred while updating credentials of the user.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
@Permission(scope = "user-modify", permissions = {"/permission/admin/login"})
|
@Scope(key = "user:admin:reset-password", name = "View users", description = "")
|
||||||
Response resetUserPassword(
|
Response resetUserPassword(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "username",
|
name = "username",
|
||||||
value = "Username of the user.",
|
value = "Username of the user.",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("username") String username,
|
@PathParam("username")
|
||||||
|
@Size(max = 45)
|
||||||
|
String username,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "credentials",
|
name = "credentials",
|
||||||
value = "Credential.",
|
value = "Credential.",
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import org.wso2.carbon.device.mgt.jaxrs.service.api.ActivityInfoProviderService;
|
|||||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -47,7 +48,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|||||||
@GET
|
@GET
|
||||||
@Override
|
@Override
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
public Response getActivity(@PathParam("id") String id,
|
public Response getActivity(@PathParam("id")
|
||||||
|
@Size(max = 45) String id,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
||||||
Activity activity;
|
Activity activity;
|
||||||
DeviceManagementProviderService dmService;
|
DeviceManagementProviderService dmService;
|
||||||
|
|||||||
@ -26,7 +26,6 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration
|
|||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.ConfigurationManagementService;
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.ConfigurationManagementService;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.MDMAppConstants;
|
import org.wso2.carbon.device.mgt.jaxrs.util.MDMAppConstants;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
|||||||
@ -44,6 +44,7 @@ import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
|||||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -62,12 +63,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@GET
|
@GET
|
||||||
@Override
|
@Override
|
||||||
public Response getDevices(
|
public Response getDevices(
|
||||||
@QueryParam("name") String name,
|
@QueryParam("name") @Size(max = 45) String name,
|
||||||
@QueryParam("type") String type,
|
@QueryParam("type") @Size(max = 45) String type,
|
||||||
@QueryParam("user") String user,
|
@QueryParam("user") @Size(max = 45) String user,
|
||||||
@QueryParam("roleName") String roleName,
|
@QueryParam("roleName") @Size(max = 45) String roleName,
|
||||||
@QueryParam("ownership") String ownership,
|
@QueryParam("ownership") @Size(max = 45) String ownership,
|
||||||
@QueryParam("status") String status,
|
@QueryParam("status") @Size(max = 45) String status,
|
||||||
@QueryParam("since") String since,
|
@QueryParam("since") String since,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||||
@QueryParam("offset") int offset,
|
@QueryParam("offset") int offset,
|
||||||
@ -180,8 +181,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@Path("/{type}/{id}")
|
@Path("/{type}/{id}")
|
||||||
@Override
|
@Override
|
||||||
public Response getDevice(
|
public Response getDevice(
|
||||||
@PathParam("type") String type,
|
@PathParam("type") @Size(max = 45) String type,
|
||||||
@PathParam("id") String id,
|
@PathParam("id") @Size(max = 45) String id,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
||||||
Device device;
|
Device device;
|
||||||
try {
|
try {
|
||||||
@ -207,8 +208,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@Path("/{type}/{id}/features")
|
@Path("/{type}/{id}/features")
|
||||||
@Override
|
@Override
|
||||||
public Response getFeaturesOfDevice(
|
public Response getFeaturesOfDevice(
|
||||||
@PathParam("type") String type,
|
@PathParam("type") @Size(max = 45) String type,
|
||||||
@PathParam("id") String id,
|
@PathParam("id") @Size(max = 45) String id,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
||||||
List<Feature> features;
|
List<Feature> features;
|
||||||
DeviceManagementProviderService dms;
|
DeviceManagementProviderService dms;
|
||||||
@ -258,8 +259,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@Path("/{type}/{id}/applications")
|
@Path("/{type}/{id}/applications")
|
||||||
@Override
|
@Override
|
||||||
public Response getInstalledApplications(
|
public Response getInstalledApplications(
|
||||||
@PathParam("type") String type,
|
@PathParam("type") @Size(max = 45) String type,
|
||||||
@PathParam("id") String id,
|
@PathParam("id") @Size(max = 45) String id,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||||
@QueryParam("offset") int offset,
|
@QueryParam("offset") int offset,
|
||||||
@QueryParam("limit") int limit) {
|
@QueryParam("limit") int limit) {
|
||||||
@ -287,8 +288,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@Path("/{type}/{id}/operations")
|
@Path("/{type}/{id}/operations")
|
||||||
@Override
|
@Override
|
||||||
public Response getDeviceOperations(
|
public Response getDeviceOperations(
|
||||||
@PathParam("type") String type,
|
@PathParam("type") @Size(max = 45) String type,
|
||||||
@PathParam("id") String id,
|
@PathParam("id") @Size(max = 45) String id,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||||
@QueryParam("offset") int offset,
|
@QueryParam("offset") int offset,
|
||||||
@QueryParam("limit") int limit) {
|
@QueryParam("limit") int limit) {
|
||||||
@ -318,8 +319,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@GET
|
@GET
|
||||||
@Path("/{type}/{id}/effective-policy")
|
@Path("/{type}/{id}/effective-policy")
|
||||||
@Override
|
@Override
|
||||||
public Response getEffectivePolicyOfDevice(@PathParam("type") String type,
|
public Response getEffectivePolicyOfDevice(@PathParam("type") @Size(max = 45) String type,
|
||||||
@PathParam("id") String id,
|
@PathParam("id") @Size(max = 45) String id,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
||||||
try {
|
try {
|
||||||
RequestValidationUtil.validateDeviceIdentifier(type, id);
|
RequestValidationUtil.validateDeviceIdentifier(type, id);
|
||||||
@ -339,8 +340,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{type}/{id}/compliance-data")
|
@Path("{type}/{id}/compliance-data")
|
||||||
public Response getComplianceDataOfDevice(@PathParam("type") String type,
|
public Response getComplianceDataOfDevice(@PathParam("type") @Size(max = 45) String type,
|
||||||
@PathParam("id") String id) {
|
@PathParam("id") @Size(max = 45) String id) {
|
||||||
|
|
||||||
RequestValidationUtil.validateDeviceIdentifier(type, id);
|
RequestValidationUtil.validateDeviceIdentifier(type, id);
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
|
|||||||
@ -31,6 +31,8 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
|||||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Max;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -46,7 +48,7 @@ public class NotificationManagementServiceImpl implements NotificationManagement
|
|||||||
@GET
|
@GET
|
||||||
@Override
|
@Override
|
||||||
public Response getNotifications(
|
public Response getNotifications(
|
||||||
@QueryParam("status") String status,
|
@QueryParam("status") @Size(max = 45) String status,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||||
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
|
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
|
||||||
|
|
||||||
@ -79,7 +81,7 @@ public class NotificationManagementServiceImpl implements NotificationManagement
|
|||||||
@PUT
|
@PUT
|
||||||
@Path("/{id}/mark-checked")
|
@Path("/{id}/mark-checked")
|
||||||
public Response updateNotificationStatus(
|
public Response updateNotificationStatus(
|
||||||
@PathParam("id") int id) {
|
@PathParam("id") @Max(45)int id) {
|
||||||
String msg;
|
String msg;
|
||||||
Notification.Status status = Notification.Status.CHECKED;
|
Notification.Status status = Notification.Status.CHECKED;
|
||||||
Notification notification;
|
Notification notification;
|
||||||
|
|||||||
@ -41,6 +41,7 @@ import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
|||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -59,7 +60,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Override
|
@Override
|
||||||
public Response addPolicy(PolicyWrapper policyWrapper) {
|
public Response addPolicy(@Valid PolicyWrapper policyWrapper) {
|
||||||
RequestValidationUtil.validatePolicyDetails(policyWrapper);
|
RequestValidationUtil.validatePolicyDetails(policyWrapper);
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Policy getPolicyFromWrapper(PolicyWrapper policyWrapper) throws DeviceManagementException {
|
private Policy getPolicyFromWrapper(@Valid PolicyWrapper policyWrapper) throws DeviceManagementException {
|
||||||
Policy policy = new Policy();
|
Policy policy = new Policy();
|
||||||
policy.setPolicyName(policyWrapper.getPolicyName());
|
policy.setPolicyName(policyWrapper.getPolicyName());
|
||||||
policy.setDescription(policyWrapper.getDescription());
|
policy.setDescription(policyWrapper.getDescription());
|
||||||
@ -187,7 +188,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
|||||||
@PUT
|
@PUT
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
@Override
|
@Override
|
||||||
public Response updatePolicy(@PathParam("id") int id, PolicyWrapper policyWrapper) {
|
public Response updatePolicy(@PathParam("id") int id, @Valid PolicyWrapper policyWrapper) {
|
||||||
RequestValidationUtil.validatePolicyDetails(policyWrapper);
|
RequestValidationUtil.validatePolicyDetails(policyWrapper);
|
||||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -20,21 +20,23 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|||||||
|
|
||||||
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.device.mgt.common.scope.mgt.ScopeManagementException;
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementService;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.Scope;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.RoleManagementService;
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.RoleManagementService;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer;
|
import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer;
|
||||||
import org.wso2.carbon.user.api.*;
|
import org.wso2.carbon.user.api.AuthorizationManager;
|
||||||
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
||||||
import org.wso2.carbon.user.mgt.UserRealmProxy;
|
|
||||||
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
|
||||||
import org.wso2.carbon.user.mgt.common.UserAdminException;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
@ -88,65 +90,48 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{roleName}/permissions")
|
@Path("/scopes")
|
||||||
@Override
|
@Override
|
||||||
public Response getPermissionsOfRole(
|
public Response getScopes(
|
||||||
@PathParam("roleName") String roleName,
|
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
||||||
RequestValidationUtil.validateRoleName(roleName);
|
|
||||||
|
List<Scope> scopes = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
ScopeManagementService scopeManagementService = DeviceMgtAPIUtils.getScopeManagementService();
|
||||||
if (!userRealm.getUserStoreManager().isExistingRole(roleName)) {
|
if (scopeManagementService == null) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorResponse.ErrorResponseBuilder().setMessage(
|
log.error("Scope management service initialization is failed, hence scopes will not be retrieved");
|
||||||
"No role exists with the name '" + roleName + "'").build()).build();
|
} else {
|
||||||
|
scopes = DeviceMgtUtil.convertAPIScopestoScopes(scopeManagementService.getAllScopes());
|
||||||
}
|
}
|
||||||
|
return Response.status(Response.Status.OK).entity(scopes).build();
|
||||||
final UIPermissionNode rolePermissions = this.getUIPermissionNode(roleName, userRealm);
|
} catch (ScopeManagementException e) {
|
||||||
if (rolePermissions == null) {
|
String msg = "Error occurred while retrieving the scopes";
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("No permissions found for the role '" + roleName + "'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK).entity(rolePermissions).build();
|
|
||||||
} catch (UserAdminException e) {
|
|
||||||
String msg = "Error occurred while retrieving the permissions of role '" + roleName + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.serverError().entity(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
String msg = "Error occurred while retrieving the underlying user realm attached to the " +
|
|
||||||
"current logged in user";
|
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
return Response.serverError().entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private UIPermissionNode getUIPermissionNode(String roleName, UserRealm userRealm)
|
@PUT
|
||||||
throws UserAdminException {
|
@Path("/scopes")
|
||||||
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
@Override
|
||||||
if (userRealm instanceof org.wso2.carbon.user.core.UserRealm) {
|
public Response updateScopes(List<Scope> scopes) {
|
||||||
userRealmCore = (org.wso2.carbon.user.core.UserRealm) userRealm;
|
RequestValidationUtil.validateScopes(scopes);
|
||||||
|
try {
|
||||||
|
ScopeManagementService scopeManagementService = DeviceMgtAPIUtils.getScopeManagementService();
|
||||||
|
if (scopeManagementService == null) {
|
||||||
|
log.error("Scope management service initialization is failed, hence scopes will not be retrieved");
|
||||||
|
} else {
|
||||||
|
scopeManagementService.updateScopes(DeviceMgtUtil.convertScopestoAPIScopes(scopes));
|
||||||
}
|
}
|
||||||
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
return Response.status(Response.Status.OK).entity("Scopes has been successfully updated").build();
|
||||||
final UIPermissionNode rolePermissions =
|
} catch (ScopeManagementException e) {
|
||||||
userRealmProxy.getRolePermissions(roleName, MultitenantConstants.SUPER_TENANT_ID);
|
String msg = "Error occurred while updating the scopes";
|
||||||
UIPermissionNode[] deviceMgtPermissions = new UIPermissionNode[2];
|
log.error(msg, e);
|
||||||
|
return Response.serverError().entity(
|
||||||
for (UIPermissionNode permissionNode : rolePermissions.getNodeList()) {
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
if ("/permission/admin".equals(permissionNode.getResourcePath())) {
|
|
||||||
for (UIPermissionNode node : permissionNode.getNodeList()) {
|
|
||||||
if ("/permission/admin/device-mgt".equals(node.getResourcePath())) {
|
|
||||||
deviceMgtPermissions[0] = node;
|
|
||||||
} else if ("/permission/admin/login".equals(node.getResourcePath())) {
|
|
||||||
deviceMgtPermissions[1] = node;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
rolePermissions.setNodeList(deviceMgtPermissions);
|
|
||||||
return rolePermissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{roleName}")
|
@Path("/{roleName}")
|
||||||
@ -160,7 +145,6 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
RoleInfo roleInfo = new RoleInfo();
|
RoleInfo roleInfo = new RoleInfo();
|
||||||
try {
|
try {
|
||||||
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
|
||||||
if (!userStoreManager.isExistingRole(roleName)) {
|
if (!userStoreManager.isExistingRole(roleName)) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" +
|
new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" +
|
||||||
@ -168,16 +152,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
}
|
}
|
||||||
roleInfo.setRoleName(roleName);
|
roleInfo.setRoleName(roleName);
|
||||||
roleInfo.setUsers(userStoreManager.getUserListOfRole(roleName));
|
roleInfo.setUsers(userStoreManager.getUserListOfRole(roleName));
|
||||||
// Get the permission nodes and hand picking only device management and login perms
|
|
||||||
final UIPermissionNode rolePermissions = this.getUIPermissionNode(roleName, userRealm);
|
|
||||||
List<String> permList = new ArrayList<>();
|
|
||||||
this.iteratePermissions(rolePermissions, permList);
|
|
||||||
roleInfo.setPermissionList(rolePermissions);
|
|
||||||
String[] permListAr = new String[permList.size()];
|
|
||||||
roleInfo.setPermissions(permList.toArray(permListAr));
|
|
||||||
|
|
||||||
return Response.status(Response.Status.OK).entity(roleInfo).build();
|
return Response.status(Response.Status.OK).entity(roleInfo).build();
|
||||||
} catch (UserStoreException | UserAdminException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving the user role '" + roleName + "'";
|
String msg = "Error occurred while retrieving the user role '" + roleName + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
return Response.serverError().entity(
|
||||||
@ -185,35 +162,18 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> iteratePermissions(UIPermissionNode uiPermissionNode, List<String> list) {
|
|
||||||
for (UIPermissionNode permissionNode : uiPermissionNode.getNodeList()) {
|
|
||||||
list.add(permissionNode.getResourcePath());
|
|
||||||
if (permissionNode.getNodeList() != null && permissionNode.getNodeList().length > 0) {
|
|
||||||
iteratePermissions(permissionNode, list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Override
|
@Override
|
||||||
public Response addRole(RoleInfo roleInfo) {
|
public Response addRole(RoleInfo roleInfo) {
|
||||||
RequestValidationUtil.validateRoleDetails(roleInfo);
|
RequestValidationUtil.validateRoleDetails(roleInfo);
|
||||||
RequestValidationUtil.validateRoleName(roleInfo.getRoleName());
|
RequestValidationUtil.validateRoleName(roleInfo.getRoleName());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Persisting the role in the underlying user store");
|
log.debug("Persisting the role in the underlying user store");
|
||||||
}
|
}
|
||||||
Permission[] permissions = null;
|
userStoreManager.addRole(roleInfo.getRoleName(), roleInfo.getUsers(), null);
|
||||||
if (roleInfo.getPermissions() != null && roleInfo.getPermissions().length > 0) {
|
|
||||||
permissions = new Permission[roleInfo.getPermissions().length];
|
|
||||||
for (int i = 0; i < permissions.length; i++) {
|
|
||||||
String permission = roleInfo.getPermissions()[i];
|
|
||||||
permissions[i] = new Permission(permission, CarbonConstants.UI_PERMISSION_ACTION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
userStoreManager.addRole(roleInfo.getRoleName(), roleInfo.getUsers(), permissions);
|
|
||||||
|
|
||||||
//TODO fix what's returned in the entity
|
//TODO fix what's returned in the entity
|
||||||
return Response.created(new URI(API_BASE_PATH + "/" + roleInfo.getRoleName())).entity(
|
return Response.created(new URI(API_BASE_PATH + "/" + roleInfo.getRoleName())).entity(
|
||||||
@ -269,14 +229,12 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
userStoreManager.updateUserListOfRole(newRoleName, usersToDelete, usersToAdd);
|
userStoreManager.updateUserListOfRole(newRoleName, usersToDelete, usersToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (roleInfo.getPermissions() != null) {
|
if (roleInfo.getScopes() != null) {
|
||||||
// Delete all authorizations for the current role before authorizing the permission tree
|
ScopeManagementService scopeManagementService = DeviceMgtAPIUtils.getScopeManagementService();
|
||||||
authorizationManager.clearRoleAuthorization(roleName);
|
if (scopeManagementService == null) {
|
||||||
if (roleInfo.getPermissions().length > 0) {
|
log.error("Scope management service initialization is failed, hence scopes will not be updated");
|
||||||
for (int i = 0; i < roleInfo.getPermissions().length; i++) {
|
} else {
|
||||||
String permission = roleInfo.getPermissions()[i];
|
scopeManagementService.updateScopes(DeviceMgtUtil.convertScopestoAPIScopes(roleInfo.getScopes()));
|
||||||
authorizationManager.authorizeRole(roleName, permission, CarbonConstants.UI_PERMISSION_ACTION);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO: Need to send the updated role information in the entity back to the client
|
//TODO: Need to send the updated role information in the entity back to the client
|
||||||
@ -287,14 +245,21 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
return Response.serverError().entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
|
} catch (ScopeManagementException e) {
|
||||||
|
String msg = "Error occurred while updating scopes of role '" + roleName + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.serverError().entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{roleName}")
|
@Path("/{roleName}")
|
||||||
@Override
|
@Override
|
||||||
public Response deleteRole(@PathParam("roleName") String roleName) {
|
public Response deleteRole(@PathParam("roleName") String roleName, RoleInfo roleInfo) {
|
||||||
RequestValidationUtil.validateRoleName(roleName);
|
RequestValidationUtil.validateRoleName(roleName);
|
||||||
|
RequestValidationUtil.validateScopes(roleInfo.getScopes());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
||||||
final UserStoreManager userStoreManager = userRealm.getUserStoreManager();
|
final UserStoreManager userStoreManager = userRealm.getUserStoreManager();
|
||||||
@ -312,12 +277,25 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
// Delete all authorizations for the current role before deleting
|
// Delete all authorizations for the current role before deleting
|
||||||
authorizationManager.clearRoleAuthorization(roleName);
|
authorizationManager.clearRoleAuthorization(roleName);
|
||||||
|
|
||||||
|
//updating scopes
|
||||||
|
ScopeManagementService scopeManagementService = DeviceMgtAPIUtils.getScopeManagementService();
|
||||||
|
if (scopeManagementService == null) {
|
||||||
|
log.error("Scope management service initialization is failed, hence scopes will not be updated");
|
||||||
|
} else {
|
||||||
|
scopeManagementService.updateScopes(DeviceMgtUtil.convertScopestoAPIScopes(roleInfo.getScopes()));
|
||||||
|
}
|
||||||
|
|
||||||
return Response.status(Response.Status.OK).build();
|
return Response.status(Response.Status.OK).build();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while deleting the role '" + roleName + "'";
|
String msg = "Error occurred while deleting the role '" + roleName + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
return Response.serverError().entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
|
} catch (ScopeManagementException e) {
|
||||||
|
String msg = "Error occurred while updating scopes of role '" + roleName + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.serverError().entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminS
|
|||||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -45,8 +46,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@GET
|
@GET
|
||||||
public Response getDevicesByName(@QueryParam("name") String name,
|
public Response getDevicesByName(@QueryParam("name") @Size(max = 45) String name,
|
||||||
@QueryParam("type") String type,
|
@QueryParam("type") @Size(min = 2, max = 45) String type,
|
||||||
@QueryParam("tenant-domain") String tenantDomain,
|
@QueryParam("tenant-domain") String tenantDomain,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||||
@QueryParam("offset") int offset,
|
@QueryParam("offset") int offset,
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper;
|
|||||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.UserManagementAdminService;
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.UserManagementAdminService;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
|
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -34,7 +35,9 @@ public class UserManagementAdminServiceImpl implements UserManagementAdminServic
|
|||||||
@POST
|
@POST
|
||||||
@Path("/{username}/credentials")
|
@Path("/{username}/credentials")
|
||||||
@Override
|
@Override
|
||||||
public Response resetUserPassword(@PathParam("username") String user, PasswordResetWrapper credentials) {
|
public Response resetUserPassword(@PathParam("username")
|
||||||
|
@Size(max = 45)
|
||||||
|
String user, PasswordResetWrapper credentials) {
|
||||||
return CredentialManagementResponseBuilder.buildResetPasswordResponse(user, credentials);
|
return CredentialManagementResponseBuilder.buildResetPasswordResponse(user, credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,11 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.jaxrs.service.impl.util;
|
package org.wso2.carbon.device.mgt.jaxrs.service.impl.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.Scope;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.*;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -313,6 +314,14 @@ public class RequestValidationUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void validateScopes(List<Scope> scopes) {
|
||||||
|
if (scopes == null || scopes.isEmpty()) {
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Scope details of the request body" +
|
||||||
|
" is incorrect or empty").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void validatePaginationParameters(int offset, int limit) {
|
public static void validatePaginationParameters(int offset, int limit) {
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
throw new InputValidationException(
|
throw new InputValidationException(
|
||||||
@ -324,6 +333,12 @@ public class RequestValidationUtil {
|
|||||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request parameter limit is a " +
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request parameter limit is a " +
|
||||||
"negative value.").build());
|
"negative value.").build());
|
||||||
}
|
}
|
||||||
|
if (limit - offset > 100) {
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request results list should" +
|
||||||
|
" be less than or equal 100 values.").build());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@SwaggerDefinition(
|
@SwaggerDefinition(
|
||||||
basePath = "/api/device-mgt/v1.0",
|
basePath = "/api-device-mgt-v1.0",
|
||||||
host = "localhost:9443"
|
host = "localhost:9443"
|
||||||
)
|
)
|
||||||
public class SecurityDefinitionConfigurator implements ReaderListener {
|
public class SecurityDefinitionConfigurator implements ReaderListener {
|
||||||
|
|||||||
@ -27,4 +27,18 @@ public class Constants {
|
|||||||
public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname";
|
public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname";
|
||||||
public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname";
|
public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname";
|
||||||
|
|
||||||
|
public final class ErrorMessages {
|
||||||
|
private ErrorMessages () { throw new AssertionError(); }
|
||||||
|
|
||||||
|
public static final String STATUS_BAD_REQUEST_MESSAGE_DEFAULT = "Bad Request";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class DeviceConstants {
|
||||||
|
private DeviceConstants () { throw new AssertionError(); }
|
||||||
|
|
||||||
|
public static final String APPLICATION_JSON = "application/json";
|
||||||
|
public static final String HEADER_CONTENT_TYPE = "Content-Type";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
|||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
||||||
@ -248,6 +249,16 @@ public class DeviceMgtAPIUtils {
|
|||||||
return gadgetDataService;
|
return gadgetDataService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ScopeManagementService getScopeManagementService() {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
ScopeManagementService scopeManagementService =
|
||||||
|
(ScopeManagementService) ctx.getOSGiService(ScopeManagementService.class, null);
|
||||||
|
if (scopeManagementService == null) {
|
||||||
|
throw new IllegalStateException("Scope Management Service has not been initialized.");
|
||||||
|
}
|
||||||
|
return scopeManagementService;
|
||||||
|
}
|
||||||
|
|
||||||
public static int getTenantId(String tenantDomain) throws DeviceManagementException {
|
public static int getTenantId(String tenantDomain) throws DeviceManagementException {
|
||||||
RealmService realmService =
|
RealmService realmService =
|
||||||
(RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(RealmService.class, null);
|
(RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(RealmService.class, null);
|
||||||
|
|||||||
@ -18,11 +18,17 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.jaxrs.util;
|
package org.wso2.carbon.device.mgt.jaxrs.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.apimgt.api.model.Scope;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorListItem;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ProfileFeature;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ProfileFeature;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException;
|
||||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class DeviceMgtUtil {
|
public class DeviceMgtUtil {
|
||||||
|
|
||||||
@ -58,4 +64,77 @@ public class DeviceMgtUtil {
|
|||||||
return profileFeature;
|
return profileFeature;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Scope> convertScopestoAPIScopes(List<org.wso2.carbon.device.mgt.jaxrs.beans.Scope> scopes) {
|
||||||
|
List<Scope> convertedScopes = new ArrayList<>();
|
||||||
|
Scope convertedScope;
|
||||||
|
for (org.wso2.carbon.device.mgt.jaxrs.beans.Scope scope : scopes) {
|
||||||
|
convertedScope = new Scope();
|
||||||
|
convertedScope.setKey(scope.getKey());
|
||||||
|
convertedScope.setName(scope.getName());
|
||||||
|
convertedScope.setDescription(scope.getDescription());
|
||||||
|
convertedScope.setRoles(scope.getRoles());
|
||||||
|
convertedScopes.add(convertedScope);
|
||||||
|
}
|
||||||
|
return convertedScopes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<org.wso2.carbon.device.mgt.jaxrs.beans.Scope> convertAPIScopestoScopes(List<Scope> scopes) {
|
||||||
|
List<org.wso2.carbon.device.mgt.jaxrs.beans.Scope> convertedScopes = new ArrayList<>();
|
||||||
|
org.wso2.carbon.device.mgt.jaxrs.beans.Scope convertedScope;
|
||||||
|
for (Scope scope : scopes) {
|
||||||
|
convertedScope = new org.wso2.carbon.device.mgt.jaxrs.beans.Scope();
|
||||||
|
convertedScope.setKey(scope.getKey());
|
||||||
|
convertedScope.setName(scope.getName());
|
||||||
|
convertedScope.setDescription(scope.getDescription());
|
||||||
|
convertedScope.setRoles(scope.getRoles());
|
||||||
|
convertedScopes.add(convertedScope);
|
||||||
|
}
|
||||||
|
return convertedScopes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new BadRequestException
|
||||||
|
*
|
||||||
|
* @param description description of the exception
|
||||||
|
* @return a new BadRequestException with the specified details as a response DTO
|
||||||
|
*/
|
||||||
|
public static BadRequestException buildBadRequestException(String description) {
|
||||||
|
ErrorResponse errorResponse = getErrorResponse(Constants.
|
||||||
|
ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT,400l, description);
|
||||||
|
return new BadRequestException(errorResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns generic ErrorResponse.
|
||||||
|
* @param message specific error message
|
||||||
|
* @param code
|
||||||
|
* @param description
|
||||||
|
* @return generic Response with error specific details.
|
||||||
|
*/
|
||||||
|
public static ErrorResponse getErrorResponse(String message, Long code, String description) {
|
||||||
|
ErrorResponse errorResponse = new ErrorResponse();
|
||||||
|
errorResponse.setCode(code);
|
||||||
|
errorResponse.setMoreInfo("");
|
||||||
|
errorResponse.setMessage(message);
|
||||||
|
errorResponse.setDescription(description);
|
||||||
|
return errorResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ErrorResponse getConstraintViolationErrorDTO(Set<ConstraintViolation<T>> violations) {
|
||||||
|
ErrorResponse errorResponse = new ErrorResponse();
|
||||||
|
errorResponse.setDescription("Validation Error");
|
||||||
|
errorResponse.setMessage("Bad Request");
|
||||||
|
errorResponse.setCode(400l);
|
||||||
|
errorResponse.setMoreInfo("");
|
||||||
|
List<ErrorListItem> errorListItems = new ArrayList<>();
|
||||||
|
for (ConstraintViolation violation : violations) {
|
||||||
|
ErrorListItem errorListItemDTO = new ErrorListItem();
|
||||||
|
errorListItemDTO.setCode(400 + "_" + violation.getPropertyPath());
|
||||||
|
errorListItemDTO.setMessage(violation.getPropertyPath() + ": " + violation.getMessage());
|
||||||
|
errorListItems.add(errorListItemDTO);
|
||||||
|
}
|
||||||
|
errorResponse.setErrorItems(errorListItems);
|
||||||
|
return errorResponse;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -68,6 +68,12 @@
|
|||||||
<url>/devices/*/*</url>
|
<url>/devices/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
<Permission>
|
||||||
|
<name>View device info</name>
|
||||||
|
<path>/device-mgt/admin/devices/View</path>
|
||||||
|
<url>/devices/*/*/info</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View device applications</name>
|
<name>View device applications</name>
|
||||||
<path>/device-mgt/admin/devices/View-Applications</path>
|
<path>/device-mgt/admin/devices/View-Applications</path>
|
||||||
|
|||||||
@ -17,12 +17,11 @@
|
|||||||
~ under the License.
|
~ under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="http://www.springframework.org/schema/beans"
|
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
|
||||||
xsi:schemaLocation="
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
|
||||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
|
||||||
|
|
||||||
<jaxrs:server id="services" address="/">
|
<jaxrs:server id="services" address="/">
|
||||||
<jaxrs:serviceBeans>
|
<jaxrs:serviceBeans>
|
||||||
@ -51,6 +50,8 @@
|
|||||||
|
|
||||||
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
|
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
|
||||||
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
|
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
|
||||||
|
<bean id="ValidationInterceptor" class="org.wso2.carbon.device.mgt.jaxrs.exception.ValidationInterceptor"/>
|
||||||
|
<bean id="GlobalExceptionMapper" class="org.wso2.carbon.device.mgt.jaxrs.exception.GlobalThrowableMapper"/>
|
||||||
|
|
||||||
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
|
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
|
||||||
<property name="resourcePackage" value="org.wso2.carbon.device.mgt.jaxrs"/>
|
<property name="resourcePackage" value="org.wso2.carbon.device.mgt.jaxrs"/>
|
||||||
@ -80,6 +81,12 @@
|
|||||||
<bean id="dashboardServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DashboardImpl"/>
|
<bean id="dashboardServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DashboardImpl"/>
|
||||||
<bean id="deviceTypeManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceTypeManagementServiceImpl"/>
|
<bean id="deviceTypeManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceTypeManagementServiceImpl"/>
|
||||||
<bean id="jsonProvider" class="org.wso2.carbon.device.mgt.jaxrs.common.GsonMessageBodyHandler"/>
|
<bean id="jsonProvider" class="org.wso2.carbon.device.mgt.jaxrs.common.GsonMessageBodyHandler"/>
|
||||||
|
|
||||||
<!--<bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.common.ErrorHandler"/>-->
|
<!--<bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.common.ErrorHandler"/>-->
|
||||||
|
<cxf:bus>
|
||||||
|
<cxf:inInterceptors>
|
||||||
|
<ref bean="ValidationInterceptor"/>
|
||||||
|
</cxf:inInterceptors>
|
||||||
|
</cxf:bus>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|||||||
@ -50,6 +50,7 @@
|
|||||||
<Import-Package>
|
<Import-Package>
|
||||||
javax.xml.bind.annotation,
|
javax.xml.bind.annotation,
|
||||||
com.fasterxml.jackson.annotation,
|
com.fasterxml.jackson.annotation,
|
||||||
|
org.wso2.carbon.apimgt.api.model,
|
||||||
io.swagger.annotations.*;resolution:=optional
|
io.swagger.annotations.*;resolution:=optional
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
</instructions>
|
</instructions>
|
||||||
@ -68,6 +69,10 @@
|
|||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-annotations</artifactId>
|
<artifactId>jackson-annotations</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.apimgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.apimgt.api</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -24,47 +24,25 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||||||
/**
|
/**
|
||||||
* This class represents the information related to permission.
|
* This class represents the information related to permission.
|
||||||
*/
|
*/
|
||||||
@XmlRootElement (name = "Permission")
|
|
||||||
public class Permission {
|
public class Permission {
|
||||||
|
|
||||||
private String name; // permission name
|
|
||||||
private String path; // permission string
|
|
||||||
private String url; // url of the resource
|
private String url; // url of the resource
|
||||||
|
private String urlTemplate; // resource template
|
||||||
private String method; // http method
|
private String method; // http method
|
||||||
private String scope; //scope of the resource
|
private String context;
|
||||||
|
|
||||||
public String getName() {
|
public String getContext() {
|
||||||
return name;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement (name = "name", required = true)
|
public void setContext(String context) {
|
||||||
public void setName(String name) {
|
this.context = context;
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement (name = "path", required = true)
|
|
||||||
public void setPath(String path) {
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getScope() {
|
|
||||||
return scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement(name = "scope", required = false)
|
|
||||||
public void setScope(String scope) {
|
|
||||||
this.scope = scope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement (name = "url", required = true)
|
|
||||||
public void setUrl(String url) {
|
public void setUrl(String url) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
@ -73,8 +51,15 @@ public class Permission {
|
|||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement (name = "method", required = true)
|
|
||||||
public void setMethod(String method) {
|
public void setMethod(String method) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUrlTemplate() {
|
||||||
|
return urlTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrlTemplate(String urlTemplate) {
|
||||||
|
this.urlTemplate = urlTemplate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,11 +29,10 @@ public interface PermissionManagerService {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param permission - Permission to be added
|
* @param permission - Permission to be added
|
||||||
* @return The status of the operation.
|
|
||||||
* @throws PermissionManagementException If some unusual behaviour is observed while adding the
|
* @throws PermissionManagementException If some unusual behaviour is observed while adding the
|
||||||
* permission.
|
* permission.
|
||||||
*/
|
*/
|
||||||
boolean addPermission(Permission permission) throws PermissionManagementException;
|
void addPermission(Permission permission) throws PermissionManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.common.scope.mgt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This exception is used to throw when there is an issue in scope management service.
|
||||||
|
*/
|
||||||
|
public class ScopeManagementException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -315127931137779899L;
|
||||||
|
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScopeManagementException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScopeManagementException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
setErrorMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScopeManagementException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScopeManagementException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScopeManagementException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.common.scope.mgt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.wso2.carbon.apimgt.api.model.Scope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface contains the basic operations related to scope management.
|
||||||
|
*/
|
||||||
|
public interface ScopeManagementService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to update the given list of scopes.
|
||||||
|
*
|
||||||
|
* @param scopes List of scopes to be updated.
|
||||||
|
* @throws ScopeManagementException
|
||||||
|
*/
|
||||||
|
void updateScopes(List<Scope> scopes) throws ScopeManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to retrieve all the scopes.
|
||||||
|
*
|
||||||
|
* @return List of scopes.
|
||||||
|
* @throws ScopeManagementException
|
||||||
|
*/
|
||||||
|
List<Scope> getAllScopes() throws ScopeManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is to retrieve the roles of the given scope
|
||||||
|
* @param scopeKey key of the scope
|
||||||
|
* @return List of roles
|
||||||
|
* @throws ScopeManagementException
|
||||||
|
*/
|
||||||
|
String getRolesOfScope(String scopeKey) throws ScopeManagementException;
|
||||||
|
|
||||||
|
}
|
||||||
@ -91,6 +91,10 @@
|
|||||||
!org.wso2.carbon.device.mgt.core.internal,
|
!org.wso2.carbon.device.mgt.core.internal,
|
||||||
org.wso2.carbon.device.mgt.core.*
|
org.wso2.carbon.device.mgt.core.*
|
||||||
</Export-Package>
|
</Export-Package>
|
||||||
|
<Embed-Dependency>
|
||||||
|
javax.ws.rs-api,
|
||||||
|
scribe;scope=compile|runtime;inline=false;
|
||||||
|
</Embed-Dependency>
|
||||||
<DynamicImport-Package>*</DynamicImport-Package>
|
<DynamicImport-Package>*</DynamicImport-Package>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -228,6 +232,7 @@
|
|||||||
<groupId>commons-collections.wso2</groupId>
|
<groupId>commons-collections.wso2</groupId>
|
||||||
<artifactId>commons-collections</artifactId>
|
<artifactId>commons-collections</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.email.sender.core</artifactId>
|
<artifactId>org.wso2.carbon.email.sender.core</artifactId>
|
||||||
@ -236,15 +241,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>5.1.34</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
<version>1.7.1</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -253,6 +255,26 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.orbit.org.scannotation</groupId>
|
||||||
|
<artifactId>scannotation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>jsr311-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|||||||
throws DeviceAccessAuthorizationException {
|
throws DeviceAccessAuthorizationException {
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
if (username == null || username.isEmpty()) {
|
if (username == null || username.isEmpty()) {
|
||||||
return false;
|
return !DeviceManagementDataHolder.getInstance().requireDeviceAuthorization(deviceIdentifier.getType());
|
||||||
}
|
}
|
||||||
//check for admin and ownership permissions
|
//check for admin and ownership permissions
|
||||||
if (isAdminOrDeviceOwner(username, tenantId, deviceIdentifier)) {
|
if (isAdminOrDeviceOwner(username, tenantId, deviceIdentifier)) {
|
||||||
@ -243,9 +243,7 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean addAdminPermissionToRegistry() throws PermissionManagementException {
|
private boolean addAdminPermissionToRegistry() throws PermissionManagementException {
|
||||||
Permission permission = new Permission();
|
return PermissionUtils.putPermission(PermissionUtils.getAbsolutePermissionPath(CDM_ADMIN_PERMISSION));
|
||||||
permission.setPath(PermissionUtils.getAbsolutePermissionPath(CDM_ADMIN_PERMISSION));
|
|
||||||
return PermissionUtils.putPermission(permission);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> getOwnershipOfDevices(List<Device> devices) {
|
private Map<String, String> getOwnershipOfDevices(List<Device> devices) {
|
||||||
|
|||||||
@ -0,0 +1,332 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.config.permission;
|
||||||
|
|
||||||
|
import org.apache.catalina.core.StandardContext;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.scannotation.AnnotationDB;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
public class AnnotationProcessor {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(AnnotationProcessor.class);
|
||||||
|
|
||||||
|
private static final String PACKAGE_ORG_APACHE = "org.apache";
|
||||||
|
private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus";
|
||||||
|
private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework";
|
||||||
|
private static final String WILD_CARD = "/*";
|
||||||
|
private static final String URL_SEPARATOR = "/";
|
||||||
|
|
||||||
|
private static final String STRING_ARR = "string_arr";
|
||||||
|
private static final String STRING = "string";
|
||||||
|
|
||||||
|
private Method[] pathClazzMethods;
|
||||||
|
private Class<Path> pathClazz;
|
||||||
|
Class<API> apiClazz;
|
||||||
|
private ClassLoader classLoader;
|
||||||
|
private ServletContext servletContext;
|
||||||
|
|
||||||
|
|
||||||
|
public AnnotationProcessor(final StandardContext context) {
|
||||||
|
servletContext = context.getServletContext();
|
||||||
|
classLoader = servletContext.getClassLoader();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scan the context for classes with annotations
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public Set<String> scanStandardContext(String className) throws IOException {
|
||||||
|
ExtendedAnnotationDB db = new ExtendedAnnotationDB();
|
||||||
|
db.addIgnoredPackages(PACKAGE_ORG_APACHE);
|
||||||
|
db.addIgnoredPackages(PACKAGE_ORG_CODEHAUS);
|
||||||
|
db.addIgnoredPackages(PACKAGE_ORG_SPRINGFRAMEWORK);
|
||||||
|
URL classPath = findWebInfClassesPath(servletContext);
|
||||||
|
db.scanArchives(classPath);
|
||||||
|
|
||||||
|
//Returns a list of classes with given Annotation
|
||||||
|
return db.getAnnotationIndex().get(className);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method identifies the URL templates and context by reading the annotations of a class
|
||||||
|
*
|
||||||
|
* @param entityClasses
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission>
|
||||||
|
extractPermissions(Set<String> entityClasses) {
|
||||||
|
|
||||||
|
List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> permissions = new ArrayList<>();
|
||||||
|
|
||||||
|
if (entityClasses != null && !entityClasses.isEmpty()) {
|
||||||
|
|
||||||
|
for (final String className : entityClasses) {
|
||||||
|
|
||||||
|
List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> resourcePermissions =
|
||||||
|
AccessController.doPrivileged(new PrivilegedAction<List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission>>() {
|
||||||
|
public List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> run() {
|
||||||
|
Class<?> clazz;
|
||||||
|
List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> apiPermissions =
|
||||||
|
new ArrayList<>();
|
||||||
|
try {
|
||||||
|
clazz = classLoader.loadClass(className);
|
||||||
|
|
||||||
|
apiClazz = (Class<API>)
|
||||||
|
classLoader.loadClass(org.wso2.carbon.apimgt.annotations.api.API
|
||||||
|
.class.getName());
|
||||||
|
|
||||||
|
Annotation apiAnno = clazz.getAnnotation(apiClazz);
|
||||||
|
List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> resourceList;
|
||||||
|
|
||||||
|
if (apiAnno != null) {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Application Context root = " + servletContext.getContextPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String rootContext = servletContext.getContextPath();
|
||||||
|
pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
|
||||||
|
pathClazzMethods = pathClazz.getMethods();
|
||||||
|
|
||||||
|
Annotation rootContectAnno = clazz.getAnnotation(pathClazz);
|
||||||
|
String subContext = "";
|
||||||
|
if (rootContectAnno != null) {
|
||||||
|
subContext = invokeMethod(pathClazzMethods[0], rootContectAnno, STRING);
|
||||||
|
if (subContext != null && !subContext.isEmpty()) {
|
||||||
|
if (subContext.trim().startsWith("/")) {
|
||||||
|
rootContext = rootContext + subContext;
|
||||||
|
} else {
|
||||||
|
rootContext = rootContext + "/" + subContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("API Root Context = " + rootContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Method[] annotatedMethods = clazz.getDeclaredMethods();
|
||||||
|
apiPermissions = getApiResources(rootContext, annotatedMethods);
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
log.error("Error encountered while scanning for annotations", throwable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
log.error("Error when passing the api annotation for device type apis.");
|
||||||
|
}
|
||||||
|
return apiPermissions;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
permissions.addAll(resourcePermissions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Resources for each API
|
||||||
|
*
|
||||||
|
* @param resourceRootContext
|
||||||
|
* @param annotatedMethods
|
||||||
|
* @return
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
private List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission>
|
||||||
|
getApiResources(String resourceRootContext, Method[] annotatedMethods) throws Throwable {
|
||||||
|
|
||||||
|
List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> permissions = new ArrayList<>();
|
||||||
|
String subCtx;
|
||||||
|
for (Method method : annotatedMethods) {
|
||||||
|
Annotation[] annotations = method.getDeclaredAnnotations();
|
||||||
|
org.wso2.carbon.device.mgt.common.permission.mgt.Permission permission =
|
||||||
|
new org.wso2.carbon.device.mgt.common.permission.mgt.Permission();
|
||||||
|
|
||||||
|
if (isHttpMethodAvailable(annotations)) {
|
||||||
|
Annotation methodContextAnno = method.getAnnotation(pathClazz);
|
||||||
|
if (methodContextAnno != null) {
|
||||||
|
subCtx = invokeMethod(pathClazzMethods[0], methodContextAnno, STRING);
|
||||||
|
} else {
|
||||||
|
subCtx = WILD_CARD;
|
||||||
|
}
|
||||||
|
permission.setContext(makeContextURLReady(resourceRootContext));
|
||||||
|
permission.setUrlTemplate(makeContextURLReady(subCtx));
|
||||||
|
|
||||||
|
// this check is added to avoid url resolving conflict which happens due
|
||||||
|
// to adding of '*' notation for dynamic path variables.
|
||||||
|
if (WILD_CARD.equals(subCtx)) {
|
||||||
|
subCtx = makeContextURLReady(resourceRootContext);
|
||||||
|
} else {
|
||||||
|
subCtx = makeContextURLReady(resourceRootContext) + makeContextURLReady(subCtx);
|
||||||
|
}
|
||||||
|
permission.setUrl(replaceDynamicPathVariables(subCtx));
|
||||||
|
String httpMethod;
|
||||||
|
for (int i = 0; i < annotations.length; i++) {
|
||||||
|
httpMethod = getHTTPMethodAnnotation(annotations[i]);
|
||||||
|
if (httpMethod != null) {
|
||||||
|
permission.setMethod(httpMethod);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
permissions.add(permission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read Method annotations indicating HTTP Methods
|
||||||
|
* @param annotation
|
||||||
|
*/
|
||||||
|
private String getHTTPMethodAnnotation(Annotation annotation) {
|
||||||
|
if (annotation.annotationType().getName().equals(GET.class.getName())) {
|
||||||
|
return HttpMethod.GET;
|
||||||
|
} else if (annotation.annotationType().getName().equals(POST.class.getName())) {
|
||||||
|
return HttpMethod.POST;
|
||||||
|
} else if (annotation.annotationType().getName().equals(OPTIONS.class.getName())) {
|
||||||
|
return HttpMethod.OPTIONS;
|
||||||
|
} else if (annotation.annotationType().getName().equals(DELETE.class.getName())) {
|
||||||
|
return HttpMethod.DELETE;
|
||||||
|
} else if (annotation.annotationType().getName().equals(PUT.class.getName())) {
|
||||||
|
return HttpMethod.PUT;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isHttpMethodAvailable(Annotation[] annotations) {
|
||||||
|
for (Annotation annotation : annotations) {
|
||||||
|
if (annotation.annotationType().getName().equals(GET.class.getName())) {
|
||||||
|
return true;
|
||||||
|
} else if (annotation.annotationType().getName().equals(POST.class.getName())) {
|
||||||
|
return true;
|
||||||
|
} else if (annotation.annotationType().getName().equals(OPTIONS.class.getName())) {
|
||||||
|
return true;
|
||||||
|
} else if (annotation.annotationType().getName().equals(DELETE.class.getName())) {
|
||||||
|
return true;
|
||||||
|
} else if (annotation.annotationType().getName().equals(PUT.class.getName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append '/' to the context and make it URL ready
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String makeContextURLReady(String context) {
|
||||||
|
if (context != null && ! context.isEmpty()) {
|
||||||
|
if (context.startsWith("/")) {
|
||||||
|
return context;
|
||||||
|
} else {
|
||||||
|
return "/" + context;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When an annotation and method is passed, this method invokes that executes said method against the annotation
|
||||||
|
*
|
||||||
|
* @param method
|
||||||
|
* @param annotation
|
||||||
|
* @param returnType
|
||||||
|
* @return
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
private String invokeMethod(Method method, Annotation annotation, String returnType) throws Throwable {
|
||||||
|
InvocationHandler methodHandler = Proxy.getInvocationHandler(annotation);
|
||||||
|
switch (returnType) {
|
||||||
|
case STRING:
|
||||||
|
return (String) methodHandler.invoke(annotation, method, null);
|
||||||
|
case STRING_ARR:
|
||||||
|
return ((String[]) methodHandler.invoke(annotation, method, null))[0];
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory
|
||||||
|
* if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
|
||||||
|
*
|
||||||
|
* @param servletContext
|
||||||
|
* @return null if cannot determin /WEB-INF/classes
|
||||||
|
*/
|
||||||
|
public static URL findWebInfClassesPath(ServletContext servletContext)
|
||||||
|
{
|
||||||
|
String path = servletContext.getRealPath("/WEB-INF/classes");
|
||||||
|
if (path == null) return null;
|
||||||
|
File fp = new File(path);
|
||||||
|
if (fp.exists() == false) return null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
URI uri = fp.toURI();
|
||||||
|
return uri.toURL();
|
||||||
|
}
|
||||||
|
catch (MalformedURLException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String replaceDynamicPathVariables(String path) {
|
||||||
|
StringBuilder replacedPath = new StringBuilder();
|
||||||
|
StringTokenizer st = new StringTokenizer(path, URL_SEPARATOR);
|
||||||
|
String currentToken;
|
||||||
|
while (st.hasMoreTokens()) {
|
||||||
|
currentToken = st.nextToken();
|
||||||
|
if (currentToken.charAt(0) == '{') {
|
||||||
|
if (currentToken.charAt(currentToken.length() - 1) == '}') {
|
||||||
|
replacedPath.append(WILD_CARD);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
replacedPath.append(URL_SEPARATOR);
|
||||||
|
replacedPath.append(currentToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return replacedPath.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core.config.permission;
|
||||||
|
|
||||||
|
import org.scannotation.AnnotationDB;
|
||||||
|
import org.scannotation.archiveiterator.Filter;
|
||||||
|
import org.scannotation.archiveiterator.StreamIterator;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class ExtendedAnnotationDB extends AnnotationDB {
|
||||||
|
|
||||||
|
public ExtendedAnnotationDB() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void scanArchives(URL... urls) throws IOException {
|
||||||
|
URL[] arr$ = urls;
|
||||||
|
int len$ = urls.length;
|
||||||
|
|
||||||
|
for(int i$ = 0; i$ < len$; ++i$) {
|
||||||
|
URL url = arr$[i$];
|
||||||
|
Filter filter = new Filter() {
|
||||||
|
public boolean accepts(String filename) {
|
||||||
|
if(filename.endsWith(".class")) {
|
||||||
|
if(filename.startsWith("/") || filename.startsWith("\\")) {
|
||||||
|
filename = filename.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!ExtendedAnnotationDB.this.ignoreScan(filename.replace('/', '.'))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
StreamIterator it = ExtendedIteratorFactory.create(url, filter);
|
||||||
|
|
||||||
|
InputStream stream;
|
||||||
|
while((stream = it.next()) != null) {
|
||||||
|
this.scanClass(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean ignoreScan(String intf) {
|
||||||
|
String[] arr$;
|
||||||
|
int len$;
|
||||||
|
int i$;
|
||||||
|
String ignored;
|
||||||
|
if(this.scanPackages != null) {
|
||||||
|
arr$ = this.scanPackages;
|
||||||
|
len$ = arr$.length;
|
||||||
|
|
||||||
|
for(i$ = 0; i$ < len$; ++i$) {
|
||||||
|
ignored = arr$[i$];
|
||||||
|
if(intf.startsWith(ignored + ".")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
arr$ = this.ignoredPackages;
|
||||||
|
len$ = arr$.length;
|
||||||
|
|
||||||
|
for(i$ = 0; i$ < len$; ++i$) {
|
||||||
|
ignored = arr$[i$];
|
||||||
|
if(intf.startsWith(ignored + ".")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core.config.permission;
|
||||||
|
|
||||||
|
import org.scannotation.archiveiterator.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class ExtendedFileProtocolIteratorFactory implements DirectoryIteratorFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StreamIterator create(URL url, Filter filter) throws IOException {
|
||||||
|
File f = new File(java.net.URLDecoder.decode(url.getPath(), "UTF-8"));
|
||||||
|
return f.isDirectory()?new FileIterator(f, filter):new JarIterator(url.openStream(), filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core.config.permission;
|
||||||
|
|
||||||
|
import org.scannotation.archiveiterator.DirectoryIteratorFactory;
|
||||||
|
import org.scannotation.archiveiterator.Filter;
|
||||||
|
import org.scannotation.archiveiterator.JarIterator;
|
||||||
|
import org.scannotation.archiveiterator.StreamIterator;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class ExtendedIteratorFactory {
|
||||||
|
|
||||||
|
private static final ConcurrentHashMap<String, DirectoryIteratorFactory> registry = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
public static StreamIterator create(URL url, Filter filter) throws IOException {
|
||||||
|
String urlString = url.toString();
|
||||||
|
if(urlString.endsWith("!/")) {
|
||||||
|
urlString = urlString.substring(4);
|
||||||
|
urlString = urlString.substring(0, urlString.length() - 2);
|
||||||
|
url = new URL(urlString);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!urlString.endsWith("/")) {
|
||||||
|
return new JarIterator(url.openStream(), filter);
|
||||||
|
} else {
|
||||||
|
DirectoryIteratorFactory factory = registry.get(url.getProtocol());
|
||||||
|
if(factory == null) {
|
||||||
|
throw new IOException("Unable to scan directory of protocol: " + url.getProtocol());
|
||||||
|
} else {
|
||||||
|
return factory.create(url, filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
registry.put("file", new ExtendedFileProtocolIteratorFactory());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,29 +25,27 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the information related to permission configuration.
|
* This class represents the information related to permissions.
|
||||||
*/
|
*/
|
||||||
@XmlRootElement (name = "PermissionConfiguration")
|
|
||||||
public class PermissionConfiguration {
|
public class PermissionConfiguration {
|
||||||
|
|
||||||
private List<Permission> permissions;
|
private String scopeName;
|
||||||
private String apiVersion;
|
private String[] permissions;
|
||||||
|
|
||||||
public String getApiVersion() {
|
public String getScopeName() {
|
||||||
return apiVersion;
|
return scopeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement (name = "APIVersion", required = true)
|
public void setScopeName(String scope) {
|
||||||
public void setApiVersion(String apiVersion) {
|
this.scopeName = scope;
|
||||||
this.apiVersion = apiVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Permission> getPermissions() {
|
public String[] getPermissions() {
|
||||||
return permissions;
|
return permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement (name = "Permission", required = true)
|
public void setPermissions(String[] permissions) {
|
||||||
public void setPermissions(List<Permission> permissions) {
|
|
||||||
this.permissions = permissions;
|
this.permissions = permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,8 @@ 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.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.common.permission.mgt.PermissionManagerService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.permission.AnnotationProcessor;
|
||||||
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 org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils;
|
||||||
@ -35,8 +37,10 @@ import javax.xml.bind.JAXBContext;
|
|||||||
import javax.xml.bind.JAXBException;
|
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.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This listener class will initiate the permission addition of permissions defined in
|
* This listener class will initiate the permission addition of permissions defined in
|
||||||
@ -45,7 +49,8 @@ import java.util.List;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class WebAppDeploymentLifecycleListener implements LifecycleListener {
|
public class WebAppDeploymentLifecycleListener implements LifecycleListener {
|
||||||
|
|
||||||
private static final String PERMISSION_CONFIG_PATH = "META-INF" + File.separator + "permissions.xml";
|
private static final String PARAM_MANAGED_API_ENABLED = "managed-api-enabled";
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(WebAppDeploymentLifecycleListener.class);
|
private static final Log log = LogFactory.getLog(WebAppDeploymentLifecycleListener.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,34 +59,27 @@ public class WebAppDeploymentLifecycleListener implements LifecycleListener {
|
|||||||
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
|
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
|
||||||
ServletContext servletContext = context.getServletContext();
|
ServletContext servletContext = context.getServletContext();
|
||||||
String contextPath = context.getServletContext().getContextPath();
|
String contextPath = context.getServletContext().getContextPath();
|
||||||
|
String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED);
|
||||||
|
boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param);
|
||||||
|
|
||||||
|
if (isManagedApi) {
|
||||||
try {
|
try {
|
||||||
InputStream permissionStream = servletContext.getResourceAsStream(PERMISSION_CONFIG_PATH);
|
AnnotationProcessor annotationProcessor = new AnnotationProcessor(context);
|
||||||
if (permissionStream != null) {
|
Set<String> annotatedAPIClasses = annotationProcessor.
|
||||||
/* Un-marshaling Device Management configuration */
|
scanStandardContext(org.wso2.carbon.apimgt.annotations.api.API.class.getName());
|
||||||
JAXBContext cdmContext = JAXBContext.newInstance(PermissionConfiguration.class);
|
List<Permission> permissions = annotationProcessor.extractPermissions(annotatedAPIClasses);
|
||||||
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
PermissionManagerService permissionManagerService = PermissionManagerServiceImpl.getInstance();
|
||||||
PermissionConfiguration permissionConfiguration = (PermissionConfiguration)
|
if (permissions != null) {
|
||||||
unmarshaller.unmarshal(permissionStream);
|
|
||||||
List<Permission> permissions = permissionConfiguration.getPermissions();
|
|
||||||
String apiVersion = permissionConfiguration.getApiVersion();
|
|
||||||
if (permissionConfiguration != null && permissions != null) {
|
|
||||||
for (Permission permission : permissions) {
|
for (Permission permission : permissions) {
|
||||||
// update the permission path to absolute permission path
|
permissionManagerService.addPermission(permission);
|
||||||
permission.setPath(PermissionUtils.getAbsolutePermissionPath(permission.getPath()));
|
|
||||||
permission.setUrl(PermissionUtils.getAbsoluteContextPathOfAPI(contextPath, apiVersion,
|
|
||||||
permission.getUrl()).toLowerCase());
|
|
||||||
permission.setMethod(permission.getMethod().toUpperCase());
|
|
||||||
PermissionManagerServiceImpl.getInstance().addPermission(permission);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (JAXBException e) {
|
|
||||||
log.error(
|
|
||||||
"Exception occurred while parsing the permission configuration of webapp : "
|
|
||||||
+ context.getServletContext().getContextPath(), e);
|
|
||||||
} catch (PermissionManagementException e) {
|
} catch (PermissionManagementException e) {
|
||||||
log.error("Exception occurred while adding the permissions from webapp : "
|
log.error("Exception occurred while adding the permissions from webapp : "
|
||||||
+ servletContext.getContextPath(), e);
|
+ servletContext.getContextPath(), e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Cannot find API annotation Class in the webapp '" + contextPath + "' class path", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.internal;
|
package org.wso2.carbon.device.mgt.core.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.apimgt.impl.APIManagerConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||||
@ -56,6 +57,16 @@ public class DeviceManagementDataHolder {
|
|||||||
private EmailSenderService emailSenderService;
|
private EmailSenderService emailSenderService;
|
||||||
private PushNotificationProviderRepository pushNotificationProviderRepository;
|
private PushNotificationProviderRepository pushNotificationProviderRepository;
|
||||||
|
|
||||||
|
public APIManagerConfiguration getApiManagerConfiguration() {
|
||||||
|
return apiManagerConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApiManagerConfiguration(APIManagerConfiguration apiManagerConfiguration) {
|
||||||
|
this.apiManagerConfiguration = apiManagerConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private APIManagerConfiguration apiManagerConfiguration;
|
||||||
|
|
||||||
private DeviceManagementDataHolder() {}
|
private DeviceManagementDataHolder() {}
|
||||||
|
|
||||||
public static DeviceManagementDataHolder getInstance() {
|
public static DeviceManagementDataHolder getInstance() {
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.apimgt.impl.APIManagerConfiguration;
|
||||||
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
@ -30,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagement
|
|||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
|
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
|
||||||
|
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementService;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
|
||||||
@ -50,6 +52,8 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
|||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||||
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.push.notification.mgt.PushNotificationProviderRepository;
|
import org.wso2.carbon.device.mgt.core.push.notification.mgt.PushNotificationProviderRepository;
|
||||||
|
import org.wso2.carbon.device.mgt.core.scope.mgt.ScopeManagementServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||||
@ -59,8 +63,10 @@ import org.wso2.carbon.email.sender.core.service.EmailSenderService;
|
|||||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -117,6 +123,9 @@ public class DeviceManagementServiceComponent {
|
|||||||
private static List<DeviceManagementService> deviceManagers = new ArrayList<>();
|
private static List<DeviceManagementService> deviceManagers = new ArrayList<>();
|
||||||
private static List<DeviceManagerStartupListener> startupListeners = new ArrayList<>();
|
private static List<DeviceManagerStartupListener> startupListeners = new ArrayList<>();
|
||||||
private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
|
private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
|
||||||
|
private static final String APIM_CONFIGURATION_PATH = CarbonUtils.getCarbonHome() + File.separator + "repository" +
|
||||||
|
File.separator + "conf" + File.separator + "api-manager.xml";
|
||||||
|
private static final String DATA_SOURCE_NAME = "DataSourceName";
|
||||||
|
|
||||||
public static void registerPluginInitializationListener(PluginInitializationListener listener) {
|
public static void registerPluginInitializationListener(PluginInitializationListener listener) {
|
||||||
synchronized (LOCK) {
|
synchronized (LOCK) {
|
||||||
@ -149,12 +158,19 @@ public class DeviceManagementServiceComponent {
|
|||||||
DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||||
|
|
||||||
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
|
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
|
||||||
|
|
||||||
|
APIManagerConfiguration apiManagerConfiguration = new APIManagerConfiguration();
|
||||||
|
apiManagerConfiguration.load(APIM_CONFIGURATION_PATH);
|
||||||
|
DeviceManagementDataHolder.getInstance().setApiManagerConfiguration(apiManagerConfiguration);
|
||||||
|
|
||||||
DeviceManagementDAOFactory.init(dsConfig);
|
DeviceManagementDAOFactory.init(dsConfig);
|
||||||
GroupManagementDAOFactory.init(dsConfig);
|
GroupManagementDAOFactory.init(dsConfig);
|
||||||
NotificationManagementDAOFactory.init(dsConfig);
|
NotificationManagementDAOFactory.init(dsConfig);
|
||||||
|
|
||||||
OperationManagementDAOFactory.init(dsConfig);
|
OperationManagementDAOFactory.init(dsConfig);
|
||||||
|
|
||||||
|
String apiManagerDataSource = apiManagerConfiguration.getFirstProperty(DATA_SOURCE_NAME);
|
||||||
|
ScopeManagementDAOFactory.init(apiManagerDataSource);
|
||||||
|
|
||||||
/* Initialize Operation Manager */
|
/* Initialize Operation Manager */
|
||||||
this.initOperationsManager();
|
this.initOperationsManager();
|
||||||
|
|
||||||
@ -227,10 +243,9 @@ public class DeviceManagementServiceComponent {
|
|||||||
= new NotificationManagementServiceImpl();
|
= new NotificationManagementServiceImpl();
|
||||||
bundleContext.registerService(NotificationManagementService.class.getName(), notificationManagementService, null);
|
bundleContext.registerService(NotificationManagementService.class.getName(), notificationManagementService, null);
|
||||||
|
|
||||||
/* Registering PermissionManager Service */
|
/* Registering Scope Management Service */
|
||||||
PermissionManagerService permissionManagerService
|
ScopeManagementService scopeManagementService = new ScopeManagementServiceImpl();
|
||||||
= PermissionManagerServiceImpl.getInstance();
|
bundleContext.registerService(ScopeManagementService.class.getName(), scopeManagementService, null);
|
||||||
bundleContext.registerService(PermissionManagerService.class.getName(), permissionManagerService, null);
|
|
||||||
|
|
||||||
/* Registering DeviceAccessAuthorization Service */
|
/* Registering DeviceAccessAuthorization Service */
|
||||||
DeviceAccessAuthorizationService deviceAccessAuthorizationService = new DeviceAccessAuthorizationServiceImpl();
|
DeviceAccessAuthorizationService deviceAccessAuthorizationService = new DeviceAccessAuthorizationServiceImpl();
|
||||||
|
|||||||
@ -20,11 +20,13 @@ package org.wso2.carbon.device.mgt.core.notification.mgt.dao;
|
|||||||
|
|
||||||
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.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
|
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
|
||||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException;
|
||||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
|
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
|
||||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl.NotificationDAOImpl;
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl.*;
|
||||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@ -39,20 +41,47 @@ import java.util.List;
|
|||||||
public class NotificationManagementDAOFactory {
|
public class NotificationManagementDAOFactory {
|
||||||
|
|
||||||
private static DataSource dataSource;
|
private static DataSource dataSource;
|
||||||
|
private static String databaseEngine;
|
||||||
private static final Log log = LogFactory.getLog(NotificationManagementDAOFactory.class);
|
private static final Log log = LogFactory.getLog(NotificationManagementDAOFactory.class);
|
||||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||||
|
|
||||||
public static NotificationDAO getNotificationDAO() {
|
public static NotificationDAO getNotificationDAO() {
|
||||||
return new NotificationDAOImpl();
|
if (databaseEngine != null) {
|
||||||
|
switch (databaseEngine) {
|
||||||
|
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE:
|
||||||
|
return new OracleNotificationDAOImpl();
|
||||||
|
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL:
|
||||||
|
return new SQLServerNotificationDAOImpl();
|
||||||
|
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||||
|
return new PostgreSQLNotificationDAOImpl();
|
||||||
|
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
|
||||||
|
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||||
|
return new GenericNotificationDAOImpl();
|
||||||
|
default:
|
||||||
|
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(DataSourceConfig config) {
|
public static void init(DataSourceConfig config) {
|
||||||
dataSource = resolveDataSource(config);
|
dataSource = resolveDataSource(config);
|
||||||
|
try {
|
||||||
|
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Error occurred while retrieving config.datasource connection", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(DataSource dtSource) {
|
public static void init(DataSource dtSource) {
|
||||||
dataSource = dtSource;
|
dataSource = dtSource;
|
||||||
|
try {
|
||||||
|
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Error occurred while retrieving config.datasource connection", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void beginTransaction() throws TransactionManagementException {
|
public static void beginTransaction() throws TransactionManagementException {
|
||||||
Connection conn = currentConnection.get();
|
Connection conn = currentConnection.get();
|
||||||
|
|||||||
@ -35,7 +35,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* Implementation of NotificationDAO which includes the methods to do CRUD operations on notification.
|
* Implementation of NotificationDAO which includes the methods to do CRUD operations on notification.
|
||||||
*/
|
*/
|
||||||
public class NotificationDAOImpl implements NotificationDAO {
|
public abstract class AbstractNotificationDAOImpl implements NotificationDAO {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addNotification(int deviceId, int tenantId,
|
public int addNotification(int deviceId, int tenantId,
|
||||||
@ -87,7 +87,7 @@ public class NotificationDAOImpl implements NotificationDAO {
|
|||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
notification = this.getNotification(rs);
|
notification = NotificationDAOUtil.getNotification(rs);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new NotificationManagementException(
|
throw new NotificationManagementException(
|
||||||
@ -165,7 +165,7 @@ public class NotificationDAOImpl implements NotificationDAO {
|
|||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
notifications = new ArrayList<>();
|
notifications = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
notifications.add(this.getNotification(rs));
|
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new NotificationManagementException(
|
throw new NotificationManagementException(
|
||||||
@ -176,45 +176,6 @@ public class NotificationDAOImpl implements NotificationDAO {
|
|||||||
return notifications;
|
return notifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws NotificationManagementException {
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
List<Notification> notifications = null;
|
|
||||||
try {
|
|
||||||
conn = NotificationManagementDAOFactory.getConnection();
|
|
||||||
String sql =
|
|
||||||
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
|
||||||
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
|
||||||
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
|
||||||
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
|
||||||
|
|
||||||
sql = sql + " LIMIT ?,?";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setInt(1, tenantId);
|
|
||||||
stmt.setInt(2, tenantId);
|
|
||||||
int paramIdx = 3;
|
|
||||||
|
|
||||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
|
||||||
stmt.setInt(paramIdx, request.getRowCount());
|
|
||||||
|
|
||||||
rs = stmt.executeQuery();
|
|
||||||
notifications = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
notifications.add(this.getNotification(rs));
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new NotificationManagementException(
|
|
||||||
"Error occurred while retrieving information of all notifications", e);
|
|
||||||
} finally {
|
|
||||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
}
|
|
||||||
return notifications;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNotificationCount(int tenantId) throws NotificationManagementException {
|
public int getNotificationCount(int tenantId) throws NotificationManagementException {
|
||||||
int notificationCount = 0;
|
int notificationCount = 0;
|
||||||
@ -277,7 +238,7 @@ public class NotificationDAOImpl implements NotificationDAO {
|
|||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
notifications = new ArrayList<>();
|
notifications = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
notifications.add(this.getNotification(rs));
|
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new NotificationManagementException(
|
throw new NotificationManagementException(
|
||||||
@ -322,59 +283,4 @@ public class NotificationDAOImpl implements NotificationDAO {
|
|||||||
}
|
}
|
||||||
return notificationCountByStatus;
|
return notificationCountByStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
|
||||||
NotificationManagementException{
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
List<Notification> notifications = null;
|
|
||||||
try {
|
|
||||||
conn = NotificationManagementDAOFactory.getConnection();
|
|
||||||
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
|
||||||
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
|
||||||
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
|
||||||
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
|
||||||
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
|
||||||
"AND TENANT_ID = ?";
|
|
||||||
|
|
||||||
sql = sql + " LIMIT ?,?";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setInt(1, tenantId);
|
|
||||||
stmt.setString(2, status.toString());
|
|
||||||
stmt.setInt(3, tenantId);
|
|
||||||
|
|
||||||
int paramIdx = 4;
|
|
||||||
|
|
||||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
|
||||||
stmt.setInt(paramIdx, request.getRowCount());
|
|
||||||
|
|
||||||
|
|
||||||
rs = stmt.executeQuery();
|
|
||||||
notifications = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
notifications.add(this.getNotification(rs));
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new NotificationManagementException(
|
|
||||||
"Error occurred while retrieving information of all " +
|
|
||||||
"notifications by status : " + status, e);
|
|
||||||
} finally {
|
|
||||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
}
|
|
||||||
return notifications;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private Notification getNotification(ResultSet rs) throws SQLException {
|
|
||||||
Notification notification = new Notification();
|
|
||||||
notification.setNotificationId(rs.getInt("NOTIFICATION_ID"));
|
|
||||||
notification.setOperationId(rs.getInt("OPERATION_ID"));
|
|
||||||
notification.setDescription(rs.getString("DESCRIPTION"));
|
|
||||||
notification.setStatus(rs.getString("STATUS"));
|
|
||||||
return notification;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds the generic implementation of NotificationDAO which can be used to support ANSI db syntax.
|
||||||
|
*/
|
||||||
|
public class GenericNotificationDAOImpl extends AbstractNotificationDAOImpl {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
|
||||||
|
NotificationManagementException {
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<Notification> notifications = null;
|
||||||
|
try {
|
||||||
|
conn = NotificationManagementDAOFactory.getConnection();
|
||||||
|
String sql =
|
||||||
|
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
||||||
|
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||||
|
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||||
|
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||||
|
|
||||||
|
sql = sql + " LIMIT ?,?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
int paramIdx = 3;
|
||||||
|
|
||||||
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||||
|
stmt.setInt(paramIdx, request.getRowCount());
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
notifications = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new NotificationManagementException(
|
||||||
|
"Error occurred while retrieving information of all notifications", e);
|
||||||
|
} finally {
|
||||||
|
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
||||||
|
NotificationManagementException{
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<Notification> notifications = null;
|
||||||
|
try {
|
||||||
|
conn = NotificationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
||||||
|
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||||
|
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||||
|
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||||
|
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||||
|
"AND TENANT_ID = ?";
|
||||||
|
|
||||||
|
sql = sql + " LIMIT ?,?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setString(2, status.toString());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
|
||||||
|
int paramIdx = 4;
|
||||||
|
|
||||||
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||||
|
stmt.setInt(paramIdx, request.getRowCount());
|
||||||
|
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
notifications = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new NotificationManagementException(
|
||||||
|
"Error occurred while retrieving information of all " +
|
||||||
|
"notifications by status : " + status, e);
|
||||||
|
} finally {
|
||||||
|
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds the Oracle implementation of NotificationDAO which can be used to support Oracle db syntax.
|
||||||
|
*/
|
||||||
|
public class OracleNotificationDAOImpl extends AbstractNotificationDAOImpl {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
|
||||||
|
NotificationManagementException {
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<Notification> notifications = null;
|
||||||
|
try {
|
||||||
|
conn = NotificationManagementDAOFactory.getConnection();
|
||||||
|
String sql =
|
||||||
|
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
||||||
|
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||||
|
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||||
|
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||||
|
|
||||||
|
sql = sql + " WHERE OFFSET >= ? AND ROWNUM <= ?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
int paramIdx = 3;
|
||||||
|
|
||||||
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||||
|
stmt.setInt(paramIdx, request.getRowCount());
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
notifications = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new NotificationManagementException(
|
||||||
|
"Error occurred while retrieving information of all notifications", e);
|
||||||
|
} finally {
|
||||||
|
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
||||||
|
NotificationManagementException{
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<Notification> notifications = null;
|
||||||
|
try {
|
||||||
|
conn = NotificationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
||||||
|
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||||
|
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||||
|
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||||
|
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||||
|
"AND TENANT_ID = ?";
|
||||||
|
|
||||||
|
sql = sql + " OFFSET >= ? AND ROWNUM <= ?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setString(2, status.toString());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
|
||||||
|
int paramIdx = 4;
|
||||||
|
|
||||||
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||||
|
stmt.setInt(paramIdx, request.getRowCount());
|
||||||
|
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
notifications = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new NotificationManagementException(
|
||||||
|
"Error occurred while retrieving information of all " +
|
||||||
|
"notifications by status : " + status, e);
|
||||||
|
} finally {
|
||||||
|
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds the implementation of NotificationDAO which can be used to support PostgreSQL db syntax.
|
||||||
|
*/
|
||||||
|
public class PostgreSQLNotificationDAOImpl extends AbstractNotificationDAOImpl {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
|
||||||
|
NotificationManagementException {
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<Notification> notifications = null;
|
||||||
|
try {
|
||||||
|
conn = NotificationManagementDAOFactory.getConnection();
|
||||||
|
String sql =
|
||||||
|
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
||||||
|
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||||
|
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||||
|
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||||
|
|
||||||
|
sql = sql + " LIMIT ? OFFSET ?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
int paramIdx = 3;
|
||||||
|
|
||||||
|
stmt.setInt(paramIdx++, request.getRowCount());
|
||||||
|
stmt.setInt(paramIdx, request.getStartIndex());
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
notifications = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new NotificationManagementException(
|
||||||
|
"Error occurred while retrieving information of all notifications", e);
|
||||||
|
} finally {
|
||||||
|
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
||||||
|
NotificationManagementException{
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<Notification> notifications = null;
|
||||||
|
try {
|
||||||
|
conn = NotificationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
||||||
|
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||||
|
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||||
|
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||||
|
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||||
|
"AND TENANT_ID = ?";
|
||||||
|
|
||||||
|
sql = sql + " LIMIT ? OFFSET ?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setString(2, status.toString());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
|
||||||
|
int paramIdx = 4;
|
||||||
|
|
||||||
|
stmt.setInt(paramIdx++, request.getRowCount());
|
||||||
|
stmt.setInt(paramIdx, request.getStartIndex());
|
||||||
|
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
notifications = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new NotificationManagementException(
|
||||||
|
"Error occurred while retrieving information of all " +
|
||||||
|
"notifications by status : " + status, e);
|
||||||
|
} finally {
|
||||||
|
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds the implementation of NotificationDAO which can be used to support SQLServer db syntax.
|
||||||
|
*/
|
||||||
|
public class SQLServerNotificationDAOImpl extends AbstractNotificationDAOImpl {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
|
||||||
|
NotificationManagementException {
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<Notification> notifications = null;
|
||||||
|
try {
|
||||||
|
conn = NotificationManagementDAOFactory.getConnection();
|
||||||
|
String sql =
|
||||||
|
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
||||||
|
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||||
|
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||||
|
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||||
|
|
||||||
|
sql = sql + " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
int paramIdx = 3;
|
||||||
|
|
||||||
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||||
|
stmt.setInt(paramIdx, request.getRowCount());
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
notifications = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new NotificationManagementException(
|
||||||
|
"Error occurred while retrieving information of all notifications", e);
|
||||||
|
} finally {
|
||||||
|
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
||||||
|
NotificationManagementException{
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<Notification> notifications = null;
|
||||||
|
try {
|
||||||
|
conn = NotificationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
||||||
|
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||||
|
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||||
|
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||||
|
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||||
|
"AND TENANT_ID = ?";
|
||||||
|
|
||||||
|
sql = sql + " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setString(2, status.toString());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
|
||||||
|
int paramIdx = 4;
|
||||||
|
|
||||||
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||||
|
stmt.setInt(paramIdx, request.getRowCount());
|
||||||
|
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
notifications = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new NotificationManagementException(
|
||||||
|
"Error occurred while retrieving information of all " +
|
||||||
|
"notifications by status : " + status, e);
|
||||||
|
} finally {
|
||||||
|
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.core.notification.mgt.dao.util;
|
|||||||
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.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
@ -123,4 +124,13 @@ public class NotificationDAOUtil {
|
|||||||
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
|
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Notification getNotification(ResultSet rs) throws SQLException {
|
||||||
|
Notification notification = new Notification();
|
||||||
|
notification.setNotificationId(rs.getInt("NOTIFICATION_ID"));
|
||||||
|
notification.setOperationId(rs.getInt("OPERATION_ID"));
|
||||||
|
notification.setDescription(rs.getString("DESCRIPTION"));
|
||||||
|
notification.setStatus(rs.getString("STATUS"));
|
||||||
|
return notification;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,8 +46,8 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
List<Operation> operations = new ArrayList<Operation>();
|
List<Operation> operations = new ArrayList<Operation>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
|
||||||
"OPERATION_CODE, om.STATUS FROM DM_OPERATION o " +
|
"o.OPERATION_CODE, om.STATUS FROM DM_OPERATION o " +
|
||||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||||
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ? OFFSET ?";
|
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ? OFFSET ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
@ -72,7 +72,7 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
||||||
"available for the device'" + enrolmentId + "' with status '", e);
|
"available for the device'" + enrolmentId, e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
List<Operation> operations = new ArrayList<Operation>();
|
List<Operation> operations = new ArrayList<Operation>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE " +
|
||||||
"FROM DM_OPERATION o " +
|
"FROM DM_OPERATION o " +
|
||||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||||
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +
|
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +
|
||||||
|
|||||||
@ -22,8 +22,9 @@ 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.common.permission.mgt.PermissionManagerService;
|
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will add, update custom permissions defined in permission.xml in webapps and it will
|
* This class will add, update custom permissions defined in permission.xml in webapps and it will
|
||||||
@ -52,16 +53,19 @@ public class PermissionManagerServiceImpl implements PermissionManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addPermission(Permission permission) throws PermissionManagementException {
|
public void addPermission(Permission permission) throws PermissionManagementException {
|
||||||
// adding a permission to the tree
|
// adding a permission to the tree
|
||||||
permissionTree.addPermission(permission);
|
permissionTree.addPermission(permission);
|
||||||
return PermissionUtils.putPermission(permission);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Permission getPermission(Properties properties) throws PermissionManagementException {
|
public Permission getPermission(Properties properties) throws PermissionManagementException {
|
||||||
String url = (String) properties.get(URL_PROPERTY);
|
String url = (String) properties.get(URL_PROPERTY);
|
||||||
String httpMethod = (String) properties.get(HTTP_METHOD_PROPERTY);
|
String httpMethod = (String) properties.get(HTTP_METHOD_PROPERTY);
|
||||||
|
|
||||||
|
if (url == null || url.isEmpty() || httpMethod == null || httpMethod.isEmpty()) {
|
||||||
|
throw new PermissionManagementException("Resource URI/HTTP method is empty");
|
||||||
|
}
|
||||||
return permissionTree.getPermission(url, httpMethod);
|
return permissionTree.getPermission(url, httpMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,9 +54,6 @@ public class PermissionTree {
|
|||||||
tempRoot = addPermissionNode(tempRoot, tempChild);
|
tempRoot = addPermissionNode(tempRoot, tempChild);
|
||||||
}
|
}
|
||||||
tempRoot.addPermission(permission.getMethod(), permission); //setting permission to the vertex
|
tempRoot.addPermission(permission.getMethod(), permission); //setting permission to the vertex
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Added permission '" + permission.getName() + "'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -66,24 +66,24 @@ public class PermissionUtils {
|
|||||||
return contextPath + 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);
|
||||||
Permission permission = new Permission();
|
// Permission permission = new Permission();
|
||||||
permission.setName(resource.getProperty(PERMISSION_PROPERTY_NAME));
|
// permission.setName(resource.getProperty(PERMISSION_PROPERTY_NAME));
|
||||||
permission.setPath(resource.getPath());
|
// permission.setPath(resource.getPath());
|
||||||
return permission;
|
// return permission;
|
||||||
} catch (RegistryException e) {
|
// } catch (RegistryException e) {
|
||||||
throw new PermissionManagementException("Error in retrieving registry resource : " +
|
// throw new PermissionManagementException("Error in retrieving registry resource : " +
|
||||||
e.getMessage(), e);
|
// e.getMessage(), e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public static boolean putPermission(Permission permission)
|
public static boolean putPermission(String permissionPath)
|
||||||
throws PermissionManagementException {
|
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,9 +95,7 @@ public class PermissionUtils {
|
|||||||
}
|
}
|
||||||
status = true;
|
status = true;
|
||||||
} catch (RegistryException e) {
|
} catch (RegistryException e) {
|
||||||
throw new PermissionManagementException(
|
throw new PermissionManagementException("Error occurred while persisting permission", e);
|
||||||
"Error occurred while persisting permission : " +
|
|
||||||
permission.getName(), e);
|
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt;
|
|
||||||
|
|
||||||
public class EvaluationContext {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt;
|
|
||||||
|
|
||||||
public class PolicyEvaluationException extends Exception {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt;
|
|
||||||
|
|
||||||
public interface PolicyEvaluationStrategy {
|
|
||||||
|
|
||||||
Profile execute(EvaluationContext ctx) throws PolicyEvaluationException;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt;
|
|
||||||
|
|
||||||
public class PolicyManagementException extends Exception {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
import org.wso2.carbon.device.mgt.core.policy.mgt.policy.Policy;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface PolicyManager {
|
|
||||||
|
|
||||||
public enum Type {
|
|
||||||
USER_BASED, ROLE_BASED, PLATFORM_BASED
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean addPolicy(Policy policy) throws PolicyManagementException;
|
|
||||||
|
|
||||||
boolean removePolicy(String policyId) throws PolicyManagementException;
|
|
||||||
|
|
||||||
boolean updatePolicy(Policy policy) throws PolicyManagementException;
|
|
||||||
|
|
||||||
Policy getPolicy(String policyId) throws PolicyManagementException;
|
|
||||||
|
|
||||||
List<Policy> getPolicies() throws PolicyManagementException;
|
|
||||||
|
|
||||||
List<Policy> getUserBasedPolicies(String user) throws PolicyManagementException;
|
|
||||||
|
|
||||||
List<Policy> getRoleBasedPolicies(String role) throws PolicyManagementException;
|
|
||||||
|
|
||||||
List<Policy> getPlatformBasedPolicies(String platform) throws PolicyManagementException;
|
|
||||||
|
|
||||||
boolean assignRoleBasedPolicy(String policyId, String role) throws PolicyManagementException;
|
|
||||||
|
|
||||||
boolean assignRoleBasedPolicy(String policyId, List<String> roles) throws PolicyManagementException;
|
|
||||||
|
|
||||||
boolean assignUserBasedPolicy(String policyId, String user) throws PolicyManagementException;
|
|
||||||
|
|
||||||
boolean assignUserBasedPolicy(String policyId, List<String> users) throws PolicyManagementException;
|
|
||||||
|
|
||||||
boolean assignPlatformBasedPolicy(String policyId, String platform) throws PolicyManagementException;
|
|
||||||
|
|
||||||
Profile getEffectiveProfile(DeviceIdentifier deviceId) throws PolicyManagementException;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.policy.mgt.policy.Policy;
|
|
||||||
|
|
||||||
public interface PolicyRepository {
|
|
||||||
|
|
||||||
public enum Type {
|
|
||||||
USER_BASED, ROLE_BASED, PLATFORM_BASED
|
|
||||||
}
|
|
||||||
|
|
||||||
void addPolicy(Policy policy) throws PolicyManagementException;
|
|
||||||
|
|
||||||
void remotePolicy(Policy policy) throws PolicyManagementException;
|
|
||||||
|
|
||||||
void getPolicy(String id) throws PolicyManagementException;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt;
|
|
||||||
|
|
||||||
public class Profile {
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt;
|
|
||||||
|
|
||||||
public class Rule {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt;
|
|
||||||
|
|
||||||
public interface RuleCombiningStrategy {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt.dao;
|
|
||||||
|
|
||||||
public interface PolicyDAO {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt.dao;
|
|
||||||
|
|
||||||
public class PolicyDAOFactory {
|
|
||||||
|
|
||||||
public static PolicyDAO getPolicyDAO() {
|
|
||||||
return new PolicyDAOImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt.dao;
|
|
||||||
|
|
||||||
public class PolicyDAOImpl implements PolicyDAO {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt.policy;
|
|
||||||
|
|
||||||
public class PlatformBasedPolicy extends Policy {
|
|
||||||
|
|
||||||
private String platform;
|
|
||||||
|
|
||||||
public String getPlatform() {
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlatform(String platform) {
|
|
||||||
this.platform = platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt.policy;
|
|
||||||
|
|
||||||
public class Policy {
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt.policy;
|
|
||||||
|
|
||||||
public class RoleBasedPolicy extends Policy {
|
|
||||||
|
|
||||||
private String role;
|
|
||||||
|
|
||||||
public String getRole() {
|
|
||||||
return role;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRole(String role) {
|
|
||||||
this.role = role;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.policy.mgt.policy;
|
|
||||||
|
|
||||||
public class UsedBasedPolicy extends Policy {
|
|
||||||
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user