Merge pull request #541 from milanperera/release-2.0.x

Fixed NPE occurred due to scope mapping
revert-70aa11f8
Ayyoob Hamza 8 years ago committed by GitHub
commit 91f8ac1341

@ -73,6 +73,9 @@ public class AnnotationProcessor {
private static final String SWAGGER_ANNOTATIONS_PROPERTIES_CONTEXT = "context"; private static final String SWAGGER_ANNOTATIONS_PROPERTIES_CONTEXT = "context";
private static final String SWAGGER_ANNOTATIONS_PROPERTIES_VALUE = "value"; private static final String SWAGGER_ANNOTATIONS_PROPERTIES_VALUE = "value";
private static final String ANNOTATIONS_SCOPES = "scopes"; private static final String ANNOTATIONS_SCOPES = "scopes";
private static final String ANNOTATIONS_SCOPE = "scope";
private static final String DEFAULT_SCOPE_KEY = "perm:admin";
private static final String DEFAULT_SCOPE_PERMISSION = "/permision/device-mgt";
private static final String PERMISSION_PREFIX = "/permission/admin"; private static final String PERMISSION_PREFIX = "/permission/admin";
@ -273,7 +276,16 @@ public class AnnotationProcessor {
resource.setProduces(invokeMethod(producesClassMethods[0], producesAnno, STRING_ARR)); resource.setProduces(invokeMethod(producesClassMethods[0], producesAnno, STRING_ARR));
} }
if (annotations[i].annotationType().getName().equals(ApiOperation.class.getName())) { if (annotations[i].annotationType().getName().equals(ApiOperation.class.getName())) {
resource.setScope(this.getScope(annotations[i])); Scope scope = this.getScope(annotations[i]);
if (scope != null) {
resource.setScope(scope);
} else {
log.error("Scope is not defined for '" + makeContextURLReady(resourceRootContext) +
makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope");
scope.setKey(DEFAULT_SCOPE_KEY);
scope.setRoles(DEFAULT_SCOPE_PERMISSION);
resource.setScope(scope);
}
} }
} }
resourceList.add(resource); resourceList.add(resource);
@ -444,18 +456,25 @@ public class AnnotationProcessor {
InvocationHandler methodHandler = Proxy.getInvocationHandler(currentMethod); InvocationHandler methodHandler = Proxy.getInvocationHandler(currentMethod);
Annotation[] extensions = (Annotation[]) methodHandler.invoke(currentMethod, Annotation[] extensions = (Annotation[]) methodHandler.invoke(currentMethod,
apiOperation.getMethod(SWAGGER_ANNOTATIONS_EXTENSIONS, null), null); apiOperation.getMethod(SWAGGER_ANNOTATIONS_EXTENSIONS, null), null);
methodHandler = Proxy.getInvocationHandler(extensions[0]); if (extensions != null) {
Annotation[] properties = (Annotation[])methodHandler.invoke(extensions[0], extensionClass methodHandler = Proxy.getInvocationHandler(extensions[0]);
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES,null), null); Annotation[] properties = (Annotation[]) methodHandler.invoke(extensions[0], extensionClass
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES, null), null);
for (Annotation property : properties) { String scopeKey;
methodHandler = Proxy.getInvocationHandler(property); String propertyName;
String scopeKey = (String) methodHandler.invoke(property, extensionPropertyClass for (Annotation property : properties) {
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_VALUE, null),null); methodHandler = Proxy.getInvocationHandler(property);
if (scopeKey.isEmpty()) { propertyName = (String) methodHandler.invoke(property, extensionPropertyClass
return null; .getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_NAME, null), null);
if (ANNOTATIONS_SCOPE.equals(propertyName)) {
scopeKey = (String) methodHandler.invoke(property, extensionPropertyClass
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_VALUE, null), null);
if (scopeKey.isEmpty()) {
return null;
}
return apiScopes.get(scopeKey);
}
} }
return apiScopes.get(scopeKey);
} }
return null; return null;
} }

@ -70,6 +70,7 @@ public class AnnotationProcessor {
private static final String SWAGGER_ANNOTATIONS_PROPERTIES_KEY = "key"; private static final String SWAGGER_ANNOTATIONS_PROPERTIES_KEY = "key";
private static final String SWAGGER_ANNOTATIONS_PROPERTIES_PERMISSIONS = "permissions"; private static final String SWAGGER_ANNOTATIONS_PROPERTIES_PERMISSIONS = "permissions";
private static final String ANNOTATIONS_SCOPES = "scopes"; private static final String ANNOTATIONS_SCOPES = "scopes";
private static final String ANNOTATIONS_SCOPE = "scope";
private static final String PERMISSION_PREFIX = "/permission/admin"; private static final String PERMISSION_PREFIX = "/permission/admin";
@ -375,19 +376,27 @@ public class AnnotationProcessor {
InvocationHandler methodHandler = Proxy.getInvocationHandler(currentMethod); InvocationHandler methodHandler = Proxy.getInvocationHandler(currentMethod);
Annotation[] extensions = (Annotation[]) methodHandler.invoke(currentMethod, Annotation[] extensions = (Annotation[]) methodHandler.invoke(currentMethod,
apiOperation.getMethod(SWAGGER_ANNOTATIONS_EXTENSIONS, null), null); apiOperation.getMethod(SWAGGER_ANNOTATIONS_EXTENSIONS, null), null);
methodHandler = Proxy.getInvocationHandler(extensions[0]); if (extensions != null) {
Annotation[] properties = (Annotation[])methodHandler.invoke(extensions[0], extensionClass methodHandler = Proxy.getInvocationHandler(extensions[0]);
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES,null), null); Annotation[] properties = (Annotation[]) methodHandler.invoke(extensions[0], extensionClass
Scope scope; .getMethod(SWAGGER_ANNOTATIONS_PROPERTIES, null), null);
for (Annotation property : properties) { Scope scope;
methodHandler = Proxy.getInvocationHandler(property); String scopeKey;
String scopeKey = (String) methodHandler.invoke(property, extensionPropertyClass String propertyName;
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_VALUE, null),null); for (Annotation property : properties) {
if (!scopeKey.isEmpty()) { methodHandler = Proxy.getInvocationHandler(property);
scope = apiScopes.get(scopeKey); propertyName = (String) methodHandler.invoke(property, extensionPropertyClass
permission.setName(scope.getName()); .getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_NAME, null), null);
//TODO: currently permission tree supports only adding one permission per API point. if (ANNOTATIONS_SCOPE.equals(propertyName)) {
permission.setPath(scope.getRoles().split(" ")[0]); scopeKey = (String) methodHandler.invoke(property, extensionPropertyClass
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_VALUE, null), null);
if (!scopeKey.isEmpty()) {
scope = apiScopes.get(scopeKey);
permission.setName(scope.getName());
//TODO: currently permission tree supports only adding one permission per API point.
permission.setPath(scope.getRoles().split(" ")[0]);
}
}
} }
} }
} }

@ -139,7 +139,8 @@
"perm:admin:certificates:delete", "perm:admin:certificates:delete",
"perm:admin:certificates:details", "perm:admin:certificates:details",
"perm:admin:certificates:view", "perm:admin:certificates:view",
"perm:admin:certificates:add" "perm:admin:certificates:add",
"perm:admin"
], ],
"isOAuthEnabled" : true, "isOAuthEnabled" : true,
"backendRestEndpoints" : { "backendRestEndpoints" : {

Loading…
Cancel
Save