Merge pull request #425 from GPrathap/IoTS-1.0.0

removed @API and @Permission annotations
revert-70aa11f8
Dilan U. Ariyaratne 8 years ago committed by GitHub
commit 023b554e0f

@ -1,36 +0,0 @@
/*
* 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.apimgt.annotations.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface API {
String name();
String version();
String context();
String[] tags();
}

@ -199,7 +199,7 @@ public class APIPublisherUtil {
String name = apiDef.getName(); String name = apiDef.getName();
if (name == null || name.isEmpty()) { if (name == null || name.isEmpty()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("API Name not set in @API Annotation"); log.debug("API Name not set in @SwaggerDefinition Annotation");
} }
name = servletContext.getServletContextName(); name = servletContext.getServletContextName();
} }
@ -208,7 +208,7 @@ public class APIPublisherUtil {
String version = apiDef.getVersion(); String version = apiDef.getVersion();
if (version == null || version.isEmpty()) { if (version == null || version.isEmpty()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("'API Version not set in @API Annotation'"); log.debug("'API Version not set in @SwaggerDefinition Annotation'");
} }
version = API_CONFIG_DEFAULT_VERSION; version = API_CONFIG_DEFAULT_VERSION;
} }
@ -218,7 +218,7 @@ public class APIPublisherUtil {
String context = apiDef.getContext(); String context = apiDef.getContext();
if (context == null || context.isEmpty()) { if (context == null || context.isEmpty()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("'API Context not set in @API Annotation'"); log.debug("'API Context not set in @SwaggerDefinition Annotation'");
} }
context = servletContext.getContextPath(); context = servletContext.getContextPath();
} }
@ -227,7 +227,7 @@ public class APIPublisherUtil {
String[] tags = apiDef.getTags(); String[] tags = apiDef.getTags();
if (tags == null || tags.length == 0) { if (tags == null || tags.length == 0) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("'API tag not set in @API Annotation'"); log.debug("'API tag not set in @SwaggerDefinition Annotation'");
} }
} else { } else {
apiConfig.setTags(tags); apiConfig.setTags(tags);

@ -57,28 +57,22 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param); boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param);
String profile = System.getProperty(PROPERTY_PROFILE); String profile = System.getProperty(PROPERTY_PROFILE);
if (WebappPublisherConfig.getInstance().getProfiles().getProfile().contains(profile.toLowerCase()) if (WebappPublisherConfig.getInstance().getProfiles().getProfile().contains(profile.toLowerCase())
&& isManagedApi) { && isManagedApi) {
try { try {
AnnotationProcessor annotationProcessor = new AnnotationProcessor(context); AnnotationProcessor annotationProcessor = new AnnotationProcessor(context);
Set<String> annotatedAPIClasses = annotationProcessor. Set<String> annotatedSwaggerAPIClasses = annotationProcessor.
scanStandardContext(org.wso2.carbon.apimgt.annotations.api.API.class.getName()); scanStandardContext(io.swagger.annotations.SwaggerDefinition.class.getName());
List<APIResourceConfiguration> apiDefinitions = annotationProcessor.extractAPIInfo(servletContext, List<APIResourceConfiguration> apiDefinitions = annotationProcessor.extractAPIInfo(servletContext,
annotatedAPIClasses); annotatedSwaggerAPIClasses);
for (APIResourceConfiguration apiDefinition : apiDefinitions) { for (APIResourceConfiguration apiDefinition : apiDefinitions) {
APIConfig apiConfig = APIPublisherUtil.buildApiConfig(servletContext, apiDefinition); APIConfig apiConfig = APIPublisherUtil.buildApiConfig(servletContext, apiDefinition);
try { try {
int tenantId = APIPublisherDataHolder.getInstance().getTenantManager(). int tenantId = APIPublisherDataHolder.getInstance().getTenantManager().
getTenantId(apiConfig.getTenantDomain()); getTenantId(apiConfig.getTenantDomain());
boolean isTenantActive = APIPublisherDataHolder.getInstance(). boolean isTenantActive = APIPublisherDataHolder.getInstance().
getTenantManager().isTenantActive(tenantId); getTenantManager().isTenantActive(tenantId);
if (isTenantActive) { if (isTenantActive) {
apiConfig.init(); apiConfig.init();
API api = APIPublisherUtil.getAPI(apiConfig); API api = APIPublisherUtil.getAPI(apiConfig);

@ -1,28 +1,25 @@
/* /*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Licensed under the Apache License, Version 2.0 (the "License");
* Version 2.0 (the "License"); you may not use this file except * you may not use this file except in compliance with the License.
* in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing, software
* software distributed under the License is distributed on an * distributed under the License is distributed on an "AS IS" BASIS,
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* KIND, either express or implied. See the License for the * See the License for the specific language governing permissions and
* specific language governing permissions and limitations * limitations under the License.
* under the License.
*/ */
package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util; package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util;
import io.swagger.annotations.SwaggerDefinition;
import org.apache.catalina.core.StandardContext; import org.apache.catalina.core.StandardContext;
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.annotations.api.API;
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;
@ -48,92 +45,96 @@ public class AnnotationProcessor {
private static final Log log = LogFactory.getLog(AnnotationProcessor.class); private static final Log log = LogFactory.getLog(AnnotationProcessor.class);
private static final String AUTH_TYPE = "Any";
private static final String STRING_ARR = "string_arr";
private static final String STRING = "string";
private static final String PACKAGE_ORG_APACHE = "org.apache"; private static final String PACKAGE_ORG_APACHE = "org.apache";
private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus"; private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus";
private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework"; private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework";
private static final String WILD_CARD = "/*"; private static final String WILD_CARD = "/*";
private static final String AUTH_TYPE = "Any"; private static final String SWAGGER_ANNOTATIONS_INFO = "info";
private static final String STRING_ARR = "string_arr"; private static final String SWAGGER_ANNOTATIONS_TAGS = "tags";
private static final String STRING = "string"; private static final String SWAGGER_ANNOTATIONS_EXTENSIONS = "extensions";
private static final String SWAGGER_ANNOTATIONS_PROPERTIES = "properties";
private static final String SWAGGER_ANNOTATIONS_PROPERTIES_NAME = "name";
private static final String SWAGGER_ANNOTATIONS_PROPERTIES_VERSION = "version";
private static final String SWAGGER_ANNOTATIONS_PROPERTIES_CONTEXT = "context";
private static final String SWAGGER_ANNOTATIONS_PROPERTIES_VALUE = "value";
Class<API> apiClazz;
private StandardContext context; private StandardContext context;
private Method[] pathClazzMethods; private Method[] pathClazzMethods;
private Class<Path> pathClazz; private Class<Path> pathClazz;
private ClassLoader classLoader; private ClassLoader classLoader;
private ServletContext servletContext; private ServletContext servletContext;
private Class<SwaggerDefinition> apiClazz;
private Class<Consumes> consumesClass;
private Class<Produces> producesClass;
private Class<io.swagger.annotations.Info> infoClass;
private Class<io.swagger.annotations.Tag> tagClass;
private Class<io.swagger.annotations.Extension> extensionClass;
private Class<io.swagger.annotations.ExtensionProperty> extensionPropertyClass;
public AnnotationProcessor(final StandardContext context) { public AnnotationProcessor(final StandardContext context) {
servletContext = context.getServletContext(); servletContext = context.getServletContext();
classLoader = servletContext.getClassLoader(); classLoader = servletContext.getClassLoader();
try {
pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
consumesClass = (Class<Consumes>) classLoader.loadClass(Consumes.class.getName());
producesClass = (Class<Produces>) classLoader.loadClass(Produces.class.getName());
apiClazz= (Class<SwaggerDefinition>)classLoader.loadClass((SwaggerDefinition.class.getName()));
infoClass = (Class<io.swagger.annotations.Info>)classLoader
.loadClass((io.swagger.annotations.Info.class.getName()));
tagClass = (Class<io.swagger.annotations.Tag>)classLoader
.loadClass((io.swagger.annotations.Tag.class.getName()));
extensionClass = (Class<io.swagger.annotations.Extension>)classLoader
.loadClass((io.swagger.annotations.Extension.class.getName()));
extensionPropertyClass = (Class<io.swagger.annotations.ExtensionProperty>)classLoader
.loadClass((io.swagger.annotations.ExtensionProperty.class.getName()));
} catch (ClassNotFoundException e) {
log.error("An error has occurred while loading classes ", e);
}
} }
/**
* Scan the context for classes with annotations
*
* @return
* @throws IOException
*/
public Set<String> scanStandardContext(String className) throws IOException { public Set<String> scanStandardContext(String className) throws IOException {
ExtendedAnnotationDB db = new ExtendedAnnotationDB(); ExtendedAnnotationDB db = new ExtendedAnnotationDB();
db.addIgnoredPackages(PACKAGE_ORG_APACHE); db.addIgnoredPackages(PACKAGE_ORG_APACHE);
db.addIgnoredPackages(PACKAGE_ORG_CODEHAUS); db.addIgnoredPackages(PACKAGE_ORG_CODEHAUS);
db.addIgnoredPackages(PACKAGE_ORG_SPRINGFRAMEWORK); db.addIgnoredPackages(PACKAGE_ORG_SPRINGFRAMEWORK);
URL classPath = findWebInfClassesPath(servletContext); URL classPath = findWebInfClassesPath(servletContext);
db.scanArchives(classPath); db.scanArchives(classPath);
//Returns a list of classes with given Annotation
return db.getAnnotationIndex().get(className); return db.getAnnotationIndex().get(className);
} }
/**
* Method identifies the URL templates and context by reading the annotations of a class
*
* @param entityClasses
* @return
*/
public List<APIResourceConfiguration> extractAPIInfo(final ServletContext servletContext, Set<String> entityClasses) public List<APIResourceConfiguration> extractAPIInfo(final ServletContext servletContext, Set<String> entityClasses)
throws ClassNotFoundException { throws ClassNotFoundException {
List<APIResourceConfiguration> apiResourceConfigs = new ArrayList<APIResourceConfiguration>(); List<APIResourceConfiguration> apiResourceConfigs = new ArrayList<APIResourceConfiguration>();
if (entityClasses != null && !entityClasses.isEmpty()) { if (entityClasses != null && !entityClasses.isEmpty()) {
for (final String className : entityClasses) { for (final String className : entityClasses) {
APIResourceConfiguration apiResourceConfiguration =
APIResourceConfiguration resource =
AccessController.doPrivileged(new PrivilegedAction<APIResourceConfiguration>() { AccessController.doPrivileged(new PrivilegedAction<APIResourceConfiguration>() {
public APIResourceConfiguration run() { public APIResourceConfiguration run() {
Class<?> clazz = null; Class<?> clazz = null;
APIResourceConfiguration apiResourceConfig = null; APIResourceConfiguration apiResourceConfig = null;
try { try {
clazz = classLoader.loadClass(className); clazz = classLoader.loadClass(className);
Annotation swaggerDefinition = clazz.getAnnotation(apiClazz);
apiClazz = (Class<API>)
classLoader.loadClass(org.wso2.carbon.apimgt.annotations.api.API
.class.getName());
Annotation apiAnno = clazz.getAnnotation(apiClazz);
List<APIResource> resourceList; List<APIResource> resourceList;
if (swaggerDefinition != null) {
if (apiAnno != null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Application Context root = " + servletContext.getContextPath()); log.debug("Application Context root = " + servletContext.getContextPath());
} }
try { try {
apiResourceConfig = processAPIAnnotation(apiAnno); apiResourceConfig = processAPIAnnotation(swaggerDefinition);
if(apiResourceConfig != null){
String rootContext = servletContext.getContextPath(); String rootContext = servletContext.getContextPath();
pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
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()) {
if (subContext.trim().startsWith("/")) { if (subContext.trim().startsWith("/")) {
rootContext = rootContext + subContext; rootContext = rootContext + subContext;
@ -145,56 +146,34 @@ public class AnnotationProcessor {
log.debug("API Root Context = " + rootContext); log.debug("API Root Context = " + rootContext);
} }
} }
Method[] annotatedMethods = clazz.getDeclaredMethods(); Method[] annotatedMethods = clazz.getDeclaredMethods();
resourceList = getApiResources(rootContext, annotatedMethods); resourceList = getApiResources(rootContext, annotatedMethods);
apiResourceConfig.setResources(resourceList); apiResourceConfig.setResources(resourceList);
}
} catch (Throwable throwable) { } catch (Throwable throwable) {
log.error("Error encountered while scanning for annotations", throwable); log.error("Error encountered while scanning for annotations", throwable);
} }
} }
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e1) {
log.error("Error when passing the api annotation for device type apis.", e); String msg = "Failed to load service class " + className + " for publishing APIs." +
" This API will not be published.";
log.error(msg);
} catch (RuntimeException e) {
log.error("Unexpected error has been occurred while publishing "+ className
+"hence, this API will not be published.");
throw new RuntimeException(e);
} }
return apiResourceConfig; return apiResourceConfig;
} }
}); });
apiResourceConfigs.add(resource); if(apiResourceConfiguration !=null)
apiResourceConfigs.add(apiResourceConfiguration);
} }
} }
return apiResourceConfigs; return apiResourceConfigs;
} }
/**
* Iterate API annotation and build API Configuration
*
* @param apiAnno
* @return
* @throws Throwable
*/
private APIResourceConfiguration processAPIAnnotation(Annotation apiAnno) throws Throwable {
Method[] apiClazzMethods = apiClazz.getMethods();
APIResourceConfiguration apiResourceConfig = new APIResourceConfiguration();
for (int k = 0; k < apiClazzMethods.length; k++) {
switch (apiClazzMethods[k].getName()) {
case "name":
apiResourceConfig.setName(invokeMethod(apiClazzMethods[k], apiAnno, STRING));
break;
case "version":
apiResourceConfig.setVersion(invokeMethod(apiClazzMethods[k], apiAnno, STRING));
break;
case "context":
apiResourceConfig.setContext(invokeMethod(apiClazzMethods[k], apiAnno, STRING));
break;
case "tags":
apiResourceConfig.setTags(invokeMethod(apiClazzMethods[k], apiAnno));
break;
}
}
return apiResourceConfig;
}
/** /**
* Get Resources for each API * Get Resources for each API
* *
@ -209,7 +188,6 @@ public class AnnotationProcessor {
for (Method method : annotatedMethods) { for (Method method : annotatedMethods) {
Annotation[] annotations = method.getDeclaredAnnotations(); Annotation[] annotations = method.getDeclaredAnnotations();
APIResource resource = new APIResource(); APIResource resource = new APIResource();
if (isHttpMethodAvailable(annotations)) { if (isHttpMethodAvailable(annotations)) {
Annotation methodContextAnno = method.getAnnotation(pathClazz); Annotation methodContextAnno = method.getAnnotation(pathClazz);
if (methodContextAnno != null) { if (methodContextAnno != null) {
@ -218,33 +196,21 @@ public class AnnotationProcessor {
subCtx = WILD_CARD; subCtx = WILD_CARD;
} }
resource.setUriTemplate(makeContextURLReady(subCtx)); resource.setUriTemplate(makeContextURLReady(subCtx));
resource.setUri(APIPublisherUtil.getServerBaseUrl() + makeContextURLReady(resourceRootContext) + resource.setUri(APIPublisherUtil.getServerBaseUrl() + makeContextURLReady(resourceRootContext) +
makeContextURLReady(subCtx)); makeContextURLReady(subCtx));
resource.setAuthType(AUTH_TYPE); resource.setAuthType(AUTH_TYPE);
for (int i = 0; i < annotations.length; i++) { for (int i = 0; i < annotations.length; i++) {
processHTTPMethodAnnotation(resource, annotations[i]); processHTTPMethodAnnotation(resource, annotations[i]);
if (annotations[i].annotationType().getName().equals(Consumes.class.getName())) { if (annotations[i].annotationType().getName().equals(Consumes.class.getName())) {
Class<Consumes> consumesClass = (Class<Consumes>) classLoader.loadClass(
Consumes.class.getName());
Method[] consumesClassMethods = consumesClass.getMethods(); Method[] consumesClassMethods = consumesClass.getMethods();
Annotation consumesAnno = method.getAnnotation(consumesClass); Annotation consumesAnno = method.getAnnotation(consumesClass);
resource.setConsumes(invokeMethod(consumesClassMethods[0], consumesAnno, STRING_ARR)); resource.setConsumes(invokeMethod(consumesClassMethods[0], consumesAnno, STRING_ARR));
} }
if (annotations[i].annotationType().getName().equals(Produces.class.getName())) { if (annotations[i].annotationType().getName().equals(Produces.class.getName())) {
Class<Produces> producesClass = (Class<Produces>) classLoader.loadClass(
Produces.class.getName());
Method[] producesClassMethods = producesClass.getMethods(); Method[] producesClassMethods = producesClass.getMethods();
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(org.wso2.carbon.apimgt.annotations.api.Scope.class.getName())) {
org.wso2.carbon.apimgt.api.model.Scope scope = this.getScope(method);
if (scope != null) {
resource.setScope(scope);
}
}
} }
resourceList.add(resource); resourceList.add(resource);
} }
@ -293,6 +259,61 @@ public class AnnotationProcessor {
return false; return false;
} }
/**
* Iterate API annotation and build API Configuration
*
* @param annotation reading @SwaggerDefinition annotation
* @return APIResourceConfiguration which compose with an API information which has its name, context,version,and tags
* @throws Throwable
*/
private APIResourceConfiguration processAPIAnnotation(Annotation annotation) throws Throwable {
InvocationHandler methodHandler = Proxy.getInvocationHandler(annotation);
Annotation info = (Annotation) methodHandler.invoke(annotation, apiClazz
.getMethod(SWAGGER_ANNOTATIONS_INFO,null),null);
Annotation[] tags = (Annotation[]) methodHandler.invoke(annotation, apiClazz
.getMethod(SWAGGER_ANNOTATIONS_TAGS,null),null);
String[] tagNames = new String[tags.length];
for(int i=0; i<tags.length; i++){
methodHandler = Proxy.getInvocationHandler(tags[i]);
tagNames[i]=(String)methodHandler.invoke(tags[i], tagClass
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_NAME, null),null);
}
methodHandler = Proxy.getInvocationHandler(info);
String version = (String)methodHandler.invoke(info, infoClass
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_VERSION,null),null);
if("".equals(version))return null;
Annotation[] apiInfo = (Annotation[])methodHandler.invoke(info, infoClass
.getMethod(SWAGGER_ANNOTATIONS_EXTENSIONS,null),null);
methodHandler = Proxy.getInvocationHandler(apiInfo[0]);
Annotation[] properties = (Annotation[])methodHandler.invoke(apiInfo[0], extensionClass
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES,null), null);
APIResourceConfiguration apiResourceConfig = new APIResourceConfiguration();
for (Annotation property : properties) {
methodHandler = Proxy.getInvocationHandler(property);
String key = (String) methodHandler.invoke(property, extensionPropertyClass
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_NAME, null),
null);
String value = (String) methodHandler.invoke(property, extensionPropertyClass
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_VALUE, null),null);
if ("".equals(key)) return null;
switch (key) {
case SWAGGER_ANNOTATIONS_PROPERTIES_NAME:
if ("".equals(value)) return null;
apiResourceConfig.setName(value);
break;
case SWAGGER_ANNOTATIONS_PROPERTIES_CONTEXT:
if ("".equals(value)) return null;
apiResourceConfig.setContext(value);
break;
default:
break;
}
}
apiResourceConfig.setVersion(version);
apiResourceConfig.setTags(tagNames);
return apiResourceConfig;
}
/** /**
* Append '/' to the context and make it URL ready * Append '/' to the context and make it URL ready
* *
@ -331,40 +352,6 @@ public class AnnotationProcessor {
} }
} }
/**
* When an annotation and method is passed, this method invokes that executes said method against the annotation
*/
private String[] invokeMethod(Method method, Annotation annotation) throws Throwable {
InvocationHandler methodHandler = Proxy.getInvocationHandler(annotation);
return ((String[]) methodHandler.invoke(annotation, method, null));
}
private org.wso2.carbon.apimgt.api.model.Scope getScope(Method currentMethod) throws Throwable {
Class<org.wso2.carbon.apimgt.annotations.api.Scope> scopeClass =
(Class<org.wso2.carbon.apimgt.annotations.api.Scope>) classLoader.
loadClass(org.wso2.carbon.apimgt.annotations.api.Scope.class.getName());
Annotation permissionAnnotation = currentMethod.getAnnotation(scopeClass);
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) {
switch (method.getName()) {
case "key":
scope.setKey(invokeMethod(method, permissionAnnotation, STRING));
break;
case "name":
scope.setName(invokeMethod(method, permissionAnnotation, STRING));
break;
case "description":
scope.setDescription(invokeMethod(method, permissionAnnotation, STRING));
break;
}
}
return scope;
}
return null;
}
/** /**
* 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
@ -388,5 +375,4 @@ public class AnnotationProcessor {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
} }

@ -4,7 +4,8 @@ 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 io.swagger.annotations.Authorization;
import io.swagger.annotations.AuthorizationScope;
import org.wso2.carbon.apimgt.annotations.api.Scope; 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;
@ -31,7 +32,15 @@ public interface CertificateMgtService {
httpMethod = "POST", httpMethod = "POST",
value = "Process a given CSR and return signed certificates.", value = "Process a given CSR and return signed certificates.",
notes = "This will return a signed certificate upon a given CSR.", notes = "This will return a signed certificate upon a given CSR.",
tags = "Device Management") tags = "Device Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/certificates/manage",
description = "Sign CSR") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -48,7 +57,6 @@ public interface CertificateMgtService {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Scope(key = "certificate:sign-csr", name = "Sign CSR", description = "") @Scope(key = "certificate:sign-csr", name = "Sign CSR", description = "")
@Permission(name = "Sign CSR", permission = "/device-mgt/certificates/manage")
Response getSignedCertFromCSR( Response getSignedCertFromCSR(
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",

@ -1,9 +1,18 @@
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.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.API; import io.swagger.annotations.Info;
import org.wso2.carbon.apimgt.annotations.api.Permission; import io.swagger.annotations.ExtensionProperty;
import org.wso2.carbon.apimgt.annotations.api.Scope; import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
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;
@ -13,10 +22,21 @@ 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", @SwaggerDefinition(
context = "api/certificate-mgt/v1.0/admin/certificates", info = @Info(
tags = {"devicemgt_admin"}) version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "Certificate Management"),
@ExtensionProperty(name = "context", value = "api/certificate-mgt/v1.0/admin/certificates"),
})
}
),
tags = {
@Tag(name = "devicemgt_admin", description = "")
}
)
@Api(value = "Certificate Management", description = "This API includes all the certificate management related operations") @Api(value = "Certificate Management", description = "This API includes all the certificate management related operations")
@Path("/admin/certificates") @Path("/admin/certificates")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -37,7 +57,15 @@ public interface CertificateManagementAdminService {
httpMethod = "POST", httpMethod = "POST",
value = "Adding a new SSL certificate", value = "Adding a new SSL certificate",
notes = "Add a new SSL certificate to the client end database.\n", notes = "Add a new SSL certificate to the client end database.\n",
tags = "Certificate Management") tags = "Certificate Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/certificates/manage",
description = "Manage certificates") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -77,7 +105,6 @@ 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(name = "Manage certificates", permission = "/device-mgt/certificates/manage")
Response addCertificate( Response addCertificate(
@ApiParam( @ApiParam(
name = "enrollmentCertificates", name = "enrollmentCertificates",
@ -101,7 +128,15 @@ public interface CertificateManagementAdminService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting Details of an SSL Certificate", value = "Getting Details of an SSL Certificate",
notes = "Get the client side SSL certificate details.", notes = "Get the client side SSL certificate details.",
tags = "Certificate Management") tags = "Certificate Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/certificates/view",
description = "View certificates") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -137,7 +172,6 @@ public interface CertificateManagementAdminService {
"Server error occurred while retrieving the requested certificate information.", "Server error occurred while retrieving the requested certificate information.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View certificates", permission = "/device-mgt/certificates/view")
Response getCertificate( Response getCertificate(
@ApiParam(name = "serialNumber", @ApiParam(name = "serialNumber",
value = "The serial number of the certificate.", value = "The serial number of the certificate.",
@ -167,7 +201,14 @@ public interface CertificateManagementAdminService {
notes = "Get all the details of the certificates you have used for mutual SSL. In a situation where you wish to " notes = "Get all the details of the certificates you have used for mutual SSL. In a situation where you wish to "
+ "view all the certificate details, it is not feasible to show all the details on one " + "view all the certificate details, it is not feasible to show all the details on one "
+ "page. Therefore, the details are paginated.", + "page. Therefore, the details are paginated.",
tags = "Certificate Management" tags = "Certificate Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/certificates/view",
description = "View certificates") }
)
}
) )
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
@ -212,7 +253,6 @@ public interface CertificateManagementAdminService {
"Server error occurred while retrieving the certificate details.", "Server error occurred while retrieving the certificate details.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View certificates", permission = "/device-mgt/certificates/view")
Response getAllCertificates( Response getAllCertificates(
@ApiParam( @ApiParam(
name = "offset", name = "offset",
@ -242,7 +282,15 @@ public interface CertificateManagementAdminService {
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Deleting an SSL Certificate", value = "Deleting an SSL Certificate",
notes = "Delete an SSL certificate that's on the client end.", notes = "Delete an SSL certificate that's on the client end.",
tags = "Certificate Management") tags = "Certificate Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/certificates/manage",
description = "Manage certificates") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -259,7 +307,6 @@ 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(name = "Manage certificates", permission = "/device-mgt/certificates/manage")
Response removeCertificate( Response removeCertificate(
@ApiParam( @ApiParam(
name = "serialNumber", name = "serialNumber",

@ -18,9 +18,19 @@
*/ */
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.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.API; import io.swagger.annotations.Info;
import org.wso2.carbon.apimgt.annotations.api.Permission; import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
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;
@ -33,11 +43,24 @@ import javax.ws.rs.core.Response;
/** /**
* Activity related REST-API implementation. * Activity related REST-API implementation.
*/ */
@API(name = "ActivityInfoProvider", version = "1.0.0", context = "/api/device-mgt/v1.0/activities", tags = {"device_management"}) @SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "ActivityInfoProvider"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/activities"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@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" +
"and responses from devices.") " operation details and responses from devices.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface ActivityInfoProviderService { public interface ActivityInfoProviderService {
@ -48,9 +71,17 @@ public interface ActivityInfoProviderService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting Details of an Activity", value = "Getting Details of an Activity",
notes = "Retrieve the details of a specific activity/operation, such as the meta information of an operation, " + notes = "Retrieve the details of a specific activity/operation, such as the meta information of " +
"including the responses from the devices.", "an operation, including the responses from the devices.",
tags = "Activity Info Provider") tags = "Activity Info Provider",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view"
, description = "View Activities") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -71,7 +102,8 @@ public interface ActivityInfoProviderService {
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."), message = "Not Modified. \n Empty body because the client already has the latest version of " +
"the requested resource."),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error.", message = "Bad Request. \n Invalid request or validation error.",
@ -91,7 +123,6 @@ public interface ActivityInfoProviderService {
message = "Internal Server Error. \n Server error occurred while fetching the activity data.", message = "Internal Server Error. \n Server error occurred while fetching the activity data.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Activities", permission = "/device-mgt/devices/owning-device/view")
Response getActivity( Response getActivity(
@ApiParam( @ApiParam(
name = "id", name = "id",
@ -115,8 +146,17 @@ public interface ActivityInfoProviderService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting Activity Details", value = "Getting Activity Details",
notes = "Get the details of the operations/activities executed by the server on the devices registered with WSO2 EMM, during a defined time period.", notes = "Get the details of the operations/activities executed by the server on the devices registered" +
tags = "Activity Info Provider") " with WSO2 EMM, during a defined time period.",
tags = "Activity Info Provider",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view"
, description = "View Activities") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -137,7 +177,8 @@ public interface ActivityInfoProviderService {
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource.\n"), message = "Not Modified. \n Empty body because the client already has the latest version of the" +
" requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 401, code = 401,
message = "Unauthorized. \n Unauthorized request."), message = "Unauthorized. \n Unauthorized request."),
@ -153,7 +194,6 @@ public interface ActivityInfoProviderService {
message = "Internal Server Error. \n Server error occurred while fetching the activity data.", message = "Internal Server Error. \n Server error occurred while fetching the activity data.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Activities", permission = "/device-mgt/devices/owning-device/view")
Response getActivities( Response getActivities(
@ApiParam( @ApiParam(
name = "since", name = "since",

@ -18,9 +18,19 @@
*/ */
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.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.API; import io.swagger.annotations.Info;
import org.wso2.carbon.apimgt.annotations.api.Permission; import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
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,8 +41,21 @@ import javax.ws.rs.core.Response;
/** /**
* General Tenant Configuration REST-API. * General Tenant Configuration REST-API.
*/ */
@API(name = "ConfigurationManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/configuration", tags = {"device_management"}) @SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "ConfigurationManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/configuration"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@Path("/configuration") @Path("/configuration")
@Api(value = "Configuration Management", description = "The general platform configuration management capabilities are exposed " + @Api(value = "Configuration Management", description = "The general platform configuration management capabilities are exposed " +
"through this API.") "through this API.")
@ -48,7 +71,14 @@ public interface ConfigurationManagementService {
notes = "WSO2 EMM monitors policies to verify that the devices comply with the policies enforced on them. " + notes = "WSO2 EMM monitors policies to verify that the devices comply with the policies enforced on them. " +
"General platform configurations include the settings on how often the device need to be monitored. " + "General platform configurations include the settings on how often the device need to be monitored. " +
"Using this REST API you can get the general platform level configurations.", "Using this REST API you can get the general platform level configurations.",
tags = "Configuration Management") tags = "Configuration Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/platform-configurations/view", description = "View Configurations") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -82,7 +112,6 @@ public interface ConfigurationManagementService {
"platform configurations.", "platform configurations.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Configurations", permission = "/device-mgt/platform-configurations/view")
Response getConfiguration( Response getConfiguration(
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",
@ -102,7 +131,14 @@ public interface ConfigurationManagementService {
notes = "WSO2 EMM monitors policies to verify that the devices comply with the policies enforced on them." + notes = "WSO2 EMM monitors policies to verify that the devices comply with the policies enforced on them." +
"General platform configurations include the settings on how often the the device need to be monitored." + "General platform configurations include the settings on how often the the device need to be monitored." +
"Using this REST API you can update the general platform level configurations.", "Using this REST API you can update the general platform level configurations.",
tags = "Configuration Management") tags = "Configuration Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/platform-configurations/manage", description = "Manage configurations") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -132,7 +168,6 @@ public interface ConfigurationManagementService {
"Server error occurred while modifying the general platform configurations.", "Server error occurred while modifying the general platform configurations.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage configurations", permission = "/device-mgt/platform-configurations/manage")
Response updateConfiguration( Response updateConfiguration(
@ApiParam( @ApiParam(
name = "configuration", name = "configuration",

@ -19,20 +19,39 @@
package org.wso2.carbon.device.mgt.jaxrs.service.api; package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Info;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.apimgt.annotations.api.Permission;
import javax.ws.rs.*; import javax.ws.rs.GET;
import javax.ws.rs.Path;
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;
/** /**
* Device Analytics Dashboard related REST-APIs. This can be used to obtain device related analytics. * Device Analytics Dashboard related REST-APIs. This can be used to obtain device related analytics.
*/ */
@API(name = "DeviceAnalyticsDashboard", @SwaggerDefinition(
version = "1.0.0", context = "/api/device-mgt/v1.0/dashboard", tags = {"device_management"}) info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "DeviceAnalyticsDashboard"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/dashboard"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@Path("/dashboard") @Path("/dashboard")
@Api(value = "Device Analytics Dashboard", @Api(value = "Device Analytics Dashboard",
description = "Device Analytics Dashboard related information APIs are described here.") description = "Device Analytics Dashboard related information APIs are described here.")

@ -18,9 +18,19 @@
*/ */
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.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.API; import io.swagger.annotations.Info;
import org.wso2.carbon.apimgt.annotations.api.Permission; import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
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;
@ -39,8 +49,21 @@ 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 = "DeviceManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/devices", tags = {"device_management"}) @SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "DeviceManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/devices"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@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 " +
"such as get all the available devices, etc.") "such as get all the available devices, etc.")
@ -54,7 +77,15 @@ public interface DeviceManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting Details of Registered Devices", value = "Getting Details of Registered Devices",
notes = "Provides details of all the devices enrolled with WSO2 EMM.", notes = "Provides details of all the devices enrolled with WSO2 EMM.",
tags = "Device Management") tags = "Device Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view"
, description = "View Devices") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.",
response = DeviceList.class, response = DeviceList.class,
@ -73,7 +104,8 @@ public interface DeviceManagementService {
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource.\n"), message = "Not Modified. \n Empty body because the client already has the latest version of " +
"the requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "The incoming request has more than one selection criteria defined via the query parameters.", message = "The incoming request has more than one selection criteria defined via the query parameters.",
@ -90,7 +122,6 @@ 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(name = "View Devices", permission = "/device-mgt/devices/owning-device/view")
Response getDevices( Response getDevices(
@ApiParam( @ApiParam(
name = "name", name = "name",
@ -173,7 +204,15 @@ public interface DeviceManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting Details of a Device", value = "Getting Details of a Device",
notes = "Get the details of a device by specifying the device type and device identifier.", notes = "Get the details of a device by specifying the device type and device identifier.",
tags = "Device Management") tags = "Device Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view",
description = "View Devices") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -195,7 +234,8 @@ public interface DeviceManagementService {
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. Empty body because the client already has the latest version of the requested resource.\n"), message = "Not Modified. Empty body because the client already has the latest version" +
" of the requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error.", message = "Bad Request. \n Invalid request or validation error.",
@ -210,7 +250,6 @@ public interface DeviceManagementService {
"Server error occurred while retrieving the device details.", "Server error occurred while retrieving the device details.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view")
Response getDevice( Response getDevice(
@ApiParam( @ApiParam(
name = "type", name = "type",
@ -245,7 +284,15 @@ public interface DeviceManagementService {
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Delete the device speccified by device id", value = "Delete the device speccified by device id",
notes = "Returns the status of the deleted device operation.", notes = "Returns the status of the deleted device operation.",
tags = "Device Management") tags = "Device Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view",
description = "View Devices") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -284,7 +331,6 @@ public interface DeviceManagementService {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
//TODO need to introduce delete permission //TODO need to introduce delete permission
@Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view")
Response deleteDevice( Response deleteDevice(
@ApiParam( @ApiParam(
name = "device-type", name = "device-type",
@ -312,7 +358,15 @@ public interface DeviceManagementService {
notes = "WSO2 EMM features enable you to carry out many operations based on the device platform. " + notes = "WSO2 EMM features enable you to carry out many operations based on the device platform. " +
"Using this REST API you can get the features that can be carried out on a preferred device type," + "Using this REST API you can get the features that can be carried out on a preferred device type," +
" such as iOS, Android or Windows.", " such as iOS, Android or Windows.",
tags = "Device Management") tags = "Device Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view",
description = "View Devices") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -361,7 +415,6 @@ public interface DeviceManagementService {
"Server error occurred while retrieving the feature list for the device platform.", "Server error occurred while retrieving the feature list for the device platform.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view")
Response getFeaturesOfDevice( Response getFeaturesOfDevice(
@ApiParam( @ApiParam(
name = "type", name = "type",
@ -396,7 +449,15 @@ public interface DeviceManagementService {
httpMethod = "POST", httpMethod = "POST",
value = "Advanced Search for Devices", value = "Advanced Search for Devices",
notes = "Search for devices by filtering the search result through the specified search terms.", notes = "Search for devices by filtering the search result through the specified search terms.",
tags = "Device Management") tags = "Device Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view",
description = "View Devices") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -439,7 +500,6 @@ public interface DeviceManagementService {
"Server error occurred while getting the device details.", "Server error occurred while getting the device details.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view")
Response searchDevices( Response searchDevices(
@ApiParam( @ApiParam(
name = "offset", name = "offset",
@ -468,7 +528,15 @@ public interface DeviceManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting Installed Application Details of a Device", value = "Getting Installed Application Details of a Device",
notes = "Get the list of applications subscribed to by a device.", notes = "Get the list of applications subscribed to by a device.",
tags = "Device Management") tags = "Device Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view",
description = "View Devices") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -517,7 +585,6 @@ public interface DeviceManagementService {
"Server error occurred while retrieving the list of installed application on the device.", "Server error occurred while retrieving the list of installed application on the device.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view")
Response getInstalledApplications( Response getInstalledApplications(
@ApiParam( @ApiParam(
name = "type", name = "type",
@ -565,7 +632,15 @@ public interface DeviceManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting Device Operation Details", value = "Getting Device Operation Details",
notes = "Get the details of operations carried out on a selected device.", notes = "Get the details of operations carried out on a selected device.",
tags = "Device Management") tags = "Device Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view",
description = "View Devices") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -614,7 +689,6 @@ public interface DeviceManagementService {
"Server error occurred while retrieving the operation list scheduled for the device.", "Server error occurred while retrieving the operation list scheduled for the device.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view")
Response getDeviceOperations( Response getDeviceOperations(
@ApiParam( @ApiParam(
name = "type", name = "type",
@ -671,7 +745,15 @@ public interface DeviceManagementService {
notes = "A policy is enforced on all the devices that register with WSO2 EMM." + notes = "A policy is enforced on all the devices that register with WSO2 EMM." +
"WSO2 EMM filters the policies based on the device platform (device type)," + "WSO2 EMM filters the policies based on the device platform (device type)," +
"the device ownership type, the user role or name and finally, the policy that matches these filters will be enforced on the device.", "the device ownership type, the user role or name and finally, the policy that matches these filters will be enforced on the device.",
tags = "Device Management") tags = "Device Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view",
description = "View Devices") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -720,7 +802,6 @@ public interface DeviceManagementService {
response = ErrorResponse.class) response = ErrorResponse.class)
} }
) )
@Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view")
Response getEffectivePolicyOfDevice( Response getEffectivePolicyOfDevice(
@ApiParam( @ApiParam(
name = "type", name = "type",
@ -755,7 +836,15 @@ public interface DeviceManagementService {
value = "Getting Policy Compliance Details of a Device", value = "Getting Policy Compliance Details of a Device",
notes = "A policy is enforced on the devices that register with WSO2 EMM. " + notes = "A policy is enforced on the devices that register with WSO2 EMM. " +
"The server checks if the settings in the device comply with the policy that is enforced on the device using this REST API.", "The server checks if the settings in the device comply with the policy that is enforced on the device using this REST API.",
tags = "Device Management") tags = "Device Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view",
description = "View Devices") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -772,7 +861,6 @@ public interface DeviceManagementService {
response = ErrorResponse.class) response = ErrorResponse.class)
} }
) )
@Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view")
Response getComplianceDataOfDevice( Response getComplianceDataOfDevice(
@ApiParam( @ApiParam(
name = "type", name = "type",

@ -18,30 +18,42 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.api; package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Info;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation; 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 io.swagger.annotations.ResponseHeader; import io.swagger.annotations.ResponseHeader;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
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;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.ws.rs.Consumes; import javax.ws.rs.*;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
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 = "DeviceTypeManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/device-types", @SwaggerDefinition(
tags = {"device_management"}) info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "DeviceTypeManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/device-types"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@Path("/device-types") @Path("/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 " +
"type management") "type management")
@ -55,7 +67,15 @@ public interface DeviceTypeManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting the Supported Device Platforms", value = "Getting the Supported Device Platforms",
notes = "Get the list of device platforms supported by WSO2 EMM.", notes = "Get the list of device platforms supported by WSO2 EMM.",
tags = "Device Type Management") tags = "Device Type Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view",
description = "View Device Types") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -80,7 +100,8 @@ public interface DeviceTypeManagementService {
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = message =
"Not Modified. \n Empty body because the client already has the latest version of the requested resource.\n"), "Not Modified. \n Empty body because the client already has the latest version " +
"of the requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ -91,7 +112,6 @@ public interface DeviceTypeManagementService {
response = ErrorResponse.class) response = ErrorResponse.class)
} }
) )
@Permission(name = "View Device Types", permission = "/device-mgt/devices/owning-device/view")
Response getDeviceTypes( Response getDeviceTypes(
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",
@ -108,8 +128,17 @@ public interface DeviceTypeManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Get Feature Details of a Device Type", value = "Get Feature Details of a Device Type",
notes = "The features in WSO2 EMM enables you to carry out many operations on a given device platform. " + notes = "The features in WSO2 EMM enables you to carry out many operations on a given device platform. " +
"Using this REST API you can get the features that can be carried out on a preferred device type, such as iOS, Android or Windows.", "Using this REST API you can get the features that can be carried out on a preferred device type," +
tags = "Device Type Management") " such as iOS, Android or Windows.",
tags = "Device Type Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view",
description = "View Device Types") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -134,7 +163,8 @@ public interface DeviceTypeManagementService {
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = message =
"Not Modified. \n Empty body because the client already has the latest version of the requested resource.\n"), "Not Modified. \n Empty body because the client already has the latest version " +
"of the requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ -145,7 +175,6 @@ public interface DeviceTypeManagementService {
response = ErrorResponse.class) response = ErrorResponse.class)
} }
) )
@Permission(name = "View Device Types", permission = "/device-mgt/devices/owning-device/view")
Response getFeatures( Response getFeatures(
@ApiParam( @ApiParam(
name = "type", name = "type",

@ -19,34 +19,26 @@
package org.wso2.carbon.device.mgt.jaxrs.service.api; package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Info;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation; 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 io.swagger.annotations.ResponseHeader; import io.swagger.annotations.ResponseHeader;
import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axis2.transport.http.HTTPConstants;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
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;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; import org.wso2.carbon.device.mgt.jaxrs.beans.*;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupShare;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupUsersList;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo;
import javax.validation.Valid; import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.*;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
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;
import java.util.List; import java.util.List;
@ -54,8 +46,21 @@ import java.util.List;
/** /**
* Device group related REST-API. This can be used to manipulated device group related details. * Device group related REST-API. This can be used to manipulated device group related details.
*/ */
@API(name = "GroupManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/groups", tags = {"device_management"}) @SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "GroupManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/groups"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@Path("/groups") @Path("/groups")
@Api(value = "Device Group Management", description = "This API carries all device group management related operations " + @Api(value = "Device Group Management", description = "This API carries all device group management related operations " +
"such as get all the available groups, etc.") "such as get all the available groups, etc.")
@ -69,7 +74,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "Get the list of groups belongs to current user.", value = "Get the list of groups belongs to current user.",
notes = "Returns all permitted groups enrolled with the system.", notes = "Returns all permitted groups enrolled with the system.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view",
description = "View Groups") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of device groups.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of device groups.",
response = DeviceGroupList.class, response = DeviceGroupList.class,
@ -102,7 +115,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while fetching the groups list.", message = "Internal Server Error. \n Server error occurred while fetching the groups list.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Groups", permission = "/device-mgt/groups/view")
Response getGroups(@ApiParam( Response getGroups(@ApiParam(
name = "name", name = "name",
value = "Name of the group.") value = "Name of the group.")
@ -127,7 +139,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "Get the count of groups belongs to current user.", value = "Get the count of groups belongs to current user.",
notes = "Returns count of all permitted groups enrolled with the system.", notes = "Returns count of all permitted groups enrolled with the system.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view",
description = "View Groups") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.",
response = DeviceGroupList.class, response = DeviceGroupList.class,
@ -160,7 +180,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while fetching the group count.", message = "Internal Server Error. \n Server error occurred while fetching the group count.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Groups", permission = "/device-mgt/groups/view")
Response getGroupCount(); Response getGroupCount();
@POST @POST
@ -169,7 +188,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_POST, httpMethod = HTTPConstants.HEADER_POST,
value = "Add new device group to the system.", value = "Add new device group to the system.",
notes = "Add device group with current user as the owner.", notes = "Add device group with current user as the owner.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/add",
description = "Add Group") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -216,7 +243,6 @@ public interface GroupManagementService {
"Server error occurred while adding a new device group.", "Server error occurred while adding a new device group.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Add Group", permission = "/device-mgt/groups/add")
Response createGroup(@ApiParam( Response createGroup(@ApiParam(
name = "group", name = "group",
value = "Group object with data.", value = "Group object with data.",
@ -230,7 +256,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "View group specified.", value = "View group specified.",
notes = "Returns details of group enrolled with the system.", notes = "Returns details of group enrolled with the system.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view",
description = "View Groups") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group.",
response = DeviceGroup.class, response = DeviceGroup.class,
@ -263,7 +297,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while fetching the group details.", message = "Internal Server Error. \n Server error occurred while fetching the group details.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Groups", permission = "/device-mgt/groups/view")
Response getGroup(@ApiParam( Response getGroup(@ApiParam(
name = "groupId", name = "groupId",
value = "ID of the group to view.", value = "ID of the group to view.",
@ -278,7 +311,15 @@ public interface GroupManagementService {
value = "Update a group.", value = "Update a group.",
notes = "If you wish to make changes to an existing group, that can be done by updating the group using " + notes = "If you wish to make changes to an existing group, that can be done by updating the group using " +
"this resource.", "this resource.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/update",
description = "Update Group") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Group has been updated successfully.", @ApiResponse(code = 200, message = "OK. \n Group has been updated successfully.",
responseHeaders = { responseHeaders = {
@ -310,7 +351,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while updating the group.", message = "Internal Server Error. \n Server error occurred while updating the group.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Update Group", permission = "/device-mgt/groups/update")
Response updateGroup(@ApiParam( Response updateGroup(@ApiParam(
name = "groupId", name = "groupId",
value = "ID of the group to be updated.", value = "ID of the group to be updated.",
@ -330,7 +370,15 @@ public interface GroupManagementService {
value = "Delete a group.", value = "Delete a group.",
notes = "If you wish to remove an existing group, that can be done by updating the group using " + notes = "If you wish to remove an existing group, that can be done by updating the group using " +
"this resource.", "this resource.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/remove",
description = "Remove Group") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Group has been deleted successfully.", @ApiResponse(code = 200, message = "OK. \n Group has been deleted successfully.",
responseHeaders = { responseHeaders = {
@ -362,7 +410,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while removing the group.", message = "Internal Server Error. \n Server error occurred while removing the group.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Remove Group", permission = "/device-mgt/groups/remove")
Response deleteGroup(@ApiParam( Response deleteGroup(@ApiParam(
name = "groupId", name = "groupId",
value = "ID of the group to be deleted.", value = "ID of the group to be deleted.",
@ -377,7 +424,15 @@ public interface GroupManagementService {
value = "Manage group sharing with a user.", value = "Manage group sharing with a user.",
notes = "If you wish to share /un share an existing group with a user under defined sharing roles, " + notes = "If you wish to share /un share an existing group with a user under defined sharing roles, " +
"that can be done using this resource.", "that can be done using this resource.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/share",
description = "Share Group") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Sharing has been updated successfully.", @ApiResponse(code = 200, message = "OK. \n Sharing has been updated successfully.",
responseHeaders = { responseHeaders = {
@ -409,7 +464,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while sharing the group.", message = "Internal Server Error. \n Server error occurred while sharing the group.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Share Group", permission = "/device-mgt/groups/share")
Response manageGroupSharing(@ApiParam( Response manageGroupSharing(@ApiParam(
name = "groupName", name = "groupName",
value = "Name of the group to be shared or unshared.", value = "Name of the group to be shared or unshared.",
@ -428,7 +482,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "View list of users of a device group.", value = "View list of users of a device group.",
notes = "Returns details of users which particular group has been shared with.", notes = "Returns details of users which particular group has been shared with.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/users/view",
description = "View users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the users.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the users.",
response = DeviceGroupUsersList.class, response = DeviceGroupUsersList.class,
@ -461,7 +523,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while fetching the users.", message = "Internal Server Error. \n Server error occurred while fetching the users.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View users", permission = "/device-mgt/groups/users/view")
Response getUsersOfGroup(@ApiParam( Response getUsersOfGroup(@ApiParam(
name = "groupId", name = "groupId",
value = "ID of the group.", value = "ID of the group.",
@ -476,7 +537,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "Create a group sharing role to a device group.", value = "Create a group sharing role to a device group.",
notes = "Group sharing is done through a group sharing role.", notes = "Group sharing is done through a group sharing role.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/roles/create",
description = "Create roles") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully created the role.", @ApiResponse(code = 200, message = "OK. \n Successfully created the role.",
response = DeviceGroupUsersList.class, response = DeviceGroupUsersList.class,
@ -509,7 +578,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while creating the role.", message = "Internal Server Error. \n Server error occurred while creating the role.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Create roles", permission = "/device-mgt/groups/roles/create")
Response createGroupSharingRole( Response createGroupSharingRole(
@ApiParam( @ApiParam(
name = "groupId", name = "groupId",
@ -534,7 +602,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "View list of roles of a device group.", value = "View list of roles of a device group.",
notes = "Returns details of roles which particular group has been shared with.", notes = "Returns details of roles which particular group has been shared with.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/roles/view",
description = "View roles") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the users.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the users.",
response = DeviceGroupUsersList.class, response = DeviceGroupUsersList.class,
@ -567,7 +643,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while fetching the roles.", message = "Internal Server Error. \n Server error occurred while fetching the roles.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View roles", permission = "/device-mgt/groups/roles/view")
Response getRolesOfGroup(@ApiParam( Response getRolesOfGroup(@ApiParam(
name = "groupId", name = "groupId",
value = "ID of the group.", value = "ID of the group.",
@ -586,7 +661,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "View list of devices in the device group.", value = "View list of devices in the device group.",
notes = "Returns list of devices in the device group.", notes = "Returns list of devices in the device group.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/view",
description = "View devices") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the devices.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the devices.",
response = DeviceList.class, response = DeviceList.class,
@ -619,7 +702,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while fetching the devices.", message = "Internal Server Error. \n Server error occurred while fetching the devices.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View devices", permission = "/device-mgt/groups/devices/view")
Response getDevicesOfGroup(@ApiParam( Response getDevicesOfGroup(@ApiParam(
name = "groupId", name = "groupId",
value = "ID of the group.", value = "ID of the group.",
@ -641,7 +723,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "View list of device count in the device group.", value = "View list of device count in the device group.",
notes = "Returns device count in the device group.", notes = "Returns device count in the device group.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/view",
description = "View devices") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device count.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device count.",
response = DeviceList.class, response = DeviceList.class,
@ -674,7 +764,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while fetching device count.", message = "Internal Server Error. \n Server error occurred while fetching device count.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View devices", permission = "/device-mgt/groups/devices/view")
Response getDeviceCountOfGroup(@ApiParam( Response getDeviceCountOfGroup(@ApiParam(
name = "groupId", name = "groupId",
value = "ID of the group.", value = "ID of the group.",
@ -688,7 +777,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_POST, httpMethod = HTTPConstants.HEADER_POST,
value = "Add devices to group.", value = "Add devices to group.",
notes = "Add existing devices to the device group.", notes = "Add existing devices to the device group.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/add",
description = "Add devices") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully add devices to the group.", @ApiResponse(code = 200, message = "OK. \n Successfully add devices to the group.",
responseHeaders = { responseHeaders = {
@ -720,7 +817,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while adding devices to the group.", message = "Internal Server Error. \n Server error occurred while adding devices to the group.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Add devices", permission = "/device-mgt/groups/devices/add")
Response addDevicesToGroup(@ApiParam( Response addDevicesToGroup(@ApiParam(
name = "groupId", name = "groupId",
value = "ID of the group.", value = "ID of the group.",
@ -739,7 +835,15 @@ public interface GroupManagementService {
httpMethod = HTTPConstants.HEADER_DELETE, httpMethod = HTTPConstants.HEADER_DELETE,
value = "Remove devices from group.", value = "Remove devices from group.",
notes = "Remove existing devices from the device group.", notes = "Remove existing devices from the device group.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/remove",
description = "Remove devices") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully removed devices from the group.", @ApiResponse(code = 200, message = "OK. \n Successfully removed devices from the group.",
responseHeaders = { responseHeaders = {
@ -771,7 +875,6 @@ public interface GroupManagementService {
message = "Internal Server Error. \n Server error occurred while removing devices from the group.", message = "Internal Server Error. \n Server error occurred while removing devices from the group.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Remove devices", permission = "/device-mgt/groups/devices/remove")
Response removeDevicesFromGroup(@ApiParam( Response removeDevicesFromGroup(@ApiParam(
name = "groupId", name = "groupId",
value = "ID of the group.", value = "ID of the group.",

@ -18,10 +18,19 @@
*/ */
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.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.API; import io.swagger.annotations.Info;
import org.wso2.carbon.apimgt.annotations.api.Permission; import io.swagger.annotations.ExtensionProperty;
import org.wso2.carbon.apimgt.annotations.api.Scope; import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
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.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;
@ -35,8 +44,22 @@ import javax.ws.rs.core.Response;
/** /**
* Notifications related REST-API. * Notifications related REST-API.
*/ */
@API(name = "DeviceNotificationManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/notifications",
tags = {"device_management"}) @SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "DeviceNotificationManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/notifications"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@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")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -49,7 +72,15 @@ public interface NotificationManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting All Device Notification Details", value = "Getting All Device Notification Details",
notes = "Get the details of all the notifications that were pushed to the devices registered with WSO2 EMM using this REST API.", notes = "Get the details of all the notifications that were pushed to the devices registered with WSO2 EMM using this REST API.",
tags = "Device Notification Management") tags = "Device Notification Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/notifications/view",
description = "View notifications") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -71,7 +102,8 @@ public interface NotificationManagementService {
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."), message = "Not Modified. \n Empty body because the client already has the latest version " +
"of the requested resource."),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid notification status type received. \n" + message = "Bad Request. \n Invalid notification status type received. \n" +
@ -90,7 +122,6 @@ public interface NotificationManagementService {
"\n Server error occurred while fetching the notification list.", "\n Server error occurred while fetching the notification list.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View notifications", permission = "/device-mgt/notifications/view")
Response getNotifications( Response getNotifications(
@ApiParam( @ApiParam(
name = "status", name = "status",
@ -132,7 +163,15 @@ public interface NotificationManagementService {
value = "Updating the Device Notification Status", value = "Updating the Device Notification Status",
notes = "When a user has read the the device notification the device notification status must " notes = "When a user has read the the device notification the device notification status must "
+ "change from NEW to CHECKED. This API is used to update device notification status.", + "change from NEW to CHECKED. This API is used to update device notification status.",
tags = "Device Notification Management") tags = "Device Notification Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/notifications/view",
description = "View notifications") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -149,7 +188,6 @@ public interface NotificationManagementService {
message = "Error occurred while updating notification status.") message = "Error occurred while updating notification status.")
} }
) )
@Permission(name = "View notifications", permission = "/device-mgt/notifications/view")
Response updateNotificationStatus( Response updateNotificationStatus(
@ApiParam( @ApiParam(
name = "id", name = "id",

@ -18,10 +18,19 @@
*/ */
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.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.API; import io.swagger.annotations.Info;
import org.wso2.carbon.apimgt.annotations.api.Permission; import io.swagger.annotations.ExtensionProperty;
import org.wso2.carbon.apimgt.annotations.api.Scope; import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
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.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
@ -37,9 +46,22 @@ 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 = "DevicePolicyManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/policies",
tags = {"device_management"})
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "DevicePolicyManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/policies"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@Api(value = "Device Policy Management", description = "This API includes the functionality around device policy management") @Api(value = "Device Policy Management", description = "This API includes the functionality around device policy management")
@Path("/policies") @Path("/policies")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -54,7 +76,15 @@ public interface PolicyManagementService {
value = "Adding a Policy", value = "Adding a Policy",
notes = "Add a policy using this REST API command. When adding a policy you will have the option of saving the policy or saving and publishing the policy." + notes = "Add a policy using this REST API command. When adding a policy you will have the option of saving the policy or saving and publishing the policy." +
"Using this REST API you are able to save a created Policy and this policy will be in the inactive state.", "Using this REST API you are able to save a created Policy and this policy will be in the inactive state.",
tags = "Device Policy Management") tags = "Device Policy Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage",
description = "Manage policies") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -101,7 +131,6 @@ public interface PolicyManagementService {
"Server error occurred while adding a new policy.", "Server error occurred while adding a new policy.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage policies", permission = "/device-mgt/policies/manage")
Response addPolicy( Response addPolicy(
@ApiParam( @ApiParam(
name = "policy", name = "policy",
@ -117,7 +146,15 @@ public interface PolicyManagementService {
responseContainer = "List", responseContainer = "List",
notes = "Retrieve the details of all the policies in WSO2 EMM.", notes = "Retrieve the details of all the policies in WSO2 EMM.",
response = Policy.class, response = Policy.class,
tags = "Device Policy Management") tags = "Device Policy Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/policies/view",
description = "View policies") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -154,7 +191,6 @@ public interface PolicyManagementService {
message = ("Internal Server Error. \n Server error occurred while fetching the policies."), message = ("Internal Server Error. \n Server error occurred while fetching the policies."),
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View policies", permission = "/device-mgt/policies/view")
Response getPolicies( Response getPolicies(
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",
@ -187,7 +223,15 @@ public interface PolicyManagementService {
value = "Getting Details of a Policy", value = "Getting Details of a Policy",
notes = "Retrieve the details of a policy that is in WSO2 EMM.", notes = "Retrieve the details of a policy that is in WSO2 EMM.",
response = Policy.class, response = Policy.class,
tags = "Device Policy Management") tags = "Device Policy Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/policies/view",
description = "View policies") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -224,7 +268,6 @@ public interface PolicyManagementService {
"policy.", "policy.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View policies", permission = "/device-mgt/policies/view")
Response getPolicy( Response getPolicy(
@ApiParam( @ApiParam(
name = "id", name = "id",
@ -250,7 +293,15 @@ public interface PolicyManagementService {
httpMethod = "PUT", httpMethod = "PUT",
value = "Updating a Policy", value = "Updating a Policy",
notes = "Make changes to an existing policy by updating the policy using this resource.", notes = "Make changes to an existing policy by updating the policy using this resource.",
tags = "Device Policy Management") tags = "Device Policy Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage",
description = "Manage policies") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -290,7 +341,6 @@ public interface PolicyManagementService {
"Server error occurred while updating the policy.", "Server error occurred while updating the policy.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage policies", permission = "/device-mgt/policies/manage")
Response updatePolicy( Response updatePolicy(
@ApiParam( @ApiParam(
name = "id", name = "id",
@ -313,7 +363,15 @@ public interface PolicyManagementService {
httpMethod = "POST", httpMethod = "POST",
value = "Removing Multiple Policies", value = "Removing Multiple Policies",
notes = "Delete one or more than one policy using this API.", notes = "Delete one or more than one policy using this API.",
tags = "Device Policy Management") tags = "Device Policy Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage",
description = "Manage policies") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -337,7 +395,6 @@ public interface PolicyManagementService {
"Server error occurred whilst bulk removing policies.", "Server error occurred whilst bulk removing policies.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage policies", permission = "/device-mgt/policies/manage")
Response removePolicies( Response removePolicies(
@ApiParam( @ApiParam(
name = "policyIds", name = "policyIds",
@ -354,7 +411,15 @@ public interface PolicyManagementService {
httpMethod = "POST", httpMethod = "POST",
value = "Activating Policies", value = "Activating Policies",
notes = "Publish a policy using this API to bring a policy that is in the inactive state to the active state.", notes = "Publish a policy using this API to bring a policy that is in the inactive state to the active state.",
tags = "Device Policy Management") tags = "Device Policy Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage",
description = "Manage policies") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -373,7 +438,6 @@ public interface PolicyManagementService {
message = "Sever error whilst activating the policies.", message = "Sever error whilst activating the policies.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage policies", permission = "/device-mgt/policies/manage")
Response activatePolicies( Response activatePolicies(
@ApiParam( @ApiParam(
name = "policyIds", name = "policyIds",
@ -390,7 +454,15 @@ public interface PolicyManagementService {
httpMethod = "POST", httpMethod = "POST",
value = "Deactivating Policies", value = "Deactivating Policies",
notes = "Unpublish a policy using this API to bring a policy that is in the active state to the inactive state.", notes = "Unpublish a policy using this API to bring a policy that is in the active state to the inactive state.",
tags = "Device Policy Management") tags = "Device Policy Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage",
description = "Manage policies") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -409,7 +481,6 @@ public interface PolicyManagementService {
message = "ErrorResponse in deactivating policies.", message = "ErrorResponse in deactivating policies.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage policies", permission = "/device-mgt/policies/manage")
Response deactivatePolicies( Response deactivatePolicies(
@ApiParam( @ApiParam(
name = "policyIds", name = "policyIds",
@ -431,7 +502,14 @@ public interface PolicyManagementService {
" policies (removing, activating, deactivating and updating) or add new policies, the existing" + " policies (removing, activating, deactivating and updating) or add new policies, the existing" +
" devices will not receive these changes immediately. Once all the required changes are made" + " devices will not receive these changes immediately. Once all the required changes are made" +
" you need to apply the changes to push the policy changes to the existing devices.", " you need to apply the changes to push the policy changes to the existing devices.",
tags = "Device Policy Management" tags = "Device Policy Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage",
description = "Manage policies") }
)
}
) )
@ApiResponses( @ApiResponses(
value = { value = {
@ -443,7 +521,6 @@ public interface PolicyManagementService {
message = "ErrorResponse in deactivating policies.", message = "ErrorResponse in deactivating policies.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage policies", permission = "/device-mgt/policies/manage")
Response applyChanges(); Response applyChanges();
@ -455,7 +532,14 @@ public interface PolicyManagementService {
httpMethod = "PUT", httpMethod = "PUT",
value = "Updating the Policy Priorities", value = "Updating the Policy Priorities",
notes = "Make changes to the existing policy priority order by updating the priority order using this API.", notes = "Make changes to the existing policy priority order by updating the priority order using this API.",
tags = "Device Policy Management" tags = "Device Policy Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage",
description = "Manage policies") }
)
}
) )
@ApiResponses( @ApiResponses(
value = { value = {
@ -471,7 +555,6 @@ public interface PolicyManagementService {
message = "Exception in updating the policy priorities.", message = "Exception in updating the policy priorities.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage policies", permission = "/device-mgt/policies/manage")
Response updatePolicyPriorities( Response updatePolicyPriorities(
@ApiParam( @ApiParam(
name = "priorityUpdatedPolicies", name = "priorityUpdatedPolicies",

@ -18,13 +18,22 @@
*/ */
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.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.API; import io.swagger.annotations.Info;
import org.wso2.carbon.apimgt.annotations.api.Permission; import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
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.user.mgt.common.UIPermissionNode; import org.wso2.carbon.user.mgt.common.UIPermissionNode;
import javax.ws.rs.*; import javax.ws.rs.*;
@ -32,8 +41,21 @@ 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 = "RoleManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/roles", tags = {"device_management"}) @SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "RoleManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/roles"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@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.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -47,7 +69,14 @@ public interface RoleManagementService {
value = "Getting the List of Roles", value = "Getting the List of Roles",
notes = "WSO2 EMM supports role-based access control (RBAC) and role management. Using this API you can the list of roles that are in WSO2 EMM.\n" + notes = "WSO2 EMM supports role-based access control (RBAC) and role management. Using this API you can the list of roles that are in WSO2 EMM.\n" +
"Note: Internal roles, roles created for service-providers, and application related roles will not be given in the output.", "Note: Internal roles, roles created for service-providers, and application related roles will not be given in the output.",
tags = "Role Management") tags = "Role Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", description = "View Roles") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -78,7 +107,6 @@ public interface RoleManagementService {
message = "Internal Server Error. \n Server error occurred while fetching list of roles.", message = "Internal Server Error. \n Server error occurred while fetching list of roles.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Roles", permission = "/device-mgt/roles/view")
Response getRoles( Response getRoles(
@ApiParam( @ApiParam(
name = "filter", name = "filter",
@ -122,7 +150,13 @@ public interface RoleManagementService {
"so using this REST API.", "so using this REST API.",
response = UIPermissionNode.class, response = UIPermissionNode.class,
responseContainer = "List", responseContainer = "List",
tags = "Role Management" tags = "Role Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", description = "View Roles") }
)
}
) )
@ApiResponses( @ApiResponses(
value = { value = {
@ -164,7 +198,6 @@ public interface RoleManagementService {
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the permission list for the requested role.", message = "Internal Server ErrorResponse. \n Server error occurred while fetching the permission list for the requested role.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Roles", permission = "/device-mgt/roles/view")
Response getPermissionsOfRole( Response getPermissionsOfRole(
@ApiParam( @ApiParam(
name = "roleName", name = "roleName",
@ -193,7 +226,15 @@ public interface RoleManagementService {
value = "Getting Details of a Role", value = "Getting Details of a Role",
notes = "Get the permissions associated with a role and role specific details using this REST API.", notes = "Get the permissions associated with a role and role specific details using this REST API.",
response = RoleInfo.class, response = RoleInfo.class,
tags = "Role Management") tags = "Role Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view",
description = "View Roles") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -234,7 +275,6 @@ public interface RoleManagementService {
"requested role.", "requested role.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Roles", permission = "/device-mgt/roles/view")
Response getRole( Response getRole(
@ApiParam( @ApiParam(
name = "roleName", name = "roleName",
@ -262,7 +302,15 @@ public interface RoleManagementService {
httpMethod = "POST", httpMethod = "POST",
value = "Adding a Role", value = "Adding a Role",
notes = "WSO2 EMM supports role-based access control (RBAC) and role management. Add a new role to WSO2 EMM using this REST API.", notes = "WSO2 EMM supports role-based access control (RBAC) and role management. Add a new role to WSO2 EMM using this REST API.",
tags = "Role Management") tags = "Role Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage",
description = "Manage Roles") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 201, code = 201,
@ -302,7 +350,6 @@ 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(name = "Manage Roles", permission = "/device-mgt/roles/manage")
Response addRole( Response addRole(
@ApiParam( @ApiParam(
name = "role", name = "role",
@ -318,7 +365,15 @@ public interface RoleManagementService {
value = "Updating Role Details", value = "Updating Role Details",
notes = "There will be situations where you need to update the role details, such as the permissions" + notes = "There will be situations where you need to update the role details, such as the permissions" +
" or the role name. Update the role details using this REST API.", " or the role name. Update the role details using this REST API.",
tags = "Role Management") tags = "Role Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage",
description = "Manage Roles") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -352,7 +407,6 @@ 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(name = "Manage Roles", permission = "/device-mgt/roles/manage")
Response updateRole( Response updateRole(
@ApiParam( @ApiParam(
name = "roleName", name = "roleName",
@ -379,7 +433,15 @@ public interface RoleManagementService {
value = "Deleting a Role", value = "Deleting a Role",
notes = "Roles become obsolete over time due to various reasons. In a situation where your Organization identifies that a specific role is no longer required, you " + notes = "Roles become obsolete over time due to various reasons. In a situation where your Organization identifies that a specific role is no longer required, you " +
"can delete a role using this REST API.", "can delete a role using this REST API.",
tags = "Role Management") tags = "Role Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage",
description = "Manage Roles") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -397,7 +459,6 @@ 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(name = "Manage Roles", permission = "/device-mgt/roles/manage")
Response deleteRole( Response deleteRole(
@ApiParam( @ApiParam(
name = "roleName", name = "roleName",
@ -424,7 +485,15 @@ public interface RoleManagementService {
"Example: Your Organization hires 30 new engineers. Updating the role details for each user can " + "Example: Your Organization hires 30 new engineers. Updating the role details for each user can " +
"be cumbersome. Therefore, you can define all the new employees that belong to the engineering " + "be cumbersome. Therefore, you can define all the new employees that belong to the engineering " +
"role using this API.", "role using this API.",
tags = "Role Management") tags = "Role Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage",
description = "Manage Roles") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -461,7 +530,6 @@ public interface RoleManagementService {
"Server error occurred while adding the user to the specified role.", "Server error occurred while adding the user to the specified role.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage Roles", permission = "/device-mgt/roles/manage")
Response updateUsersOfRole( Response updateUsersOfRole(
@ApiParam( @ApiParam(
name = "roleName", name = "roleName",

@ -18,9 +18,19 @@
*/ */
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.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.API; import io.swagger.annotations.Info;
import org.wso2.carbon.apimgt.annotations.api.Permission; import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
import org.wso2.carbon.device.mgt.jaxrs.beans.*; import org.wso2.carbon.device.mgt.jaxrs.beans.*;
import javax.ws.rs.*; import javax.ws.rs.*;
@ -28,9 +38,21 @@ 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;
@SwaggerDefinition(
@API(name = "UserManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/users", tags = {"device_management"}) info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "UserManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/users"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@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.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -44,7 +66,15 @@ public interface UserManagementService {
httpMethod = "POST", httpMethod = "POST",
value = "Adding a User", value = "Adding a User",
notes = "WSO2 EMM supports user management. Add a new user to the WSO2 EMM user management system via this REST API", notes = "WSO2 EMM supports user management. Add a new user to the WSO2 EMM user management system via this REST API",
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage",
description = "Manage Users") }
)
}
)
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
@ -83,7 +113,6 @@ 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(name = "Manage Users", permission = "/device-mgt/users/manage")
Response addUser( Response addUser(
@ApiParam( @ApiParam(
name = "user", name = "user",
@ -99,7 +128,15 @@ public interface UserManagementService {
value = "Getting Details of a User", value = "Getting Details of a User",
notes = "Get the details of a user registered with WSO2 EMM using the REST API.", notes = "Get the details of a user registered with WSO2 EMM using the REST API.",
response = BasicUserInfo.class, response = BasicUserInfo.class,
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/view",
description = "View Users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -135,7 +172,6 @@ public interface UserManagementService {
" fetching the ruser details.", " fetching the ruser details.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Users", permission = "/device-mgt/users/view")
Response getUser( Response getUser(
@ApiParam( @ApiParam(
name = "username", name = "username",
@ -165,7 +201,15 @@ public interface UserManagementService {
value = "Updating Details of a User", value = "Updating Details of a User",
notes = "There will be situations where you will want to update the user details. In such " notes = "There will be situations where you will want to update the user details. In such "
+ "situation you can update the user details using this REST API.", + "situation you can update the user details using this REST API.",
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage",
description = "Manage Users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -200,7 +244,6 @@ public interface UserManagementService {
"Server error occurred while updating the user.", "Server error occurred while updating the user.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage Users", permission = "/device-mgt/users/manage")
Response updateUser( Response updateUser(
@ApiParam( @ApiParam(
name = "username", name = "username",
@ -225,7 +268,15 @@ public interface UserManagementService {
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Deleting a User", value = "Deleting a User",
notes = "When an employee leaves the organization, you can remove the user details from WSO2 EMM using this REST API.", notes = "When an employee leaves the organization, you can remove the user details from WSO2 EMM using this REST API.",
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage",
description = "Manage Users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -241,7 +292,6 @@ public interface UserManagementService {
response = ErrorResponse.class response = ErrorResponse.class
) )
}) })
@Permission(name = "Manage Users", permission = "/device-mgt/users/manage")
Response removeUser( Response removeUser(
@ApiParam( @ApiParam(
name = "username", name = "username",
@ -263,7 +313,15 @@ public interface UserManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting the Role Details of a User", value = "Getting the Role Details of a User",
notes = "A user can be assigned to one or more role in EMM. Using this REST API you can get the role/roles a user is assigned to.", notes = "A user can be assigned to one or more role in EMM. Using this REST API you can get the role/roles a user is assigned to.",
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/view",
description = "View Users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -299,7 +357,6 @@ public interface UserManagementService {
" assigned to the specified user.", " assigned to the specified user.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Users", permission = "/device-mgt/users/view")
Response getRolesOfUser( Response getRolesOfUser(
@ApiParam( @ApiParam(
name = "username", name = "username",
@ -320,7 +377,15 @@ public interface UserManagementService {
value = "Getting Details of Users", value = "Getting Details of Users",
notes = "You are able to manage users in WSO2 EMM by adding, updating and removing users. If you wish to get the list of users registered with WSO2 EMM, you can do so " notes = "You are able to manage users in WSO2 EMM by adding, updating and removing users. If you wish to get the list of users registered with WSO2 EMM, you can do so "
+ "using this REST API", + "using this REST API",
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/view",
description = "View Users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -341,7 +406,8 @@ public interface UserManagementService {
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource.\n"), message = "Not Modified. \n Empty body because the client already has the latest version of " +
"the requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable.\n The requested media type is not supported", message = "Not Acceptable.\n The requested media type is not supported",
@ -351,7 +417,6 @@ public interface UserManagementService {
message = "Internal Server Error. \n Server error occurred while fetching the list of WSO2 EMM users.", message = "Internal Server Error. \n Server error occurred while fetching the list of WSO2 EMM users.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Users", permission = "/device-mgt/users/view")
Response getUsers( Response getUsers(
@ApiParam( @ApiParam(
name = "filter", name = "filter",
@ -385,7 +450,14 @@ public interface UserManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting the User Count", value = "Getting the User Count",
notes = "Get the number of users in WSO2 EMM via this REST API.", notes = "Get the number of users in WSO2 EMM via this REST API.",
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", description = "View Users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -405,7 +477,6 @@ public interface UserManagementService {
message = "Internal Server Error. \n Server error occurred while fetching the total number of users in WSO2 EMM.", message = "Internal Server Error. \n Server error occurred while fetching the total number of users in WSO2 EMM.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Users", permission = "/device-mgt/users/view")
Response getUserCount(); Response getUserCount();
@GET @GET
@ -415,7 +486,15 @@ public interface UserManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting the User existence status", value = "Getting the User existence status",
notes = "Check if the user exists in the user store.", notes = "Check if the user exists in the user store.",
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/view",
description = "View Users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -432,10 +511,10 @@ public interface UserManagementService {
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the total user exist status.", message = "Internal Server Error. \n Server error occurred while fetching the " +
"total user exist status.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Users", permission = "/device-mgt/users/view")
Response isUserExists(@ApiParam( Response isUserExists(@ApiParam(
name = "username", name = "username",
value = "The username of the user.", value = "The username of the user.",
@ -452,7 +531,14 @@ public interface UserManagementService {
+ "search for that user by giving a character or a few characters in the username. " + "search for that user by giving a character or a few characters in the username. "
+ "You will be given a list of users having the user name in the exact order of the " + "You will be given a list of users having the user name in the exact order of the "
+ "characters you provided.", + "characters you provided.",
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", description = "View Users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -484,7 +570,6 @@ public interface UserManagementService {
message = "Internal Server Error. \n Server error occurred while fetching the list of users that matched the given filter.", message = "Internal Server Error. \n Server error occurred while fetching the list of users that matched the given filter.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Users", permission = "/device-mgt/users/view")
Response getUserNames( Response getUserNames(
@ApiParam( @ApiParam(
name = "filter", name = "filter",
@ -524,7 +609,14 @@ public interface UserManagementService {
httpMethod = "PUT", httpMethod = "PUT",
value = "Changing the User Password", value = "Changing the User Password",
notes = "A user is able to change the password to secure their WSO2 EMM profile via this REST API.", notes = "A user is able to change the password to secure their WSO2 EMM profile via this REST API.",
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/login", description = "Reset user password") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -547,7 +639,6 @@ public interface UserManagementService {
"Server error occurred while updating the user credentials.", "Server error occurred while updating the user credentials.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Reset user password", permission = "/login")
Response resetPassword( Response resetPassword(
@ApiParam( @ApiParam(
name = "credentials", name = "credentials",
@ -564,7 +655,14 @@ public interface UserManagementService {
value = "Sending Enrollment Invitations to Users", value = "Sending Enrollment Invitations to Users",
notes = "Send the users a mail inviting them to download the EMM mobile application on their devices using the REST API given below.\n" + notes = "Send the users a mail inviting them to download the EMM mobile application on their devices using the REST API given below.\n" +
"Before running the REST API command to send the enrollment invitations to users make sure to configure WSO2 EMM as explained in step 4, under the WSO2 EMM general server configurations documentation.", "Before running the REST API command to send the enrollment invitations to users make sure to configure WSO2 EMM as explained in step 4, under the WSO2 EMM general server configurations documentation.",
tags = "User Management") tags = "User Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", description = "Manage Users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -587,7 +685,6 @@ public interface UserManagementService {
"Server error occurred while updating the user credentials.", "Server error occurred while updating the user credentials.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Manage Users", permission = "/device-mgt/users/manage")
Response inviteExistingUsersToEnrollDevice( Response inviteExistingUsersToEnrollDevice(
@ApiParam( @ApiParam(
name = "users", name = "users",

@ -19,9 +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.API;
import org.wso2.carbon.apimgt.annotations.api.Permission; 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.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;
@ -33,8 +31,21 @@ 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 = "ApplicationManagementAdmin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/applications", tags = {"device_management"}) @SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "ApplicationManagementAdmin"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/admin/applications"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@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 " +
"'internal' components to log in as an admin user and do a selected number of operations. " + "'internal' components to log in as an admin user and do a selected number of operations. " +
@ -52,7 +63,15 @@ public interface ApplicationManagementAdminService {
value = "Installing an Application (Internal API)", value = "Installing an Application (Internal API)",
notes = "This is an internal API that can be used to install an application on a device.", notes = "This is an internal API that can be used to install an application on a device.",
response = Activity.class, response = Activity.class,
tags = "Application Management Administrative Service") tags = "Application Management Administrative Service",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/applications/manage", description
= "Install/Uninstall applications") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 202, code = 202,
@ -75,7 +94,6 @@ public interface ApplicationManagementAdminService {
" for a specified set of devices.", " for a specified set of devices.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Install/Uninstall applications", permission = "/device-mgt/applications/manage")
Response installApplication( Response installApplication(
@ApiParam( @ApiParam(
name = "applicationWrapper", name = "applicationWrapper",
@ -91,7 +109,15 @@ public interface ApplicationManagementAdminService {
value = "Uninstalling an Application (Internal API)\n", value = "Uninstalling an Application (Internal API)\n",
notes = "This is an internal API that can be used to uninstall an application.", notes = "This is an internal API that can be used to uninstall an application.",
response = Activity.class, response = Activity.class,
tags = "Application Management Administrative Service") tags = "Application Management Administrative Service",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/applications/manage", description
= "Install/Uninstall applications") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 202, code = 202,
@ -109,11 +135,10 @@ public interface ApplicationManagementAdminService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while executing the application install operation in bulk" + message = "Internal Server Error. \n Server error occurred while executing the application install" +
" for a specified set of devices.", " operation in bulk for a specified set of devices.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "Install/Uninstall applications", permission = "/device-mgt/applications/manage")
Response uninstallApplication( Response uninstallApplication(
@ApiParam( @ApiParam(
name = "applicationWrapper", name = "applicationWrapper",

@ -18,9 +18,19 @@
*/ */
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.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.API; import io.swagger.annotations.Info;
import org.wso2.carbon.apimgt.annotations.api.Permission; import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
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;
@ -29,8 +39,21 @@ 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 = "/api/device-mgt/v1.0/admin/devices", @SwaggerDefinition(
tags = {"device_management"}) info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "DeviceManagementAdmin"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/admin/devices"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@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 " +
"'internal' components to log in as an admin user and do a selected number of operations. " + "'internal' components to log in as an admin user and do a selected number of operations. " +
@ -47,7 +70,15 @@ public interface DeviceManagementAdminService {
notes = "Get the details of a device by searching via the device name, device type and the tenant domain.", notes = "Get the details of a device by searching via the device name, device type and the tenant domain.",
response = Device.class, response = Device.class,
responseContainer = "List", responseContainer = "List",
tags = "Device Management Administrative Service") tags = "Device Management Administrative Service",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", description
= "View Devices") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.",
response = Device.class, response = Device.class,
@ -67,7 +98,8 @@ public interface DeviceManagementAdminService {
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. Empty body because the client already has the latest version of the requested resource.\n"), message = "Not Modified. Empty body because the client already has the latest version of the " +
"requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 401, code = 401,
message = "Unauthorized.\n The unauthorized access to the requested resource.", message = "Unauthorized.\n The unauthorized access to the requested resource.",
@ -84,11 +116,11 @@ 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)
}) })
@Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view")
Response getDevicesByName( Response getDevicesByName(
@ApiParam( @ApiParam(
name = "name", name = "name",
value = "The name of the device.If you are unsure of the name of the device, run the GET /devices API that is under Device Management.", value = "The name of the device.If you are unsure of the name of the device, run the GET /devices" +
" API that is under Device Management.",
required = true) required = true)
@QueryParam("name") @QueryParam("name")
@Size(max = 45) @Size(max = 45)
@ -127,5 +159,4 @@ public interface DeviceManagementAdminService {
required = false, required = false,
defaultValue = "5") defaultValue = "5")
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
} }

@ -19,28 +19,42 @@
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Info;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation; 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 io.swagger.annotations.ResponseHeader; import io.swagger.annotations.ResponseHeader;
import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axis2.transport.http.HTTPConstants;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import javax.ws.rs.Consumes; import javax.ws.rs.*;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
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;
@API(name = "GroupManagementAdmin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/groups", tags = {"device_management"}) @SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "GroupManagementAdmin"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/admin/groups"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@Path("/admin/groups") @Path("/admin/groups")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ -55,7 +69,15 @@ public interface GroupManagementAdminService {
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "Get the list of groups.", value = "Get the list of groups.",
notes = "Returns all groups enrolled with the system.", notes = "Returns all groups enrolled with the system.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/admin/groups/view", description
= "View Groups") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of device groups.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of device groups.",
response = DeviceGroupList.class, response = DeviceGroupList.class,
@ -88,7 +110,6 @@ public interface GroupManagementAdminService {
message = "Internal Server Error. \n Server error occurred while fetching the groups list.", message = "Internal Server Error. \n Server error occurred while fetching the groups list.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Groups", permission = "/device-mgt/admin/groups/view")
Response getGroups(@ApiParam( Response getGroups(@ApiParam(
name = "name", name = "name",
value = "Name of the group.") value = "Name of the group.")
@ -113,7 +134,15 @@ public interface GroupManagementAdminService {
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "Get the count of groups belongs to current user.", value = "Get the count of groups belongs to current user.",
notes = "Returns count of all permitted groups enrolled with the system.", notes = "Returns count of all permitted groups enrolled with the system.",
tags = "Device Group Management") tags = "Device Group Management",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/admin/groups/view", description
= "View Groups") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.",
response = DeviceGroupList.class, response = DeviceGroupList.class,
@ -146,7 +175,6 @@ public interface GroupManagementAdminService {
message = "Internal Server Error. \n Server error occurred while fetching the group count.", message = "Internal Server Error. \n Server error occurred while fetching the group count.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
@Permission(name = "View Groups", permission = "/device-mgt/admin/groups/view")
Response getGroupCount(); Response getGroupCount();
} }

@ -18,10 +18,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.SwaggerDefinition;
import org.wso2.carbon.apimgt.annotations.api.API; import io.swagger.annotations.Info;
import org.wso2.carbon.apimgt.annotations.api.Permission; import io.swagger.annotations.ExtensionProperty;
import org.wso2.carbon.apimgt.annotations.api.Scope; import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
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;
@ -30,8 +38,21 @@ 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 = "UserManagementAdmin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/users", tags = {"device_management"}) @SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "UserManagementAdmin"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/admin/users"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@Path("/admin/users") @Path("/admin/users")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ -49,7 +70,15 @@ public interface UserManagementAdminService {
value = "Changing the User Password.", value = "Changing the User Password.",
notes = "The EMM administrator is able to change the password of the users in " + notes = "The EMM administrator is able to change the password of the users in " +
"the system and block them from logging into their EMM profile using this REST API.", "the system and block them from logging into their EMM profile using this REST API.",
tags = "User Management Administrative Service") tags = "User Management Administrative Service",
authorizations = {
@Authorization(
value="permission",
scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", description
= "View Users") }
)
}
)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -70,7 +99,6 @@ 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(name = "View Users", permission = "/device-mgt/users/manage")
Response resetUserPassword( Response resetUserPassword(
@ApiParam( @ApiParam(
name = "username", name = "username",

@ -18,10 +18,11 @@
package org.wso2.carbon.device.mgt.core.config.permission; package org.wso2.carbon.device.mgt.core.config.permission;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.models.Swagger;
import org.apache.catalina.core.StandardContext; import org.apache.catalina.core.StandardContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.device.mgt.common.permission.mgt.Permission; import org.wso2.carbon.device.mgt.common.permission.mgt.Permission;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -55,16 +56,43 @@ public class AnnotationProcessor {
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";
private static final String SWAGGER_ANNOTATIONS_AUTHORIZATIONS = "authorizations";
private static final String SWAGGER_ANNOTATIONS_PERMISSION = "permission";
private static final String SWAGGER_ANNOTATIONS_SCOPES = "scopes";
private static final String SWAGGER_ANNOTATIONS_SCOPE = "scope";
private static final String SWAGGER_ANNOTATIONS_DESCRIPTION = "description";
private StandardContext context;
private Method[] pathClazzMethods; private Method[] pathClazzMethods;
private Class<Path> pathClazz; private Class<Path> pathClazz;
Class<API> apiClazz;
private ClassLoader classLoader; private ClassLoader classLoader;
private ServletContext servletContext; private ServletContext servletContext;
private Swagger swagger;
private Class<SwaggerDefinition> apiClazz;
private Class<Consumes> consumesClass;
private Class<Produces> producesClass;
private Class<io.swagger.annotations.ApiOperation> apiOperation;
private Class<io.swagger.annotations.Authorization> authorizationClass;
private Class<io.swagger.annotations.AuthorizationScope> authorizationScopeClass;
public AnnotationProcessor(final StandardContext context) { public AnnotationProcessor(final StandardContext context) {
servletContext = context.getServletContext(); servletContext = context.getServletContext();
classLoader = servletContext.getClassLoader(); classLoader = servletContext.getClassLoader();
try {
pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
consumesClass = (Class<Consumes>) classLoader.loadClass(Consumes.class.getName());
producesClass = (Class<Produces>) classLoader.loadClass(Produces.class.getName());
apiClazz= (Class<SwaggerDefinition>)classLoader.loadClass((SwaggerDefinition.class.getName()));
apiOperation = (Class<io.swagger.annotations.ApiOperation>)classLoader
.loadClass((io.swagger.annotations.ApiOperation.class.getName()));
authorizationClass = (Class<io.swagger.annotations.Authorization>)classLoader
.loadClass((io.swagger.annotations.Authorization.class.getName()));
authorizationScopeClass = (Class<io.swagger.annotations.AuthorizationScope>)classLoader
.loadClass((io.swagger.annotations.AuthorizationScope.class.getName()));
} catch (ClassNotFoundException e) {
log.error("An error has occurred while loading classes ", e);
}
} }
/** /**
@ -91,8 +119,7 @@ public class AnnotationProcessor {
* @param entityClasses * @param entityClasses
* @return * @return
*/ */
public List<Permission> public List<Permission> extractPermissions(Set<String> entityClasses) {
extractPermissions(Set<String> entityClasses) {
List<Permission> permissions = new ArrayList<>(); List<Permission> permissions = new ArrayList<>();
@ -107,25 +134,15 @@ public class AnnotationProcessor {
List<Permission> apiPermissions = new ArrayList<>(); List<Permission> apiPermissions = new ArrayList<>();
try { try {
clazz = classLoader.loadClass(className); clazz = classLoader.loadClass(className);
apiClazz = (Class<API>)
classLoader.loadClass(org.wso2.carbon.apimgt.annotations.api.API
.class.getName());
Annotation apiAnno = clazz.getAnnotation(apiClazz); Annotation apiAnno = clazz.getAnnotation(apiClazz);
List<Permission> resourceList; List<Permission> resourceList;
if (apiAnno != null) { if (apiAnno != null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Application Context root = " + servletContext.getContextPath()); log.debug("Application Context root = " + servletContext.getContextPath());
} }
try { try {
String rootContext = servletContext.getContextPath(); String rootContext = servletContext.getContextPath();
pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
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) {
@ -141,7 +158,6 @@ public class AnnotationProcessor {
log.debug("API Root Context = " + rootContext); log.debug("API Root Context = " + rootContext);
} }
} }
Method[] annotatedMethods = clazz.getDeclaredMethods(); Method[] annotatedMethods = clazz.getDeclaredMethods();
apiPermissions = getApiResources(rootContext, annotatedMethods); apiPermissions = getApiResources(rootContext, annotatedMethods);
} catch (Throwable throwable) { } catch (Throwable throwable) {
@ -200,12 +216,11 @@ public class AnnotationProcessor {
permission.setMethod(httpMethod); permission.setMethod(httpMethod);
} }
if (annotations[i].annotationType().getName(). if (annotations[i].annotationType().getName().
equals(org.wso2.carbon.apimgt.annotations.api.Permission.class.getName())) { equals(io.swagger.annotations.ApiOperation.class.getName())) {
this.setPermission(method, permission); this.setPermission(annotations[i], permission);
} }
} }
permissions.add(permission); permissions.add(permission);
} }
} }
return permissions; return permissions;
@ -325,24 +340,30 @@ public class AnnotationProcessor {
return replacedPath.toString(); return replacedPath.toString();
} }
private void setPermission(Method currentMethod, Permission permission) throws Throwable { private void setPermission(Annotation currentMethod, Permission permission) throws Throwable {
Class<org.wso2.carbon.apimgt.annotations.api.Permission> permissionClass = InvocationHandler methodHandler = Proxy.getInvocationHandler(currentMethod);
(Class<org.wso2.carbon.apimgt.annotations.api.Permission>) classLoader. Annotation[] authorizations = (Annotation[]) methodHandler.invoke(currentMethod
loadClass(org.wso2.carbon.apimgt.annotations.api.Permission.class.getName()); , apiOperation.getMethod(SWAGGER_ANNOTATIONS_AUTHORIZATIONS,null),null);
Annotation permissionAnnotation = currentMethod.getAnnotation(permissionClass); for(int i=0; i<authorizations.length; i++){
if (permissionClass != null) { methodHandler = Proxy.getInvocationHandler(authorizations[i]);
Method[] permissionClassMethods = permissionClass.getMethods(); String value =(String)methodHandler.invoke(authorizations[i], authorizationClass.getMethod("value", null)
for (Method method : permissionClassMethods) { ,null);
switch (method.getName()) { if(SWAGGER_ANNOTATIONS_PERMISSION.equals(value)){
case "name": Annotation[] scopes =(Annotation[])methodHandler.invoke(authorizations[i], authorizationClass
permission.setName(invokeMethod(method, permissionAnnotation, STRING)); .getMethod(SWAGGER_ANNOTATIONS_SCOPES, null),null);
break; String[] scopesList = new String[scopes.length];
case "permission": String[] descriptions = new String[scopes.length];
permission.setPath(invokeMethod(method, permissionAnnotation, STRING)); for(int j=0; j<scopes.length; j++){
break; methodHandler = Proxy.getInvocationHandler(scopes[j]);
scopesList[j] = (String)methodHandler.invoke(authorizations[j], authorizationScopeClass
.getMethod(SWAGGER_ANNOTATIONS_SCOPE, null),null);
descriptions[j] = (String)methodHandler.invoke(authorizations[j], authorizationScopeClass
.getMethod(SWAGGER_ANNOTATIONS_DESCRIPTION, null),null);
}
//todo currently permission tree supports only adding one permission per API point.
permission.setName(descriptions[0]);
permission.setPath(scopesList[0]);
} }
} }
} }
} }
}

@ -59,7 +59,7 @@ public class WebAppDeploymentLifecycleListener implements LifecycleListener {
try { try {
AnnotationProcessor annotationProcessor = new AnnotationProcessor(context); AnnotationProcessor annotationProcessor = new AnnotationProcessor(context);
Set<String> annotatedAPIClasses = annotationProcessor. Set<String> annotatedAPIClasses = annotationProcessor.
scanStandardContext(org.wso2.carbon.apimgt.annotations.api.API.class.getName()); scanStandardContext(io.swagger.annotations.SwaggerDefinition.class.getName());
List<Permission> permissions = annotationProcessor.extractPermissions(annotatedAPIClasses); List<Permission> permissions = annotationProcessor.extractPermissions(annotatedAPIClasses);
PermissionManagerService permissionManagerService = PermissionManagerServiceImpl.getInstance(); PermissionManagerService permissionManagerService = PermissionManagerServiceImpl.getInstance();
if (permissions != null) { if (permissions != null) {

Loading…
Cancel
Save