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 c1427834453..46024d64768 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 @@ -73,6 +73,7 @@ org.apache.tomcat.util.buf, org.apache.tomcat.util.http, org.osgi.service.component, + org.osgi.framework, org.w3c.dom, org.wso2.carbon.apimgt.api, org.wso2.carbon.apimgt.core.authenticate, diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/Constants.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/Constants.java index 9d85c6bb46c..26166e864a7 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/Constants.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/Constants.java @@ -15,6 +15,7 @@ * specific language governing permissions and limitations * under the License. */ + package org.wso2.carbon.webapp.authenticator.framework; public final class Constants { diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BSTAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BSTAuthenticator.java index 972e2eb0e67..42b382a6720 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BSTAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BSTAuthenticator.java @@ -23,7 +23,6 @@ import org.apache.axiom.om.impl.builder.StAXBuilder; import org.apache.axiom.om.util.StAXUtils; import org.apache.axiom.soap.SOAPEnvelope; import org.apache.axiom.soap.SOAPHeader; -import org.apache.axiom.soap.SOAPHeaderBlock; import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/config/AuthenticatorConfigService.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/config/AuthenticatorConfigService.java new file mode 100644 index 00000000000..c36aaea9344 --- /dev/null +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/config/AuthenticatorConfigService.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.webapp.authenticator.framework.config; + +/** + * This defines the contract for AuthenticatorConfigService to expose authenticator configs in webapp-authenticators.xml. + */ +public interface AuthenticatorConfigService { + + AuthenticatorConfig getAuthenticatorConfig(String authenticatorName) throws InvalidConfigurationStateException; + +} diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/config/impl/AuthenticatorConfigServiceImpl.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/config/impl/AuthenticatorConfigServiceImpl.java new file mode 100644 index 00000000000..702a5cbc9e9 --- /dev/null +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/config/impl/AuthenticatorConfigServiceImpl.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.webapp.authenticator.framework.config.impl; + +import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig; +import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfigService; +import org.wso2.carbon.webapp.authenticator.framework.config.InvalidConfigurationStateException; +import org.wso2.carbon.webapp.authenticator.framework.config.WebappAuthenticatorConfig; + +import java.util.List; + +/** + * This holds implementation of AuthenticatorConfigService. + */ +public class AuthenticatorConfigServiceImpl implements AuthenticatorConfigService { + + @Override + public AuthenticatorConfig getAuthenticatorConfig(String authenticatorName) throws + InvalidConfigurationStateException { + List configs = WebappAuthenticatorConfig.getInstance().getAuthenticators(); + int index = 0; + if (authenticatorName == null || authenticatorName.isEmpty()) { + return null; + } + for (int i = 0; i < configs.size(); i++) { + AuthenticatorConfig authenticatorConfig = configs.get(i); + if (authenticatorName.equals(authenticatorConfig.getName())) { + index = i; + break; + } + } + return configs.get(index); + } +} 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 c81ae13f4b2..4a342186a73 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 @@ -20,6 +20,7 @@ package org.wso2.carbon.webapp.authenticator.framework.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; import org.wso2.carbon.device.mgt.core.scep.SCEPManager; @@ -29,10 +30,12 @@ import org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.webapp.authenticator.framework.AuthenticatorFrameworkDataHolder; import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticationValve; -import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticatorRepository; +import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig; +import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfigService; import org.wso2.carbon.webapp.authenticator.framework.config.WebappAuthenticatorConfig; +import org.wso2.carbon.webapp.authenticator.framework.config.impl.AuthenticatorConfigServiceImpl; import java.util.ArrayList; import java.util.List; @@ -91,6 +94,12 @@ public class WebappAuthenticatorFrameworkServiceComponent { authenticator.init(); repository.addAuthenticator(authenticator); } + + //Register AuthenticatorConfigService to expose webapp-authenticator configs. + BundleContext bundleContext = componentContext.getBundleContext(); + AuthenticatorConfigService authenticatorConfigService = new AuthenticatorConfigServiceImpl(); + bundleContext.registerService(AuthenticatorConfigService.class.getName(), authenticatorConfigService, null); + AuthenticatorFrameworkDataHolder.getInstance().setWebappAuthenticatorRepository(repository); List valves = new ArrayList();