diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/src/main/java/org/wso2/carbon/apimgt/annotations/api/API.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/src/main/java/org/wso2/carbon/apimgt/annotations/api/API.java deleted file mode 100644 index 04ecd9ed70..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/src/main/java/org/wso2/carbon/apimgt/annotations/api/API.java +++ /dev/null @@ -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(); -} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java index 07452e5a0e..6d1bc7695b 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java @@ -199,7 +199,7 @@ public class APIPublisherUtil { String name = apiDef.getName(); if (name == null || name.isEmpty()) { if (log.isDebugEnabled()) { - log.debug("API Name not set in @API Annotation"); + log.debug("API Name not set in @SwaggerDefinition Annotation"); } name = servletContext.getServletContextName(); } @@ -208,7 +208,7 @@ public class APIPublisherUtil { String version = apiDef.getVersion(); if (version == null || version.isEmpty()) { 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; } @@ -218,7 +218,7 @@ public class APIPublisherUtil { String context = apiDef.getContext(); if (context == null || context.isEmpty()) { if (log.isDebugEnabled()) { - log.debug("'API Context not set in @API Annotation'"); + log.debug("'API Context not set in @SwaggerDefinition Annotation'"); } context = servletContext.getContextPath(); } @@ -227,7 +227,7 @@ public class APIPublisherUtil { String[] tags = apiDef.getTags(); if (tags == null || tags.length == 0) { if (log.isDebugEnabled()) { - log.debug("'API tag not set in @API Annotation'"); + log.debug("'API tag not set in @SwaggerDefinition Annotation'"); } } else { apiConfig.setTags(tags); diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java index d2932f994e..436580978c 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java @@ -57,28 +57,22 @@ public class APIPublisherLifecycleListener implements LifecycleListener { boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param); String profile = System.getProperty(PROPERTY_PROFILE); - if (WebappPublisherConfig.getInstance().getProfiles().getProfile().contains(profile.toLowerCase()) && isManagedApi) { try { AnnotationProcessor annotationProcessor = new AnnotationProcessor(context); - Set annotatedAPIClasses = annotationProcessor. - scanStandardContext(org.wso2.carbon.apimgt.annotations.api.API.class.getName()); - + Set annotatedSwaggerAPIClasses = annotationProcessor. + scanStandardContext(io.swagger.annotations.SwaggerDefinition.class.getName()); List apiDefinitions = annotationProcessor.extractAPIInfo(servletContext, - annotatedAPIClasses); - + annotatedSwaggerAPIClasses); for (APIResourceConfiguration apiDefinition : apiDefinitions) { - APIConfig apiConfig = APIPublisherUtil.buildApiConfig(servletContext, apiDefinition); - try { int tenantId = APIPublisherDataHolder.getInstance().getTenantManager(). getTenantId(apiConfig.getTenantDomain()); boolean isTenantActive = APIPublisherDataHolder.getInstance(). getTenantManager().isTenantActive(tenantId); - if (isTenantActive) { apiConfig.init(); API api = APIPublisherUtil.getAPI(apiConfig); diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java index bc4bf85724..d36e1442f4 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java @@ -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, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util; +import io.swagger.annotations.SwaggerDefinition; import org.apache.catalina.core.StandardContext; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; 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.config.APIResource; import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration; @@ -48,153 +45,135 @@ public class AnnotationProcessor { 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_CODEHAUS = "org.codehaus"; private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework"; private static final String WILD_CARD = "/*"; - 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 SWAGGER_ANNOTATIONS_INFO = "info"; + private static final String SWAGGER_ANNOTATIONS_TAGS = "tags"; + 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 apiClazz; private StandardContext context; private Method[] pathClazzMethods; private Class pathClazz; private ClassLoader classLoader; private ServletContext servletContext; - + private Class apiClazz; + private Class consumesClass; + private Class producesClass; + private Class infoClass; + private Class tagClass; + private Class extensionClass; + private Class extensionPropertyClass; public AnnotationProcessor(final StandardContext context) { servletContext = context.getServletContext(); classLoader = servletContext.getClassLoader(); + try { + pathClazz = (Class) classLoader.loadClass(Path.class.getName()); + consumesClass = (Class) classLoader.loadClass(Consumes.class.getName()); + producesClass = (Class) classLoader.loadClass(Produces.class.getName()); + apiClazz= (Class)classLoader.loadClass((SwaggerDefinition.class.getName())); + infoClass = (Class)classLoader + .loadClass((io.swagger.annotations.Info.class.getName())); + tagClass = (Class)classLoader + .loadClass((io.swagger.annotations.Tag.class.getName())); + extensionClass = (Class)classLoader + .loadClass((io.swagger.annotations.Extension.class.getName())); + extensionPropertyClass = (Class)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 scanStandardContext(String className) throws IOException { ExtendedAnnotationDB db = new ExtendedAnnotationDB(); db.addIgnoredPackages(PACKAGE_ORG_APACHE); db.addIgnoredPackages(PACKAGE_ORG_CODEHAUS); db.addIgnoredPackages(PACKAGE_ORG_SPRINGFRAMEWORK); - URL classPath = findWebInfClassesPath(servletContext); db.scanArchives(classPath); - - //Returns a list of classes with given Annotation return db.getAnnotationIndex().get(className); } - /** - * Method identifies the URL templates and context by reading the annotations of a class - * - * @param entityClasses - * @return - */ public List extractAPIInfo(final ServletContext servletContext, Set entityClasses) throws ClassNotFoundException { - List apiResourceConfigs = new ArrayList(); - if (entityClasses != null && !entityClasses.isEmpty()) { for (final String className : entityClasses) { - - APIResourceConfiguration resource = + APIResourceConfiguration apiResourceConfiguration = AccessController.doPrivileged(new PrivilegedAction() { public APIResourceConfiguration run() { Class clazz = null; APIResourceConfiguration apiResourceConfig = null; try { clazz = classLoader.loadClass(className); - - apiClazz = (Class) - classLoader.loadClass(org.wso2.carbon.apimgt.annotations.api.API - .class.getName()); - - Annotation apiAnno = clazz.getAnnotation(apiClazz); + Annotation swaggerDefinition = clazz.getAnnotation(apiClazz); List resourceList; - - if (apiAnno != null) { - + if (swaggerDefinition != null) { if (log.isDebugEnabled()) { log.debug("Application Context root = " + servletContext.getContextPath()); } - try { - apiResourceConfig = processAPIAnnotation(apiAnno); - String rootContext = servletContext.getContextPath(); - pathClazz = (Class) classLoader.loadClass(Path.class.getName()); - pathClazzMethods = pathClazz.getMethods(); - - Annotation rootContectAnno = clazz.getAnnotation(pathClazz); - String subContext; - if (rootContectAnno != null) { - subContext = invokeMethod(pathClazzMethods[0], rootContectAnno, STRING); - if (subContext != null && !subContext.isEmpty()) { - if (subContext.trim().startsWith("/")) { - rootContext = rootContext + subContext; - } else { - rootContext = rootContext + "/" + subContext; + apiResourceConfig = processAPIAnnotation(swaggerDefinition); + if(apiResourceConfig != null){ + String rootContext = servletContext.getContextPath(); + pathClazzMethods = pathClazz.getMethods(); + Annotation rootContectAnno = clazz.getAnnotation(pathClazz); + String subContext; + if (rootContectAnno != null) { + subContext = invokeMethod(pathClazzMethods[0], rootContectAnno + , STRING); + if (subContext != null && !subContext.isEmpty()) { + if (subContext.trim().startsWith("/")) { + rootContext = rootContext + subContext; + } else { + rootContext = rootContext + "/" + subContext; + } + } + if (log.isDebugEnabled()) { + log.debug("API Root Context = " + rootContext); } } - if (log.isDebugEnabled()) { - log.debug("API Root Context = " + rootContext); - } + Method[] annotatedMethods = clazz.getDeclaredMethods(); + resourceList = getApiResources(rootContext, annotatedMethods); + apiResourceConfig.setResources(resourceList); } - Method[] annotatedMethods = clazz.getDeclaredMethods(); - resourceList = getApiResources(rootContext, annotatedMethods); - apiResourceConfig.setResources(resourceList); } catch (Throwable throwable) { log.error("Error encountered while scanning for annotations", throwable); } } - } catch (ClassNotFoundException e) { - log.error("Error when passing the api annotation for device type apis.", e); + } catch (ClassNotFoundException e1) { + 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; } }); - apiResourceConfigs.add(resource); + if(apiResourceConfiguration !=null) + apiResourceConfigs.add(apiResourceConfiguration); } } 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 * @@ -209,7 +188,6 @@ public class AnnotationProcessor { for (Method method : annotatedMethods) { Annotation[] annotations = method.getDeclaredAnnotations(); APIResource resource = new APIResource(); - if (isHttpMethodAvailable(annotations)) { Annotation methodContextAnno = method.getAnnotation(pathClazz); if (methodContextAnno != null) { @@ -218,33 +196,21 @@ public class AnnotationProcessor { subCtx = WILD_CARD; } resource.setUriTemplate(makeContextURLReady(subCtx)); - resource.setUri(APIPublisherUtil.getServerBaseUrl() + makeContextURLReady(resourceRootContext) + makeContextURLReady(subCtx)); resource.setAuthType(AUTH_TYPE); - for (int i = 0; i < annotations.length; i++) { processHTTPMethodAnnotation(resource, annotations[i]); if (annotations[i].annotationType().getName().equals(Consumes.class.getName())) { - Class consumesClass = (Class) classLoader.loadClass( - Consumes.class.getName()); Method[] consumesClassMethods = consumesClass.getMethods(); Annotation consumesAnno = method.getAnnotation(consumesClass); resource.setConsumes(invokeMethod(consumesClassMethods[0], consumesAnno, STRING_ARR)); } if (annotations[i].annotationType().getName().equals(Produces.class.getName())) { - Class producesClass = (Class) classLoader.loadClass( - Produces.class.getName()); Method[] producesClassMethods = producesClass.getMethods(); Annotation producesAnno = method.getAnnotation(producesClass); 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); } @@ -293,6 +259,61 @@ public class AnnotationProcessor { 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 scopeClass = - (Class) 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 * 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); } } - } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/CertificateMgtService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/CertificateMgtService.java index 6527bff32d..f47ddda3bf 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/CertificateMgtService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/CertificateMgtService.java @@ -4,7 +4,8 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; 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.certificate.mgt.jaxrs.beans.ErrorResponse; @@ -31,7 +32,15 @@ public interface CertificateMgtService { httpMethod = "POST", value = "Process a given CSR and return signed certificates.", 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( value = { @ApiResponse( @@ -48,7 +57,6 @@ public interface CertificateMgtService { response = ErrorResponse.class) }) @Scope(key = "certificate:sign-csr", name = "Sign CSR", description = "") - @Permission(name = "Sign CSR", permission = "/device-mgt/certificates/manage") Response getSignedCertFromCSR( @ApiParam( name = "If-Modified-Since", diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java index b34e83f0e1..5e835f2df1 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java @@ -1,9 +1,18 @@ package org.wso2.carbon.certificate.mgt.cert.jaxrs.api; -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.Scope; +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.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.EnrollmentCertificate; 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.Response; -@API(name = "Certificate Management", version = "1.0.0", - context = "api/certificate-mgt/v1.0/admin/certificates", - tags = {"devicemgt_admin"}) - +@SwaggerDefinition( + info = @Info( + 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") @Path("/admin/certificates") @Produces(MediaType.APPLICATION_JSON) @@ -37,7 +57,15 @@ public interface CertificateManagementAdminService { httpMethod = "POST", value = "Adding a new SSL certificate", 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( value = { @ApiResponse( @@ -77,7 +105,6 @@ public interface CertificateManagementAdminService { message = "Internal Server Error. \n Server error occurred while adding certificates.", response = ErrorResponse.class) }) - @Permission(name = "Manage certificates", permission = "/device-mgt/certificates/manage") Response addCertificate( @ApiParam( name = "enrollmentCertificates", @@ -101,7 +128,15 @@ public interface CertificateManagementAdminService { httpMethod = "GET", value = "Getting Details of an SSL Certificate", 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 = { @ApiResponse( code = 200, @@ -137,7 +172,6 @@ public interface CertificateManagementAdminService { "Server error occurred while retrieving the requested certificate information.", response = ErrorResponse.class) }) - @Permission(name = "View certificates", permission = "/device-mgt/certificates/view") Response getCertificate( @ApiParam(name = "serialNumber", 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 " + "view all the certificate details, it is not feasible to show all the details on one " + "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 = { @ApiResponse( @@ -212,7 +253,6 @@ public interface CertificateManagementAdminService { "Server error occurred while retrieving the certificate details.", response = ErrorResponse.class) }) - @Permission(name = "View certificates", permission = "/device-mgt/certificates/view") Response getAllCertificates( @ApiParam( name = "offset", @@ -242,7 +282,15 @@ public interface CertificateManagementAdminService { httpMethod = "DELETE", value = "Deleting an SSL Certificate", 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 = { @ApiResponse( code = 200, @@ -259,7 +307,6 @@ public interface CertificateManagementAdminService { message = "Internal Server Error. \n " + "Server error occurred while removing the certificate.", response = ErrorResponse.class)}) - @Permission(name = "Manage certificates", permission = "/device-mgt/certificates/manage") Response removeCertificate( @ApiParam( name = "serialNumber", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java index 17f10385de..f584554ecb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java @@ -18,9 +18,19 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api; -import io.swagger.annotations.*; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.apimgt.annotations.api.Permission; +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.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.jaxrs.beans.ActivityList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; @@ -33,11 +43,24 @@ import javax.ws.rs.core.Response; /** * 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") -@Api(value = "Activity Info Provider", description = "Activity related information manipulation. For example operation details " + - "and responses from devices.") +@Api(value = "Activity Info Provider", description = "Activity related information manipulation. For example" + + " operation details and responses from devices.") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public interface ActivityInfoProviderService { @@ -48,9 +71,17 @@ public interface ActivityInfoProviderService { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting Details of an Activity", - notes = "Retrieve the details of a specific activity/operation, such as the meta information of an operation, " + - "including the responses from the devices.", - tags = "Activity Info Provider") + notes = "Retrieve the details of a specific activity/operation, such as the meta information of " + + "an operation, including the responses from the devices.", + tags = "Activity Info Provider", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view" + , description = "View Activities") } + ) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -71,7 +102,8 @@ public interface ActivityInfoProviderService { }), @ApiResponse( 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( code = 400, 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.", response = ErrorResponse.class) }) - @Permission(name = "View Activities", permission = "/device-mgt/devices/owning-device/view") Response getActivity( @ApiParam( name = "id", @@ -115,8 +146,17 @@ public interface ActivityInfoProviderService { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", 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.", - tags = "Activity Info Provider") + notes = "Get the details of the operations/activities executed by the server on the devices registered" + + " 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 = { @ApiResponse( code = 200, @@ -137,7 +177,8 @@ public interface ActivityInfoProviderService { }), @ApiResponse( 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( code = 401, 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.", response = ErrorResponse.class) }) - @Permission(name = "View Activities", permission = "/device-mgt/devices/owning-device/view") Response getActivities( @ApiParam( name = "since", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java index a9c010e184..a7575d88f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java @@ -18,9 +18,19 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api; -import io.swagger.annotations.*; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.apimgt.annotations.api.Permission; +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.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.jaxrs.beans.ErrorResponse; @@ -31,8 +41,21 @@ import javax.ws.rs.core.Response; /** * 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") @Api(value = "Configuration Management", description = "The general platform configuration management capabilities are exposed " + "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. " + "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.", - tags = "Configuration Management") + tags = "Configuration Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/platform-configurations/view", description = "View Configurations") } + ) + } + ) @ApiResponses( value = { @ApiResponse( @@ -82,7 +112,6 @@ public interface ConfigurationManagementService { "platform configurations.", response = ErrorResponse.class) }) - @Permission(name = "View Configurations", permission = "/device-mgt/platform-configurations/view") Response getConfiguration( @ApiParam( 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." + "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.", - tags = "Configuration Management") + tags = "Configuration Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/platform-configurations/manage", description = "Manage configurations") } + ) + } + ) @ApiResponses( value = { @ApiResponse( @@ -132,7 +168,6 @@ public interface ConfigurationManagementService { "Server error occurred while modifying the general platform configurations.", response = ErrorResponse.class) }) - @Permission(name = "Manage configurations", permission = "/device-mgt/platform-configurations/manage") Response updateConfiguration( @ApiParam( name = "configuration", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java index a3a72f6acd..22126d9042 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java @@ -19,20 +19,39 @@ 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 org.wso2.carbon.apimgt.annotations.api.API; 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.Response; /** * Device Analytics Dashboard related REST-APIs. This can be used to obtain device related analytics. */ -@API(name = "DeviceAnalyticsDashboard", - version = "1.0.0", context = "/api/device-mgt/v1.0/dashboard", tags = {"device_management"}) - +@SwaggerDefinition( + 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") @Api(value = "Device Analytics Dashboard", description = "Device Analytics Dashboard related information APIs are described here.") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index f72db7e45e..650ae34f7b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -18,9 +18,19 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api; -import io.swagger.annotations.*; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.apimgt.annotations.api.Permission; +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.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.Feature; 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. */ -@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") @Api(value = "Device Management", description = "This API carries all device management related operations " + "such as get all the available devices, etc.") @@ -54,7 +77,15 @@ public interface DeviceManagementService { httpMethod = "GET", value = "Getting Details of Registered Devices", 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.", response = DeviceList.class, @@ -73,7 +104,8 @@ public interface DeviceManagementService { }), @ApiResponse( 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( code = 400, 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.", response = ErrorResponse.class) }) - @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") Response getDevices( @ApiParam( name = "name", @@ -173,7 +204,15 @@ public interface DeviceManagementService { httpMethod = "GET", value = "Getting Details of a Device", 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( value = { @ApiResponse( @@ -195,7 +234,8 @@ public interface DeviceManagementService { }), @ApiResponse( 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( code = 400, message = "Bad Request. \n Invalid request or validation error.", @@ -210,7 +250,6 @@ public interface DeviceManagementService { "Server error occurred while retrieving the device details.", response = ErrorResponse.class) }) - @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") Response getDevice( @ApiParam( name = "type", @@ -245,7 +284,15 @@ public interface DeviceManagementService { httpMethod = "DELETE", value = "Delete the device speccified by device id", 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( value = { @ApiResponse( @@ -284,7 +331,6 @@ public interface DeviceManagementService { response = ErrorResponse.class) }) //TODO need to introduce delete permission - @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") Response deleteDevice( @ApiParam( 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. " + "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.", - tags = "Device Management") + tags = "Device Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Devices") } + ) + } + ) @ApiResponses( value = { @ApiResponse( @@ -361,7 +415,6 @@ public interface DeviceManagementService { "Server error occurred while retrieving the feature list for the device platform.", response = ErrorResponse.class) }) - @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") Response getFeaturesOfDevice( @ApiParam( name = "type", @@ -396,7 +449,15 @@ public interface DeviceManagementService { httpMethod = "POST", value = "Advanced Search for Devices", 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( value = { @ApiResponse( @@ -439,7 +500,6 @@ public interface DeviceManagementService { "Server error occurred while getting the device details.", response = ErrorResponse.class) }) - @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") Response searchDevices( @ApiParam( name = "offset", @@ -468,7 +528,15 @@ public interface DeviceManagementService { httpMethod = "GET", value = "Getting Installed Application Details of 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( value = { @ApiResponse( @@ -517,7 +585,6 @@ public interface DeviceManagementService { "Server error occurred while retrieving the list of installed application on the device.", response = ErrorResponse.class) }) - @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") Response getInstalledApplications( @ApiParam( name = "type", @@ -565,7 +632,15 @@ public interface DeviceManagementService { httpMethod = "GET", value = "Getting Device Operation Details", 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( value = { @ApiResponse( @@ -614,7 +689,6 @@ public interface DeviceManagementService { "Server error occurred while retrieving the operation list scheduled for the device.", response = ErrorResponse.class) }) - @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") Response getDeviceOperations( @ApiParam( name = "type", @@ -671,7 +745,15 @@ public interface DeviceManagementService { 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)," + "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( value = { @ApiResponse( @@ -720,7 +802,6 @@ public interface DeviceManagementService { response = ErrorResponse.class) } ) - @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") Response getEffectivePolicyOfDevice( @ApiParam( name = "type", @@ -755,7 +836,15 @@ public interface DeviceManagementService { value = "Getting Policy Compliance Details of a Device", 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.", - tags = "Device Management") + tags = "Device Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Devices") } + ) + } + ) @ApiResponses( value = { @ApiResponse( @@ -772,7 +861,6 @@ public interface DeviceManagementService { response = ErrorResponse.class) } ) - @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") Response getComplianceDataOfDevice( @ApiParam( name = "type", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java index b82531c070..94b06ea751 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java @@ -18,30 +18,42 @@ */ 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.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.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.ErrorResponse; import javax.validation.constraints.Size; -import javax.ws.rs.Consumes; -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.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -@API(name = "DeviceTypeManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/device-types", - tags = {"device_management"}) - +@SwaggerDefinition( + 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") @Api(value = "Device Type Management", description = "This API corresponds to all tasks related to device " + "type management") @@ -55,7 +67,15 @@ public interface DeviceTypeManagementService { httpMethod = "GET", value = "Getting the Supported Device Platforms", 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( value = { @ApiResponse( @@ -80,7 +100,8 @@ public interface DeviceTypeManagementService { @ApiResponse( code = 304, 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( code = 406, message = "Not Acceptable.\n The requested media type is not supported"), @@ -91,7 +112,6 @@ public interface DeviceTypeManagementService { response = ErrorResponse.class) } ) - @Permission(name = "View Device Types", permission = "/device-mgt/devices/owning-device/view") Response getDeviceTypes( @ApiParam( name = "If-Modified-Since", @@ -108,8 +128,17 @@ public interface DeviceTypeManagementService { httpMethod = "GET", 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. " + - "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.", - tags = "Device Type Management") + "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.", + tags = "Device Type Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Device Types") } + ) + } + ) @ApiResponses( value = { @ApiResponse( @@ -134,7 +163,8 @@ public interface DeviceTypeManagementService { @ApiResponse( code = 304, 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( code = 406, message = "Not Acceptable.\n The requested media type is not supported"), @@ -145,7 +175,6 @@ public interface DeviceTypeManagementService { response = ErrorResponse.class) } ) - @Permission(name = "View Device Types", permission = "/device-mgt/devices/owning-device/view") Response getFeatures( @ApiParam( name = "type", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java index 75fd081d96..b7630f1643 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java @@ -19,34 +19,26 @@ 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.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.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.group.mgt.DeviceGroup; -import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; -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 org.wso2.carbon.device.mgt.jaxrs.beans.*; import javax.validation.Valid; -import javax.ws.rs.Consumes; -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.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; 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. */ -@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") @Api(value = "Device Group Management", description = "This API carries all device group management related operations " + "such as get all the available groups, etc.") @@ -69,7 +74,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_GET, value = "Get the list of groups belongs to current user.", 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of device groups.", response = DeviceGroupList.class, @@ -102,7 +115,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while fetching the groups list.", response = ErrorResponse.class) }) - @Permission(name = "View Groups", permission = "/device-mgt/groups/view") Response getGroups(@ApiParam( name = "name", value = "Name of the group.") @@ -127,7 +139,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_GET, value = "Get the count of groups belongs to current user.", 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.", response = DeviceGroupList.class, @@ -160,7 +180,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while fetching the group count.", response = ErrorResponse.class) }) - @Permission(name = "View Groups", permission = "/device-mgt/groups/view") Response getGroupCount(); @POST @@ -169,7 +188,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_POST, value = "Add new device group to the system.", 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( value = { @ApiResponse( @@ -216,7 +243,6 @@ public interface GroupManagementService { "Server error occurred while adding a new device group.", response = ErrorResponse.class) }) - @Permission(name = "Add Group", permission = "/device-mgt/groups/add") Response createGroup(@ApiParam( name = "group", value = "Group object with data.", @@ -230,7 +256,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_GET, value = "View group specified.", 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group.", response = DeviceGroup.class, @@ -263,7 +297,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while fetching the group details.", response = ErrorResponse.class) }) - @Permission(name = "View Groups", permission = "/device-mgt/groups/view") Response getGroup(@ApiParam( name = "groupId", value = "ID of the group to view.", @@ -278,7 +311,15 @@ public interface GroupManagementService { value = "Update a group.", notes = "If you wish to make changes to an existing group, that can be done by updating the group using " + "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 = { @ApiResponse(code = 200, message = "OK. \n Group has been updated successfully.", responseHeaders = { @@ -310,7 +351,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while updating the group.", response = ErrorResponse.class) }) - @Permission(name = "Update Group", permission = "/device-mgt/groups/update") Response updateGroup(@ApiParam( name = "groupId", value = "ID of the group to be updated.", @@ -330,7 +370,15 @@ public interface GroupManagementService { value = "Delete a group.", notes = "If you wish to remove an existing group, that can be done by updating the group using " + "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 = { @ApiResponse(code = 200, message = "OK. \n Group has been deleted successfully.", responseHeaders = { @@ -362,7 +410,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while removing the group.", response = ErrorResponse.class) }) - @Permission(name = "Remove Group", permission = "/device-mgt/groups/remove") Response deleteGroup(@ApiParam( name = "groupId", value = "ID of the group to be deleted.", @@ -377,7 +424,15 @@ public interface GroupManagementService { 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, " + "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 = { @ApiResponse(code = 200, message = "OK. \n Sharing has been updated successfully.", responseHeaders = { @@ -409,7 +464,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while sharing the group.", response = ErrorResponse.class) }) - @Permission(name = "Share Group", permission = "/device-mgt/groups/share") Response manageGroupSharing(@ApiParam( name = "groupName", value = "Name of the group to be shared or unshared.", @@ -428,7 +482,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_GET, value = "View list of users of a device group.", 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the users.", response = DeviceGroupUsersList.class, @@ -461,7 +523,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while fetching the users.", response = ErrorResponse.class) }) - @Permission(name = "View users", permission = "/device-mgt/groups/users/view") Response getUsersOfGroup(@ApiParam( name = "groupId", value = "ID of the group.", @@ -476,7 +537,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_GET, value = "Create a group sharing role to a device group.", 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully created the role.", response = DeviceGroupUsersList.class, @@ -509,7 +578,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while creating the role.", response = ErrorResponse.class) }) - @Permission(name = "Create roles", permission = "/device-mgt/groups/roles/create") Response createGroupSharingRole( @ApiParam( name = "groupId", @@ -534,7 +602,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_GET, value = "View list of roles of a device group.", 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the users.", response = DeviceGroupUsersList.class, @@ -567,7 +643,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while fetching the roles.", response = ErrorResponse.class) }) - @Permission(name = "View roles", permission = "/device-mgt/groups/roles/view") Response getRolesOfGroup(@ApiParam( name = "groupId", value = "ID of the group.", @@ -586,7 +661,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_GET, value = "View 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the devices.", response = DeviceList.class, @@ -619,7 +702,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while fetching the devices.", response = ErrorResponse.class) }) - @Permission(name = "View devices", permission = "/device-mgt/groups/devices/view") Response getDevicesOfGroup(@ApiParam( name = "groupId", value = "ID of the group.", @@ -641,7 +723,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_GET, value = "View list of 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device count.", response = DeviceList.class, @@ -674,7 +764,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while fetching device count.", response = ErrorResponse.class) }) - @Permission(name = "View devices", permission = "/device-mgt/groups/devices/view") Response getDeviceCountOfGroup(@ApiParam( name = "groupId", value = "ID of the group.", @@ -688,7 +777,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_POST, value = "Add devices to 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully add devices to the group.", responseHeaders = { @@ -720,7 +817,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while adding devices to the group.", response = ErrorResponse.class) }) - @Permission(name = "Add devices", permission = "/device-mgt/groups/devices/add") Response addDevicesToGroup(@ApiParam( name = "groupId", value = "ID of the group.", @@ -739,7 +835,15 @@ public interface GroupManagementService { httpMethod = HTTPConstants.HEADER_DELETE, value = "Remove devices from 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully removed devices from the group.", responseHeaders = { @@ -771,7 +875,6 @@ public interface GroupManagementService { message = "Internal Server Error. \n Server error occurred while removing devices from the group.", response = ErrorResponse.class) }) - @Permission(name = "Remove devices", permission = "/device-mgt/groups/devices/remove") Response removeDevicesFromGroup(@ApiParam( name = "groupId", value = "ID of the group.", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java index f1a230e758..0a2998251c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java @@ -18,10 +18,19 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api; -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.Scope; +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.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.jaxrs.NotificationList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; @@ -35,8 +44,22 @@ import javax.ws.rs.core.Response; /** * 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.") @Path("/notifications") @Produces(MediaType.APPLICATION_JSON) @@ -49,7 +72,15 @@ public interface NotificationManagementService { httpMethod = "GET", 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.", - tags = "Device Notification Management") + tags = "Device Notification Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/notifications/view", + description = "View notifications") } + ) + } + ) @ApiResponses( value = { @ApiResponse( @@ -71,7 +102,8 @@ public interface NotificationManagementService { }), @ApiResponse( 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( code = 400, 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.", response = ErrorResponse.class) }) - @Permission(name = "View notifications", permission = "/device-mgt/notifications/view") Response getNotifications( @ApiParam( name = "status", @@ -132,7 +163,15 @@ public interface NotificationManagementService { value = "Updating the Device Notification Status", 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.", - tags = "Device Notification Management") + tags = "Device Notification Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/notifications/view", + description = "View notifications") } + ) + } + ) @ApiResponses( value = { @ApiResponse( @@ -149,7 +188,6 @@ public interface NotificationManagementService { message = "Error occurred while updating notification status.") } ) - @Permission(name = "View notifications", permission = "/device-mgt/notifications/view") Response updateNotificationStatus( @ApiParam( name = "id", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java index 7ed2d23388..6a77938b0f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java @@ -18,10 +18,19 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api; -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.Scope; +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.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.PolicyWrapper; 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, * 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") @Path("/policies") @Produces(MediaType.APPLICATION_JSON) @@ -54,7 +76,15 @@ public interface PolicyManagementService { 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." + "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( value = { @ApiResponse( @@ -101,7 +131,6 @@ public interface PolicyManagementService { "Server error occurred while adding a new policy.", response = ErrorResponse.class) }) - @Permission(name = "Manage policies", permission = "/device-mgt/policies/manage") Response addPolicy( @ApiParam( name = "policy", @@ -117,7 +146,15 @@ public interface PolicyManagementService { responseContainer = "List", notes = "Retrieve the details of all the policies in WSO2 EMM.", 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( value = { @ApiResponse( @@ -154,7 +191,6 @@ public interface PolicyManagementService { message = ("Internal Server Error. \n Server error occurred while fetching the policies."), response = ErrorResponse.class) }) - @Permission(name = "View policies", permission = "/device-mgt/policies/view") Response getPolicies( @ApiParam( name = "If-Modified-Since", @@ -187,7 +223,15 @@ public interface PolicyManagementService { value = "Getting Details of a Policy", notes = "Retrieve the details of a policy that is in WSO2 EMM.", 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( value = { @ApiResponse( @@ -224,7 +268,6 @@ public interface PolicyManagementService { "policy.", response = ErrorResponse.class) }) - @Permission(name = "View policies", permission = "/device-mgt/policies/view") Response getPolicy( @ApiParam( name = "id", @@ -250,7 +293,15 @@ public interface PolicyManagementService { httpMethod = "PUT", value = "Updating a Policy", 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( value = { @ApiResponse( @@ -290,7 +341,6 @@ public interface PolicyManagementService { "Server error occurred while updating the policy.", response = ErrorResponse.class) }) - @Permission(name = "Manage policies", permission = "/device-mgt/policies/manage") Response updatePolicy( @ApiParam( name = "id", @@ -313,7 +363,15 @@ public interface PolicyManagementService { httpMethod = "POST", value = "Removing Multiple Policies", 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( value = { @ApiResponse( @@ -337,7 +395,6 @@ public interface PolicyManagementService { "Server error occurred whilst bulk removing policies.", response = ErrorResponse.class) }) - @Permission(name = "Manage policies", permission = "/device-mgt/policies/manage") Response removePolicies( @ApiParam( name = "policyIds", @@ -354,7 +411,15 @@ public interface PolicyManagementService { httpMethod = "POST", value = "Activating Policies", 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( value = { @ApiResponse( @@ -373,7 +438,6 @@ public interface PolicyManagementService { message = "Sever error whilst activating the policies.", response = ErrorResponse.class) }) - @Permission(name = "Manage policies", permission = "/device-mgt/policies/manage") Response activatePolicies( @ApiParam( name = "policyIds", @@ -390,7 +454,15 @@ public interface PolicyManagementService { httpMethod = "POST", value = "Deactivating Policies", 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( value = { @ApiResponse( @@ -409,7 +481,6 @@ public interface PolicyManagementService { message = "ErrorResponse in deactivating policies.", response = ErrorResponse.class) }) - @Permission(name = "Manage policies", permission = "/device-mgt/policies/manage") Response deactivatePolicies( @ApiParam( name = "policyIds", @@ -431,7 +502,14 @@ public interface PolicyManagementService { " 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" + " 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( value = { @@ -443,7 +521,6 @@ public interface PolicyManagementService { message = "ErrorResponse in deactivating policies.", response = ErrorResponse.class) }) - @Permission(name = "Manage policies", permission = "/device-mgt/policies/manage") Response applyChanges(); @@ -455,7 +532,14 @@ public interface PolicyManagementService { httpMethod = "PUT", value = "Updating the Policy Priorities", 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( value = { @@ -471,7 +555,6 @@ public interface PolicyManagementService { message = "Exception in updating the policy priorities.", response = ErrorResponse.class) }) - @Permission(name = "Manage policies", permission = "/device-mgt/policies/manage") Response updatePolicyPriorities( @ApiParam( name = "priorityUpdatedPolicies", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java index d53c367450..cc2fef4ff2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java @@ -18,13 +18,22 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api; -import io.swagger.annotations.*; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.apimgt.annotations.api.Permission; +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.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.RoleInfo; 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 javax.ws.rs.*; @@ -32,8 +41,21 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; 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") @Api(value = "Role Management", description = "Role management related operations can be found here.") @Produces(MediaType.APPLICATION_JSON) @@ -47,7 +69,14 @@ public interface RoleManagementService { 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" + "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( value = { @ApiResponse( @@ -78,7 +107,6 @@ public interface RoleManagementService { message = "Internal Server Error. \n Server error occurred while fetching list of roles.", response = ErrorResponse.class) }) - @Permission(name = "View Roles", permission = "/device-mgt/roles/view") Response getRoles( @ApiParam( name = "filter", @@ -122,7 +150,13 @@ public interface RoleManagementService { "so using this REST API.", response = UIPermissionNode.class, responseContainer = "List", - tags = "Role Management" + tags = "Role Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", description = "View Roles") } + ) + } ) @ApiResponses( 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.", response = ErrorResponse.class) }) - @Permission(name = "View Roles", permission = "/device-mgt/roles/view") Response getPermissionsOfRole( @ApiParam( name = "roleName", @@ -193,7 +226,15 @@ public interface RoleManagementService { value = "Getting Details of a Role", notes = "Get the permissions associated with a role and role specific details using this REST API.", response = RoleInfo.class, - tags = "Role Management") + tags = "Role Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", + description = "View Roles") } + ) + } + ) @ApiResponses( value = { @ApiResponse( @@ -234,7 +275,6 @@ public interface RoleManagementService { "requested role.", response = ErrorResponse.class) }) - @Permission(name = "View Roles", permission = "/device-mgt/roles/view") Response getRole( @ApiParam( name = "roleName", @@ -262,7 +302,15 @@ public interface RoleManagementService { httpMethod = "POST", 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.", - tags = "Role Management") + tags = "Role Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", + description = "Manage Roles") } + ) + } + ) @ApiResponses(value = { @ApiResponse( code = 201, @@ -302,7 +350,6 @@ public interface RoleManagementService { message = "Internal Server Error. \n Server error occurred while adding a new role.", response = ErrorResponse.class) }) - @Permission(name = "Manage Roles", permission = "/device-mgt/roles/manage") Response addRole( @ApiParam( name = "role", @@ -318,7 +365,15 @@ public interface RoleManagementService { value = "Updating Role Details", 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.", - tags = "Role Management") + tags = "Role Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", + description = "Manage Roles") } + ) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -352,7 +407,6 @@ public interface RoleManagementService { message = "Internal Server Error. \n Server error occurred while updating the role.", response = ErrorResponse.class) }) - @Permission(name = "Manage Roles", permission = "/device-mgt/roles/manage") Response updateRole( @ApiParam( name = "roleName", @@ -379,7 +433,15 @@ public interface RoleManagementService { 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 " + "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 = { @ApiResponse( code = 200, @@ -397,7 +459,6 @@ public interface RoleManagementService { message = "Internal Server Error. \n Server error occurred while removing the role.", response = ErrorResponse.class) }) - @Permission(name = "Manage Roles", permission = "/device-mgt/roles/manage") Response deleteRole( @ApiParam( name = "roleName", @@ -424,7 +485,15 @@ public interface RoleManagementService { "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 " + "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( value = { @ApiResponse( @@ -461,7 +530,6 @@ public interface RoleManagementService { "Server error occurred while adding the user to the specified role.", response = ErrorResponse.class) }) - @Permission(name = "Manage Roles", permission = "/device-mgt/roles/manage") Response updateUsersOfRole( @ApiParam( name = "roleName", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index 845cf11b82..b211a3a101 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -18,9 +18,19 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api; -import io.swagger.annotations.*; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.apimgt.annotations.api.Permission; +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.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 javax.ws.rs.*; @@ -28,9 +38,21 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; - -@API(name = "UserManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/users", tags = {"device_management"}) - +@SwaggerDefinition( + 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") @Api(value = "User Management", description = "User management related operations can be found here.") @Produces(MediaType.APPLICATION_JSON) @@ -44,7 +66,15 @@ public interface UserManagementService { httpMethod = "POST", 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", - tags = "User Management") + tags = "User Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", + description = "Manage Users") } + ) + } + ) @ApiResponses( value = { @ApiResponse( @@ -83,7 +113,6 @@ public interface UserManagementService { message = "Internal Server Error. \n Server error occurred while adding a new user.", response = ErrorResponse.class) }) - @Permission(name = "Manage Users", permission = "/device-mgt/users/manage") Response addUser( @ApiParam( name = "user", @@ -99,7 +128,15 @@ public interface UserManagementService { value = "Getting Details of a User", notes = "Get the details of a user registered with WSO2 EMM using the REST API.", 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 = { @ApiResponse( code = 200, @@ -135,7 +172,6 @@ public interface UserManagementService { " fetching the ruser details.", response = ErrorResponse.class) }) - @Permission(name = "View Users", permission = "/device-mgt/users/view") Response getUser( @ApiParam( name = "username", @@ -165,7 +201,15 @@ public interface UserManagementService { value = "Updating Details of a User", 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.", - tags = "User Management") + tags = "User Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", + description = "Manage Users") } + ) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -200,7 +244,6 @@ public interface UserManagementService { "Server error occurred while updating the user.", response = ErrorResponse.class) }) - @Permission(name = "Manage Users", permission = "/device-mgt/users/manage") Response updateUser( @ApiParam( name = "username", @@ -225,7 +268,15 @@ public interface UserManagementService { httpMethod = "DELETE", value = "Deleting a User", 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 = { @ApiResponse( code = 200, @@ -241,7 +292,6 @@ public interface UserManagementService { response = ErrorResponse.class ) }) - @Permission(name = "Manage Users", permission = "/device-mgt/users/manage") Response removeUser( @ApiParam( name = "username", @@ -263,7 +313,15 @@ public interface UserManagementService { httpMethod = "GET", 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.", - tags = "User Management") + tags = "User Management", + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", + description = "View Users") } + ) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -299,7 +357,6 @@ public interface UserManagementService { " assigned to the specified user.", response = ErrorResponse.class) }) - @Permission(name = "View Users", permission = "/device-mgt/users/view") Response getRolesOfUser( @ApiParam( name = "username", @@ -320,7 +377,15 @@ public interface UserManagementService { 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 " + "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 = { @ApiResponse( code = 200, @@ -341,7 +406,8 @@ public interface UserManagementService { }), @ApiResponse( 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( code = 406, 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.", response = ErrorResponse.class) }) - @Permission(name = "View Users", permission = "/device-mgt/users/view") Response getUsers( @ApiParam( name = "filter", @@ -385,7 +450,14 @@ public interface UserManagementService { httpMethod = "GET", value = "Getting the User Count", 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 = { @ApiResponse( 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.", response = ErrorResponse.class) }) - @Permission(name = "View Users", permission = "/device-mgt/users/view") Response getUserCount(); @GET @@ -415,7 +486,15 @@ public interface UserManagementService { httpMethod = "GET", value = "Getting the User existence status", 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 = { @ApiResponse( code = 200, @@ -432,10 +511,10 @@ public interface UserManagementService { response = ErrorResponse.class), @ApiResponse( 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) }) - @Permission(name = "View Users", permission = "/device-mgt/users/view") Response isUserExists(@ApiParam( name = "username", 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. " + "You will be given a list of users having the user name in the exact order of the " + "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 = { @ApiResponse( 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.", response = ErrorResponse.class) }) - @Permission(name = "View Users", permission = "/device-mgt/users/view") Response getUserNames( @ApiParam( name = "filter", @@ -524,7 +609,14 @@ public interface UserManagementService { httpMethod = "PUT", value = "Changing the User Password", 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 = { @ApiResponse( code = 200, @@ -547,7 +639,6 @@ public interface UserManagementService { "Server error occurred while updating the user credentials.", response = ErrorResponse.class) }) - @Permission(name = "Reset user password", permission = "/login") Response resetPassword( @ApiParam( name = "credentials", @@ -564,7 +655,14 @@ public interface UserManagementService { 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" + "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 = { @ApiResponse( code = 200, @@ -587,7 +685,6 @@ public interface UserManagementService { "Server error occurred while updating the user credentials.", response = ErrorResponse.class) }) - @Permission(name = "Manage Users", permission = "/device-mgt/users/manage") Response inviteExistingUsersToEnrollDevice( @ApiParam( name = "users", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java index ed4ce0d8e7..132d1e1377 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java @@ -19,9 +19,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; 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.Scope; 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.ErrorResponse; @@ -33,8 +31,21 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; 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") @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. " + @@ -52,7 +63,15 @@ public interface ApplicationManagementAdminService { value = "Installing an Application (Internal API)", notes = "This is an internal API that can be used to install an application on a device.", 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 = { @ApiResponse( code = 202, @@ -75,7 +94,6 @@ public interface ApplicationManagementAdminService { " for a specified set of devices.", response = ErrorResponse.class) }) - @Permission(name = "Install/Uninstall applications", permission = "/device-mgt/applications/manage") Response installApplication( @ApiParam( name = "applicationWrapper", @@ -91,7 +109,15 @@ public interface ApplicationManagementAdminService { value = "Uninstalling an Application (Internal API)\n", notes = "This is an internal API that can be used to uninstall an application.", 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 = { @ApiResponse( 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."), @ApiResponse( code = 500, - message = "Internal Server Error. \n Server error occurred while executing the application install operation in bulk" + - " for a specified set of devices.", + message = "Internal Server Error. \n Server error occurred while executing the application install" + + " operation in bulk for a specified set of devices.", response = ErrorResponse.class) }) - @Permission(name = "Install/Uninstall applications", permission = "/device-mgt/applications/manage") Response uninstallApplication( @ApiParam( name = "applicationWrapper", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java index 6736e14b97..6266a9b737 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java @@ -18,9 +18,19 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; -import io.swagger.annotations.*; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.apimgt.annotations.api.Permission; +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.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.jaxrs.beans.ErrorResponse; @@ -29,8 +39,21 @@ import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -@API(name = "DeviceManagementAdmin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/devices", - tags = {"device_management"}) +@SwaggerDefinition( + 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") @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. " + @@ -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.", response = Device.class, 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.", response = Device.class, @@ -67,7 +98,8 @@ public interface DeviceManagementAdminService { }), @ApiResponse( 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( code = 401, 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.", response = ErrorResponse.class) }) - @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") Response getDevicesByName( @ApiParam( 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) @QueryParam("name") @Size(max = 45) @@ -127,5 +159,4 @@ public interface DeviceManagementAdminService { required = false, defaultValue = "5") @QueryParam("limit") int limit); - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java index 6757c471b5..daffe2a6c5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java @@ -19,28 +19,42 @@ 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.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.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.ErrorResponse; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; 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") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @@ -55,7 +69,15 @@ public interface GroupManagementAdminService { httpMethod = HTTPConstants.HEADER_GET, value = "Get the list of groups.", 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of device groups.", response = DeviceGroupList.class, @@ -88,7 +110,6 @@ public interface GroupManagementAdminService { message = "Internal Server Error. \n Server error occurred while fetching the groups list.", response = ErrorResponse.class) }) - @Permission(name = "View Groups", permission = "/device-mgt/admin/groups/view") Response getGroups(@ApiParam( name = "name", value = "Name of the group.") @@ -113,7 +134,15 @@ public interface GroupManagementAdminService { httpMethod = HTTPConstants.HEADER_GET, value = "Get the count of groups belongs to current user.", 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 = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.", response = DeviceGroupList.class, @@ -146,7 +175,6 @@ public interface GroupManagementAdminService { message = "Internal Server Error. \n Server error occurred while fetching the group count.", response = ErrorResponse.class) }) - @Permission(name = "View Groups", permission = "/device-mgt/admin/groups/view") Response getGroupCount(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java index be9160a785..99914a94ab 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java @@ -18,10 +18,18 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; -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.Scope; +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.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.PasswordResetWrapper; @@ -30,8 +38,21 @@ import javax.ws.rs.*; import javax.ws.rs.core.MediaType; 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") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @@ -49,7 +70,15 @@ public interface UserManagementAdminService { value = "Changing the User Password.", 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.", - 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 = { @ApiResponse( code = 200, @@ -70,7 +99,6 @@ public interface UserManagementAdminService { "Server error occurred while updating credentials of the user.", response = ErrorResponse.class) }) - @Permission(name = "View Users", permission = "/device-mgt/users/manage") Response resetUserPassword( @ApiParam( name = "username", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/AnnotationProcessor.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/AnnotationProcessor.java index 855698032b..86735ff88a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/AnnotationProcessor.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/AnnotationProcessor.java @@ -18,10 +18,11 @@ 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.commons.logging.Log; 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 javax.servlet.ServletContext; @@ -55,16 +56,43 @@ public class AnnotationProcessor { private static final String STRING_ARR = "string_arr"; 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 Class pathClazz; - Class apiClazz; private ClassLoader classLoader; private ServletContext servletContext; + private Swagger swagger; + private Class apiClazz; + private Class consumesClass; + private Class producesClass; + private Class apiOperation; + private Class authorizationClass; + private Class authorizationScopeClass; public AnnotationProcessor(final StandardContext context) { servletContext = context.getServletContext(); classLoader = servletContext.getClassLoader(); + try { + pathClazz = (Class) classLoader.loadClass(Path.class.getName()); + consumesClass = (Class) classLoader.loadClass(Consumes.class.getName()); + producesClass = (Class) classLoader.loadClass(Produces.class.getName()); + apiClazz= (Class)classLoader.loadClass((SwaggerDefinition.class.getName())); + apiOperation = (Class)classLoader + .loadClass((io.swagger.annotations.ApiOperation.class.getName())); + authorizationClass = (Class)classLoader + .loadClass((io.swagger.annotations.Authorization.class.getName())); + authorizationScopeClass = (Class)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 * @return */ - public List - extractPermissions(Set entityClasses) { + public List extractPermissions(Set entityClasses) { List permissions = new ArrayList<>(); @@ -107,25 +134,15 @@ public class AnnotationProcessor { List apiPermissions = new ArrayList<>(); try { clazz = classLoader.loadClass(className); - - apiClazz = (Class) - classLoader.loadClass(org.wso2.carbon.apimgt.annotations.api.API - .class.getName()); - Annotation apiAnno = clazz.getAnnotation(apiClazz); List resourceList; - if (apiAnno != null) { - if (log.isDebugEnabled()) { log.debug("Application Context root = " + servletContext.getContextPath()); } - try { String rootContext = servletContext.getContextPath(); - pathClazz = (Class) classLoader.loadClass(Path.class.getName()); pathClazzMethods = pathClazz.getMethods(); - Annotation rootContectAnno = clazz.getAnnotation(pathClazz); String subContext = ""; if (rootContectAnno != null) { @@ -141,7 +158,6 @@ public class AnnotationProcessor { log.debug("API Root Context = " + rootContext); } } - Method[] annotatedMethods = clazz.getDeclaredMethods(); apiPermissions = getApiResources(rootContext, annotatedMethods); } catch (Throwable throwable) { @@ -200,12 +216,11 @@ public class AnnotationProcessor { permission.setMethod(httpMethod); } if (annotations[i].annotationType().getName(). - equals(org.wso2.carbon.apimgt.annotations.api.Permission.class.getName())) { - this.setPermission(method, permission); + equals(io.swagger.annotations.ApiOperation.class.getName())) { + this.setPermission(annotations[i], permission); } } permissions.add(permission); - } } return permissions; @@ -325,24 +340,30 @@ public class AnnotationProcessor { return replacedPath.toString(); } - private void setPermission(Method currentMethod, Permission permission) throws Throwable { - Class permissionClass = - (Class) classLoader. - loadClass(org.wso2.carbon.apimgt.annotations.api.Permission.class.getName()); - Annotation permissionAnnotation = currentMethod.getAnnotation(permissionClass); - if (permissionClass != null) { - Method[] permissionClassMethods = permissionClass.getMethods(); - for (Method method : permissionClassMethods) { - switch (method.getName()) { - case "name": - permission.setName(invokeMethod(method, permissionAnnotation, STRING)); - break; - case "permission": - permission.setPath(invokeMethod(method, permissionAnnotation, STRING)); - break; + private void setPermission(Annotation currentMethod, Permission permission) throws Throwable { + InvocationHandler methodHandler = Proxy.getInvocationHandler(currentMethod); + Annotation[] authorizations = (Annotation[]) methodHandler.invoke(currentMethod + , apiOperation.getMethod(SWAGGER_ANNOTATIONS_AUTHORIZATIONS,null),null); + for(int i=0; i annotatedAPIClasses = annotationProcessor. - scanStandardContext(org.wso2.carbon.apimgt.annotations.api.API.class.getName()); + scanStandardContext(io.swagger.annotations.SwaggerDefinition.class.getName()); List permissions = annotationProcessor.extractPermissions(annotatedAPIClasses); PermissionManagerService permissionManagerService = PermissionManagerServiceImpl.getInstance(); if (permissions != null) {