From bf58c0bec36479d83859f6b3e7c590a5525b5aa3 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Mon, 4 Jul 2016 16:45:36 +0530 Subject: [PATCH 1/3] add package changes to appAuthenticatorFrameworkServiceComponent.java --- ...uthenticatorFrameworkServiceComponent.java | 198 ++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkServiceComponent.java 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 new file mode 100644 index 00000000000..b450d33aeba --- /dev/null +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkServiceComponent.java @@ -0,0 +1,198 @@ +package org.wso2.carbon.webapp.authenticator.framework.internal; + +//import org.wso2.carbon.device.mgt.core.scep.SCEPManager; + +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.scep.SCEPManager; +import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; +import org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService; +import org.wso2.carbon.registry.core.service.TenantRegistryLoader; +import org.wso2.carbon.registry.indexing.service.TenantIndexingLoader; +import org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve; +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.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; +import java.util.Properties; + +/** + * @scr.component name="org.wso2.carbon.webapp.authenticator" immediate="true" + * @scr.reference name="user.realmservice.default" + * interface="org.wso2.carbon.user.core.service.RealmService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRealmService" + * unbind="unsetRealmService" + * @scr.reference name="org.wso2.carbon.certificate.mgt" + * interface="org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService" + * policy="dynamic" + * cardinality="1..n" + * bind="setCertificateManagementService" + * unbind="unsetCertificateManagementService" + * @scr.reference name="org.wso2.carbon.certificate.mgt.core.scep" + * interface="org.wso2.carbon.certificate.mgt.core.scep.SCEPManager" + * policy="dynamic" + * cardinality="1..n" + * bind="setSCEPManagementService" + * unbind="unsetSCEPManagementService" + * @scr.reference name="identity.oauth2.validation.service" + * interface="org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService" + * cardinality="1..1" + * policy="dynamic" + * bind="setOAuth2ValidationService" + * unbind="unsetOAuth2ValidationService" + * @scr.reference name="tenant.indexloader" + * interface="org.wso2.carbon.registry.indexing.service.TenantIndexingLoader" + * cardinality="1..1" + * policy="dynamic" + * bind="setTenantIndexLoader" + * unbind="unsetTenantIndexLoader" + * @scr.reference name="tenant.registryloader" + * interface="org.wso2.carbon.registry.core.service.TenantRegistryLoader" + * cardinality="1..1" policy="dynamic" + * bind="setTenantRegistryLoader" + * unbind="unsetTenantRegistryLoader" + */ +public class WebappAuthenticatorFrameworkServiceComponent { + private static final Log log = LogFactory.getLog(WebappAuthenticatorFrameworkServiceComponent.class); + + @SuppressWarnings("unused") + protected void activate(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("Starting Web Application Authenticator Framework Bundle"); + } + try { + WebappAuthenticatorConfig.init(); + WebappAuthenticatorRepository repository = new WebappAuthenticatorRepository(); + for (AuthenticatorConfig config : WebappAuthenticatorConfig.getInstance().getAuthenticators()) { + WebappAuthenticator authenticator = + (WebappAuthenticator) Class.forName(config.getClassName()).newInstance(); + + 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); + } + + //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(); + valves.add(new WebappAuthenticationValve()); + TomcatValveContainer.addValves(valves); + + if (log.isDebugEnabled()) { + log.debug("Web Application Authenticator Framework Bundle has been started successfully"); + } + } catch (Throwable e) { + log.error("Error occurred while initializing the bundle", e); + } + } + + @SuppressWarnings("unused") + protected void deactivate(ComponentContext componentContext) { + //do nothing + } + + protected void setRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("RealmService acquired"); + } + AuthenticatorFrameworkDataHolder.getInstance().setRealmService(realmService); + } + + protected void unsetRealmService(RealmService realmService) { + AuthenticatorFrameworkDataHolder.getInstance().setRealmService(null); + } + + protected void setCertificateManagementService(CertificateManagementService certificateManagementService) { + if (log.isDebugEnabled()) { + log.debug("Setting certificate management service"); + } + AuthenticatorFrameworkDataHolder.getInstance().setCertificateManagementService(certificateManagementService); + } + + protected void unsetCertificateManagementService(CertificateManagementService certificateManagementService) { + if (log.isDebugEnabled()) { + log.debug("Removing certificate management service"); + } + + AuthenticatorFrameworkDataHolder.getInstance().setCertificateManagementService(null); + } + + protected void setSCEPManagementService(SCEPManager scepManager) { + if (log.isDebugEnabled()) { + log.debug("Setting SCEP management service"); + } + AuthenticatorFrameworkDataHolder.getInstance().setScepManager(scepManager); + } + + protected void unsetSCEPManagementService(SCEPManager scepManager) { + if (log.isDebugEnabled()) { + log.debug("Removing SCEP management service"); + } + + AuthenticatorFrameworkDataHolder.getInstance().setScepManager(null); + } + + /** + * Sets OAuth2TokenValidation Service. + * + * @param tokenValidationService An instance of OAuth2TokenValidationService + */ + protected void setOAuth2ValidationService(OAuth2TokenValidationService tokenValidationService) { + if (log.isDebugEnabled()) { + log.debug("Setting OAuth2TokenValidationService Service"); + } + AuthenticatorFrameworkDataHolder.getInstance().setOAuth2TokenValidationService(tokenValidationService); + } + + /** + * Unsets OAuth2TokenValidation Service. + * + * @param tokenValidationService An instance of OAuth2TokenValidationService + */ + protected void unsetOAuth2ValidationService(OAuth2TokenValidationService tokenValidationService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting OAuth2TokenValidationService Service"); + } + AuthenticatorFrameworkDataHolder.getInstance().setOAuth2TokenValidationService(null); + } + + protected void setTenantIndexLoader(TenantIndexingLoader tenantIndexLoader) { + AuthenticatorFrameworkDataHolder.getInstance().setTenantIndexingLoader(tenantIndexLoader); + } + + protected void unsetTenantIndexLoader(TenantIndexingLoader tenantIndexLoader) { + AuthenticatorFrameworkDataHolder.getInstance().setTenantIndexingLoader(null); + } + + protected void setTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader) { + AuthenticatorFrameworkDataHolder.getInstance().setTenantRegistryLoader(tenantRegistryLoader); + } + + protected void unsetTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader) { + AuthenticatorFrameworkDataHolder.getInstance().setTenantRegistryLoader(null); + } +} From bbbbb28795db2ad3cc3dd6d8d4cd8dceab3ab48d Mon Sep 17 00:00:00 2001 From: hasuniea Date: Mon, 4 Jul 2016 16:51:36 +0530 Subject: [PATCH 2/3] removing unused packages --- ...uthenticatorFrameworkServiceComponent.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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 b450d33aeba..017d4ced44a 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 @@ -1,6 +1,23 @@ -package org.wso2.carbon.webapp.authenticator.framework.internal; +/* + * Copyright (c) 2016, 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. + * + */ -//import org.wso2.carbon.device.mgt.core.scep.SCEPManager; +package org.wso2.carbon.webapp.authenticator.framework.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; From 282ac72249ca7de9be0d82704532d7d83244e966 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Mon, 4 Jul 2016 17:58:14 +0530 Subject: [PATCH 3/3] adding SCEPManagerService to scep manager compenent --- .../internal/SCEPManagerServiceComponent.java | 60 +++++++++++++++++++ .../internal/SCEPManagerServiceComponent.java | 52 ++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/internal/SCEPManagerServiceComponent.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/SCEPManagerServiceComponent.java diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/internal/SCEPManagerServiceComponent.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/internal/SCEPManagerServiceComponent.java new file mode 100644 index 00000000000..2f9fc8e22c3 --- /dev/null +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/internal/SCEPManagerServiceComponent.java @@ -0,0 +1,60 @@ +package org.wso2.carbon.certificate.mgt.core.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.scep.SCEPManager; +import org.wso2.carbon.certificate.mgt.core.scep.SCEPManagerImpl; +import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; + +/** + * @scr.component name="org.wso2.carbon.certificate.mgt.core.scep" immediate="true" + * @scr.reference name="app.mgt.service" + * interface="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService" + * cardinality="1..1" + * policy="dynamic" + * bind="setApplicationManagementProviderService" + * unbind="unsetApplicationManagementProviderService" + */ +public class SCEPManagerServiceComponent { + + private static final Log log = LogFactory.getLog(SCEPManagerServiceComponent.class); + + protected void activate(ComponentContext componentContext) { + + try { + if (log.isDebugEnabled()) { + log.debug("Initializing SCEP core bundle"); + } + + BundleContext bundleContext = componentContext.getBundleContext(); + bundleContext.registerService(SCEPManager.class.getName(), + new SCEPManagerImpl(), null); + + if (log.isDebugEnabled()) { + log.debug("SCEP core bundle has been successfully initialized"); + } + } catch (Throwable e) { + String msg = "Error occurred while initializing SCEP core bundle"; + log.error(msg, e); + } + } + + protected void deactivate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("Deactivating SCEP core bundle"); + } + } + + protected void unsetApplicationManagementProviderService(ApplicationManagementProviderService + applicationManagementProviderService) { + //do nothing + } + + protected void setApplicationManagementProviderService(ApplicationManagementProviderService + applicationManagementProviderService) { + //do nothing + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/SCEPManagerServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/SCEPManagerServiceComponent.java new file mode 100644 index 00000000000..e5d9058bdfc --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/SCEPManagerServiceComponent.java @@ -0,0 +1,52 @@ +package org.wso2.carbon.device.mgt.core.internal; + +///** +// * @scr.component name="org.wso2.carbon.certificate.mgt.core.scep" immediate="true" +// * @scr.reference name="app.mgt.service" +// * interface="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService" +// * cardinality="1..1" +// * policy="dynamic" +// * bind="setApplicationManagementProviderService" +// * unbind="unsetApplicationManagementProviderService" +// */ +//public class SCEPManagerServiceComponent { +// +// private static final Log log = LogFactory.getLog(SCEPManagerServiceComponent.class); +// +// protected void activate(ComponentContext componentContext) { +// +// try { +// if (log.isDebugEnabled()) { +// log.debug("Initializing SCEP core bundle"); +// } +// +// BundleContext bundleContext = componentContext.getBundleContext(); +// bundleContext.registerService(SCEPManager.class.getName(), +// new SCEPManagerImpl(), null); +// +// if (log.isDebugEnabled()) { +// log.debug("SCEP core bundle has been successfully initialized"); +// } +// } catch (Throwable e) { +// String msg = "Error occurred while initializing SCEP core bundle"; +// log.error(msg, e); +// } +// } +// +// protected void deactivate(ComponentContext ctx) { +// if (log.isDebugEnabled()) { +// log.debug("Deactivating SCEP core bundle"); +// } +// } +// +// protected void unsetApplicationManagementProviderService(ApplicationManagementProviderService +// applicationManagementProviderService) { +// //do nothing +// } +// +// protected void setApplicationManagementProviderService(ApplicationManagementProviderService +// applicationManagementProviderService) { +// //do nothing +// } +// +//}