mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixing issues surfaced when a proper authentication scheme is not defined for certain resources
This commit is contained in:
parent
a9d3d15438
commit
7942fb4cbb
@ -31,6 +31,6 @@ public interface WebappAuthenticator {
|
|||||||
|
|
||||||
Status authenticate(Request request, Response response);
|
Status authenticate(Request request, Response response);
|
||||||
|
|
||||||
String getAuthenticatorName();
|
String getName();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import org.wso2.carbon.webapp.authenticator.framework.authenticator.OAuthAuthent
|
|||||||
public class WebappAuthenticatorFactory {
|
public class WebappAuthenticatorFactory {
|
||||||
|
|
||||||
public static WebappAuthenticator getAuthenticator(String authScheme) {
|
public static WebappAuthenticator getAuthenticator(String authScheme) {
|
||||||
return new OAuthAuthenticator();
|
return DataHolder.getWebappAuthenticatorRepository().getAuthenticator(authScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,14 +29,18 @@ 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 String AUTHENTICATION_SCHEME = "authentication-scheme";
|
||||||
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) {
|
||||||
String authScheme =
|
String authScheme =
|
||||||
request.getContext().findParameter(WebappAuthenticatorFrameworkValve.AUTHENTICATION_SCHEME);
|
request.getContext().findParameter(WebappAuthenticatorFrameworkValve.AUTHENTICATION_SCHEME);
|
||||||
|
if (authScheme == null || "".equals(authScheme)) {
|
||||||
|
this.getNext().invoke(request, response, compositeValve);
|
||||||
|
return;
|
||||||
|
}
|
||||||
WebappAuthenticator authenticator = WebappAuthenticatorFactory.getAuthenticator(authScheme);
|
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);
|
||||||
}
|
}
|
||||||
@ -55,5 +59,4 @@ public class WebappAuthenticatorFrameworkValve extends CarbonTomcatValve {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticator;
|
|||||||
|
|
||||||
public class BasicAuthAuthenticator implements WebappAuthenticator {
|
public class BasicAuthAuthenticator implements WebappAuthenticator {
|
||||||
|
|
||||||
private static final String BASIC_AUTH_AUTHENTICATOR = "BasicAuthAuthenticator";
|
private static final String BASIC_AUTH_AUTHENTICATOR = "BasicAuth";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAuthenticated(Request request) {
|
public boolean isAuthenticated(Request request) {
|
||||||
@ -41,7 +41,7 @@ public class BasicAuthAuthenticator implements WebappAuthenticator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAuthenticatorName() {
|
public String getName() {
|
||||||
return BasicAuthAuthenticator.BASIC_AUTH_AUTHENTICATOR;
|
return BasicAuthAuthenticator.BASIC_AUTH_AUTHENTICATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,7 @@ import java.util.StringTokenizer;
|
|||||||
|
|
||||||
public class OAuthAuthenticator implements WebappAuthenticator {
|
public class OAuthAuthenticator implements WebappAuthenticator {
|
||||||
|
|
||||||
private static final String OAUTH_AUTHENTICATOR = "OAuthAuthenticator";
|
private static final String OAUTH_AUTHENTICATOR = "OAuth";
|
||||||
private static APITokenAuthenticator authenticator = new APITokenAuthenticator();
|
private static APITokenAuthenticator authenticator = new APITokenAuthenticator();
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(OAuthAuthenticator.class);
|
private static final Log log = LogFactory.getLog(OAuthAuthenticator.class);
|
||||||
@ -97,7 +97,7 @@ public class OAuthAuthenticator implements WebappAuthenticator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAuthenticatorName() {
|
public String getName() {
|
||||||
return OAuthAuthenticator.OAUTH_AUTHENTICATOR;
|
return OAuthAuthenticator.OAUTH_AUTHENTICATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,10 @@ import org.osgi.framework.BundleActivator;
|
|||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
import org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve;
|
import org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve;
|
||||||
import org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer;
|
import org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticator;
|
||||||
import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticatorFrameworkValve;
|
import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticatorFrameworkValve;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticatorRepository;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig;
|
||||||
import org.wso2.carbon.webapp.authenticator.framework.config.WebappAuthenticatorConfig;
|
import org.wso2.carbon.webapp.authenticator.framework.config.WebappAuthenticatorConfig;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -41,6 +44,14 @@ public class WebappAuthenticatorFrameworkBundleActivator implements BundleActiva
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
WebappAuthenticatorConfig.init();
|
WebappAuthenticatorConfig.init();
|
||||||
|
|
||||||
|
WebappAuthenticatorRepository repository = new WebappAuthenticatorRepository();
|
||||||
|
for (AuthenticatorConfig config : WebappAuthenticatorConfig.getInstance().getAuthenticators()) {
|
||||||
|
WebappAuthenticator authenticator =
|
||||||
|
(WebappAuthenticator) Class.forName(config.getClassName()).newInstance();
|
||||||
|
repository.addAuthenticator(authenticator);
|
||||||
|
}
|
||||||
|
|
||||||
List<CarbonTomcatValve> valves = new ArrayList<CarbonTomcatValve>();
|
List<CarbonTomcatValve> valves = new ArrayList<CarbonTomcatValve>();
|
||||||
valves.add(new WebappAuthenticatorFrameworkValve());
|
valves.add(new WebappAuthenticatorFrameworkValve());
|
||||||
TomcatValveContainer.addValves(valves);
|
TomcatValveContainer.addValves(valves);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user