Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement RequiresAuthorization
  • Loading branch information
dhleong committed May 5, 2013
commit 0cab24349c617146a84b2bc905584f614f65b383
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.lang.model.element.VariableElement;

import org.androidannotations.annotations.rest.Accept;
import org.androidannotations.annotations.rest.RequiresAuthentication;
import org.androidannotations.annotations.rest.RequiresCookie;
import org.androidannotations.annotations.rest.RequiresCookieInUrl;
import org.androidannotations.annotations.rest.RequiresHeader;
Expand Down Expand Up @@ -342,6 +343,13 @@ protected JVar generateHttpHeadersVar(MethodProcessorHolder methodHolder, EBeanH

}

boolean requiresAuth = requiresAuth(executableElement);
if (requiresAuth) {
// attach auth
RestImplementationHolder restHolder = restImplementationsHolder.getEnclosingHolder(methodHolder.getElement());
body.add(httpHeadersVar.invoke("setAuthorization").arg(restHolder.authenticationField));
}

return httpHeadersVar;
}

Expand Down Expand Up @@ -405,6 +413,14 @@ private String[] retrieveSettingCookieNames(ExecutableElement executableElement)
}
}

private boolean requiresAuth(ExecutableElement executableElement) {
RequiresAuthentication basicAuthAnnotation = executableElement.getAnnotation(RequiresAuthentication.class);
if (basicAuthAnnotation == null) {
basicAuthAnnotation = executableElement.getEnclosingElement().getAnnotation(RequiresAuthentication.class);
}
return basicAuthAnnotation != null;
}

private TreeMap<String, JVar> extractMethodParamsVar(EBeanHolder eBeanHolder, JMethod method, ExecutableElement executableElement, RestImplementationHolder holder) {
List<? extends VariableElement> params = executableElement.getParameters();
TreeMap<String, JVar> methodParams = new TreeMap<String, JVar>();
Expand Down