Improving the way webapp requests are authenticated

revert-70aa11f8
prabathabey 9 years ago
parent 1bbaac168b
commit c8affcf836

@ -28,7 +28,7 @@ import org.wso2.carbon.webapp.authenticator.framework.authenticator.OAuthAuthent
public class WebappAuthenticatorFactory { public class WebappAuthenticatorFactory {
public static WebappAuthenticator getAuthenticator(Request request) { public static WebappAuthenticator getAuthenticator(String authScheme) {
return new OAuthAuthenticator(); return new OAuthAuthenticator();
} }

@ -29,11 +29,14 @@ import javax.servlet.http.HttpServletResponse;
public class WebappAuthenticatorFrameworkValve extends CarbonTomcatValve { public class WebappAuthenticatorFrameworkValve extends CarbonTomcatValve {
private static final String AUTHENTICATION_SCHEME = "AuthenticationScheme";
private static final Log log = LogFactory.getLog(WebappAuthenticatorFrameworkValve.class); private static final Log log = LogFactory.getLog(WebappAuthenticatorFrameworkValve.class);
@Override @Override
public void invoke(Request request, Response response, CompositeValve compositeValve) { public void invoke(Request request, Response response, CompositeValve compositeValve) {
WebappAuthenticator authenticator = WebappAuthenticatorFactory.getAuthenticator(request); String authScheme =
request.getContext().findParameter(WebappAuthenticatorFrameworkValve.AUTHENTICATION_SCHEME);
WebappAuthenticator authenticator = WebappAuthenticatorFactory.getAuthenticator(authScheme);
WebappAuthenticator.Status status = authenticator.authenticate(request, response); WebappAuthenticator.Status status = authenticator.authenticate(request, response);
this.processResponse(request, response, compositeValve, status); this.processResponse(request, response, compositeValve, status);
} }

@ -49,8 +49,12 @@ public class OAuthAuthenticator implements WebappAuthenticator {
@Override @Override
public Status authenticate(Request request, Response response) { public Status authenticate(Request request, Response response) {
StringTokenizer tokenizer = new StringTokenizer(request.getRequestURI(), "/"); String requestUri = request.getRequestURI();
if (requestUri == null || "".equals(requestUri)) {
return Status.CONTINUE;
}
StringTokenizer tokenizer = new StringTokenizer(requestUri, "/");
String context = request.getContextPath(); String context = request.getContextPath();
if (context == null || "".equals(context)) { if (context == null || "".equals(context)) {
context = tokenizer.nextToken(); context = tokenizer.nextToken();
@ -59,13 +63,13 @@ public class OAuthAuthenticator implements WebappAuthenticator {
} }
} }
boolean isContextCached = false; // boolean isContextCached = false;
if (APIUtil.getAPIContextCache().get(context) != null) { // if (APIUtil.getAPIContextCache().get(context) != null) {
isContextCached = Boolean.parseBoolean(APIUtil.getAPIContextCache().get(context).toString()); // isContextCached = Boolean.parseBoolean(APIUtil.getAPIContextCache().get(context).toString());
} // }
if (!isContextCached) { // if (!isContextCached) {
return Status.CONTINUE; // return Status.CONTINUE;
} // }
try { try {
String apiVersion = tokenizer.nextToken(); String apiVersion = tokenizer.nextToken();

Loading…
Cancel
Save