From 337afa5da2a6b38b838a9d92df78fd0f067e375f Mon Sep 17 00:00:00 2001 From: prabathabey Date: Sat, 19 Dec 2015 13:27:45 +0530 Subject: [PATCH] Revert "Further optimizing webapp authenticator valve implementation" This reverts commit 262e53ddcccf9080942bf783f8a715bfd4f0480f. --- .../pom.xml | 3 +-- .../OAuthTokenValidationStubFactory.java | 13 +++++------ .../authenticator/BasicAuthAuthenticator.java | 5 ---- .../CertificateAuthenticator.java | 5 ---- .../authenticator/JWTAuthenticator.java | 5 ---- .../authenticator/OAuthAuthenticator.java | 23 +++---------------- .../authenticator/WebappAuthenticator.java | 2 -- .../framework/config/AuthenticatorConfig.java | 11 ++++----- ...uthenticatorFrameworkServiceComponent.java | 5 ++-- .../conf/webapp-authenticator-config.xml | 8 ------- 10 files changed, 17 insertions(+), 63 deletions(-) diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml index 3414eea46f..7684fb68e9 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml @@ -112,8 +112,7 @@ org.apache.commons.pool.impl, org.apache.http.client, org.apache.http.conn, - org.apache.http.impl.client, - org.apache.http.impl.conn + org.apache.http.impl.client diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/Utils/OAuthTokenValidationStubFactory.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/Utils/OAuthTokenValidationStubFactory.java index 88ceb34aeb..85e22d4519 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/Utils/OAuthTokenValidationStubFactory.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/Utils/OAuthTokenValidationStubFactory.java @@ -31,9 +31,6 @@ import org.apache.commons.pool.PoolableObjectFactory; import org.apache.http.client.HttpClient; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.conn.PoolingClientConnectionManager; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; import org.wso2.carbon.webapp.authenticator.framework.authenticator.oauth.OAuthConstants; import org.wso2.carbon.webapp.authenticator.framework.authenticator.oauth.OAuthTokenValidationException; @@ -55,10 +52,12 @@ public class OAuthTokenValidationStubFactory implements PoolableObjectFactory { this.url = url; this.basicAuthHeader = new String(Base64.encodeBase64((adminUsername + ":" + adminPassword).getBytes())); - PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); - connectionManager.setDefaultMaxPerRoute(Integer.parseInt(properties.getProperty("MaxConnectionsPerHost"))); - connectionManager.setMaxTotal(Integer.parseInt(properties.getProperty("MaxTotalConnections"))); - this.httpClient = HttpClients.custom().setConnectionManager(connectionManager).build(); + MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); + connectionManager.getParams().setDefaultMaxConnectionsPerHost( + Integer.parseInt(properties.getProperty("MaxConnectionsPerHost"))); + connectionManager.getParams().setMaxTotalConnections( + Integer.parseInt(properties.getProperty("MaxTotalConnections"))); + this.httpClient = new DefaultHttpClient((ClientConnectionManager) connectionManager); } @Override diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java index 06878d8ef8..7b83a90923 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java @@ -33,11 +33,6 @@ public class BasicAuthAuthenticator implements WebappAuthenticator { private static final String BASIC_AUTH_AUTHENTICATOR = "BasicAuth"; - @Override - public void init() { - - } - @Override public boolean canHandle(Request request) { MessageBytes authorization = diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java index ec2880d539..cb59559ad5 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java @@ -26,11 +26,6 @@ public class CertificateAuthenticator implements WebappAuthenticator { private static final String CERTIFICATE_AUTHENTICATOR = "CertificateAuth"; private static final String CERTIFICATE_VERIFICATION_HEADER = "certificate-verification-header"; - @Override - public void init() { - - } - @Override public boolean canHandle(Request request) { String certVerificationHeader = request.getContext().findParameter(CERTIFICATE_VERIFICATION_HEADER); diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java index d48e4d0a29..0f4cb51015 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java @@ -52,11 +52,6 @@ public class JWTAuthenticator implements WebappAuthenticator { private static final String JWT_AUTHENTICATOR = "JWT"; private static final String JWT_ASSERTION_HEADER = "X-JWT-Assertion"; - @Override - public void init() { - - } - @Override public boolean canHandle(Request request) { String authorizationHeader = request.getHeader(JWTAuthenticator.JWT_ASSERTION_HEADER); diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java index 1b29c9b389..83838b87e1 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java @@ -52,33 +52,16 @@ public class OAuthAuthenticator implements WebappAuthenticator { private static final Log log = LogFactory.getLog(OAuthAuthenticator.class); - @Override - public void init() { - if (properties == null) { - throw new IllegalArgumentException("Required properties needed to initialize OAuthAuthenticator are " + - "not provided"); - } + public OAuthAuthenticator() { String url = properties.getProperty("TokenValidationEndpointUrl"); - if (url == null || url.isEmpty()) { - throw new IllegalArgumentException("OAuth token validation endpoint url is not provided"); - } String adminUsername = properties.getProperty("Username"); - if (adminUsername == null) { - throw new IllegalArgumentException("Username to connect to the OAuth token validation endpoint is " + - "not provided"); - } String adminPassword = properties.getProperty("Password"); - if (adminPassword == null) { - throw new IllegalArgumentException("Password to connect to the OAuth token validation endpoint is " + - "not provided"); - } boolean isRemote = Boolean.parseBoolean(properties.getProperty("IsRemote")); Properties validatorProperties = new Properties(); validatorProperties.setProperty("MaxTotalConnections", properties.getProperty("MaxTotalConnections")); - validatorProperties.setProperty("MaxConnectionsPerHost", properties.getProperty("MaxConnectionsPerHost")); - this.tokenValidator = - OAuthValidatorFactory.getNewValidator(url, adminUsername, adminPassword, isRemote, validatorProperties); + validatorProperties.setProperty("MaxConnectionsPerHost", properties.getProperty("MaxTotalConnectionsPerHost")); + this.tokenValidator = OAuthValidatorFactory.getNewValidator(url, adminUsername, adminPassword, isRemote, validatorProperties); } @Override diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/WebappAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/WebappAuthenticator.java index 5090920624..7817ba10d3 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/WebappAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/WebappAuthenticator.java @@ -30,8 +30,6 @@ public interface WebappAuthenticator { SUCCESS, FAILURE, CONTINUE } - void init(); - boolean canHandle(Request request); AuthenticationInfo authenticate(Request request, Response response); diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/config/AuthenticatorConfig.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/config/AuthenticatorConfig.java index 6a36ba2498..d1669bed88 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/config/AuthenticatorConfig.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/config/AuthenticatorConfig.java @@ -18,7 +18,10 @@ */ package org.wso2.carbon.webapp.authenticator.framework.config; -import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; import java.util.List; @XmlRootElement(name = "Authenticator") @@ -52,10 +55,6 @@ public class AuthenticatorConfig { return params; } - public void setParams(List params) { - this.params = params; - } - @XmlRootElement(name = "Parameter") public static class Parameter { private String name; @@ -70,7 +69,7 @@ public class AuthenticatorConfig { this.name = name; } - @XmlValue + @XmlElement(name = "Value") public String getValue() { return value; } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkServiceComponent.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkServiceComponent.java index c2684f9c97..eef67ebaf7 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkServiceComponent.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkServiceComponent.java @@ -80,14 +80,13 @@ public class WebappAuthenticatorFrameworkServiceComponent { for (AuthenticatorConfig config : WebappAuthenticatorConfig.getInstance().getAuthenticators()) { WebappAuthenticator authenticator = (WebappAuthenticator) Class.forName(config.getClassName()). newInstance(); - if (config.getParams() != null && !config.getParams().isEmpty()) { + if (config.getParams() != null || !config.getParams().isEmpty()) { Properties properties = new Properties(); for (AuthenticatorConfig.Parameter param : config.getParams()) { properties.setProperty(param.getName(), param.getValue()); } authenticator.setProperties(properties); } - authenticator.init(); repository.addAuthenticator(authenticator); } AuthenticatorFrameworkDataHolder.getInstance().setWebappAuthenticatorRepository(repository); @@ -100,7 +99,7 @@ public class WebappAuthenticatorFrameworkServiceComponent { log.debug("Web Application Authenticator Framework Bundle has been started successfully"); } } catch (Throwable e) { - log.error("Error occurred while initializing the bundle", e); + log.error("Error occurred while initializing the bundle", e); } } diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml index 5099328df7..067d8cd3ce 100644 --- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml +++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml @@ -3,14 +3,6 @@ OAuth org.wso2.carbon.webapp.authenticator.framework.authenticator.OAuthAuthenticator - - https://localhost:9443 - admin - admin - true - 10000 - 10000 - BasicAuth