Merged 5.2.N (5.2.2) to HEAD (5.2)

135565 jkaabimofrad: Merged WEBAPP-API (5.2.1) to 5.2.N (5.2.1)
      135229 jkaabimofrad: APPSREPO-136: Updated the API framework so that WebApiNoAuth annotation can be used with operations.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@137401 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrei Rebegea
2017-06-14 17:07:13 +00:00
parent 25c8c95298
commit 67402ac66d
6 changed files with 121 additions and 55 deletions

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -40,6 +40,7 @@ import java.util.Set;
public class OperationResourceMetaData extends ResourceMetadata
{
private final Method operationMethod;
private final boolean noAuthRequired;
/**
* Use this constructor to create the resource metadata
@@ -47,8 +48,9 @@ public class OperationResourceMetaData extends ResourceMetadata
* @param operations
* @param api
* @param operationMethod
* @param noAuthRequired
*/
public OperationResourceMetaData(String uniqueId, List<ResourceOperation> operations, Api api, Method operationMethod)
public OperationResourceMetaData(String uniqueId, List<ResourceOperation> operations, Api api, Method operationMethod, boolean noAuthRequired)
{
super(uniqueId, RESOURCE_TYPE.OPERATION, operations, api, null, null, null);
if (operations.size()!= 1)
@@ -56,6 +58,7 @@ public class OperationResourceMetaData extends ResourceMetadata
throw new IllegalArgumentException("Only 1 operation per url is supported for an entity");
}
this.operationMethod = operationMethod;
this.noAuthRequired = noAuthRequired;
}
/**
@@ -63,11 +66,13 @@ public class OperationResourceMetaData extends ResourceMetadata
* @param uniqueId
* @param api
* @param apiDeleted
* @param noAuthRequired
*/
public OperationResourceMetaData(String uniqueId, Api api, Set<Class<? extends ResourceAction>> apiDeleted)
public OperationResourceMetaData(String uniqueId, Api api, Set<Class<? extends ResourceAction>> apiDeleted, boolean noAuthRequired)
{
super(uniqueId, RESOURCE_TYPE.OPERATION, null, api, apiDeleted, null, null);
this.operationMethod = null;
this.noAuthRequired = noAuthRequired;
}
public Method getOperationMethod()
@@ -75,6 +80,12 @@ public class OperationResourceMetaData extends ResourceMetadata
return operationMethod;
}
@Override
public boolean isNoAuth(Class<? extends ResourceAction> resourceAction)
{
return this.noAuthRequired;
}
@Override
public String toString()
{
@@ -91,7 +102,8 @@ public class OperationResourceMetaData extends ResourceMetadata
builder.append(this.getOperations());
builder.append(", apiDeleted=");
builder.append(this.getApiDeleted());
builder.append("operationMethod=").append(operationMethod);
builder.append(", operationMethod=").append(operationMethod);
builder.append(", noAuthRequired=").append(noAuthRequired);
builder.append("]");
return builder.toString();
}

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -308,7 +308,7 @@ public class ResourceInspector
{
if (! (httpMethod.equals(HttpMethod.GET) || httpMethod.equals(HttpMethod.POST)))
{
throw new IllegalArgumentException("@WebApiNoAuth should only be on GET methods: "+operation.getTitle()+" Or POST method for creating a ticket.");
throw new IllegalArgumentException("@WebApiNoAuth should only be on GET or POST methods: " + operation.getTitle());
}
helper.whenOperationNoAuth(resourceInterfaceWithOneMethod, aMethod);
}
@@ -327,7 +327,7 @@ public class ResourceInspector
Annotation annot = AnnotationUtils.findAnnotation(aMethod, WebApiDescription.class);
List<ResourceParameter> parameters = new ArrayList<ResourceParameter>();
parameters.addAll(inspectParameters(resource, aMethod, httpMethod));
if (annot != null)
{
Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
@@ -638,6 +638,7 @@ public class ResourceInspector
* Inspect a resource to find operations on it.
* @param api Api
* @param entityPath String
* @param metainfo resource metadata
*/
public static void inspectOperations(Api api, Class<?> resource, final String entityPath, List<ResourceMetadata> metainfo)
{
@@ -646,13 +647,16 @@ public class ResourceInspector
{
for (Entry<String, Pair<ResourceOperation, Method>> opera : operations.entrySet())
{
if (isDeleted(opera.getValue().getSecond()))
Method annotatedMethod = opera.getValue().getSecond();
final boolean isNoAuthRequired = isNoAuth(annotatedMethod);
if (isDeleted(annotatedMethod))
{
metainfo.add(new OperationResourceMetaData(opera.getKey(), api, new HashSet(Arrays.asList(opera.getValue().getFirst()))));
metainfo.add(new OperationResourceMetaData(opera.getKey(), api, new HashSet(Arrays.asList(opera.getValue().getFirst())), isNoAuthRequired));
}
else
{
metainfo.add(new OperationResourceMetaData(opera.getKey(), Arrays.asList(opera.getValue().getFirst()), api, opera.getValue().getSecond()));
metainfo.add(new OperationResourceMetaData(opera.getKey(), Arrays.asList(opera.getValue().getFirst()), api, annotatedMethod, isNoAuthRequired));
}
}
}

View File

@@ -1,8 +1,9 @@
/*
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -86,16 +87,17 @@ public class ResourceMetadata
}
/**
* Indicates if this resource can support the specified HTTPMethod
* @param supportedMethod HttpMethod
* @return true if can support it
* Gets the data type of the resource parameter
*
* @param operation {@code ResourceOperation} object
* @return The data type of the resource parameter
*/
@SuppressWarnings("rawtypes")
public Class getObjectType(ResourceOperation operation)
{
for (ResourceParameter param : operation.getParameters())
{
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(param.getParamType())) {
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(param.getParamType()))
{
return param.getDataType();
}
}