From d5dcf44f27d1a040c59f16b8b273e7d1a579b557 Mon Sep 17 00:00:00 2001 From: Kamidu Sachith Date: Fri, 16 Oct 2015 18:39:34 +0530 Subject: [PATCH] Change the service registration --- .../backend-oauth-authenticator/pom.xml | 12 ++++++---- .../OauthAuthenticatorServiceComponent.java | 24 +++++++++++-------- .../authenticator/OAuthAuthenticator.java | 5 ++-- .../pom.xml | 7 ++++++ pom.xml | 5 ++++ 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/components/identity-extensions/backend-oauth-authenticator/pom.xml b/components/identity-extensions/backend-oauth-authenticator/pom.xml index e148f5fdf3..a071805ad4 100644 --- a/components/identity-extensions/backend-oauth-authenticator/pom.xml +++ b/components/identity-extensions/backend-oauth-authenticator/pom.xml @@ -87,12 +87,14 @@ ${pom.artifactId} ${pom.artifactId} + ${carbon.device.mgt.version} + Identity backend Bundle + org.wso2.carbon.identity.authenticator.backend.oauth.internal.OauthAuthenticatorServiceComponent - org.wso2.sample.authenticator.internal + org.wso2.org.wso2.carbon.identity.authenticator.backend.oauth.internal - !org.wso2.sample.authenticator.internal, - org.wso2.sample.authenticator.*, + org.wso2.carbon.identity.authenticator.backend.oauth.* javax.servlet.http, @@ -112,8 +114,8 @@ org.wso2.carbon.core.services.authentication, org.wso2.carbon.identity.oauth2.stub, org.wso2.carbon.identity.oauth2.stub.dto, - org.wso2.carbon.base, - org.wso2.carbon.utils + org.wso2.carbon.base, + org.wso2.carbon.utils diff --git a/components/identity-extensions/backend-oauth-authenticator/src/main/java/org/wso2/carbon/identity/authenticator/backend/oauth/internal/OauthAuthenticatorServiceComponent.java b/components/identity-extensions/backend-oauth-authenticator/src/main/java/org/wso2/carbon/identity/authenticator/backend/oauth/internal/OauthAuthenticatorServiceComponent.java index 59577ac633..7076afd4a6 100755 --- a/components/identity-extensions/backend-oauth-authenticator/src/main/java/org/wso2/carbon/identity/authenticator/backend/oauth/internal/OauthAuthenticatorServiceComponent.java +++ b/components/identity-extensions/backend-oauth-authenticator/src/main/java/org/wso2/carbon/identity/authenticator/backend/oauth/internal/OauthAuthenticatorServiceComponent.java @@ -20,25 +20,27 @@ package org.wso2.carbon.identity.authenticator.backend.oauth.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.osgi.service.component.ComponentContext; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; import org.wso2.carbon.core.services.authentication.CarbonServerAuthenticator; import org.wso2.carbon.identity.authenticator.backend.oauth.OauthAuthenticator; -/** - * @scr.component component.name="org.wso2.carbon.identity.authenticator.backend.oauth.OauthAuthenticator" immediate="true" - */ -@SuppressWarnings("unused") -public class OauthAuthenticatorServiceComponent { +public class OauthAuthenticatorServiceComponent implements BundleActivator { + + private ServiceRegistration pipServiceRegRef; private static final Log log = LogFactory.getLog(OauthAuthenticatorServiceComponent .class); - protected void activate(ComponentContext ctxt) { + @Override + public void start(BundleContext bundleContext) throws Exception { + log.info("Initiating"); try { OauthAuthenticator oauthAuthenticator = new OauthAuthenticator(); - ctxt.getBundleContext().registerService(CarbonServerAuthenticator.class.getName(), - oauthAuthenticator, null); + pipServiceRegRef = bundleContext.registerService(CarbonServerAuthenticator.class.getName(), + oauthAuthenticator, null); if (log.isDebugEnabled()) { log.debug("OAuth Authenticator bundle is activated"); } @@ -47,10 +49,12 @@ public class OauthAuthenticatorServiceComponent { } } - protected void deactivate(ComponentContext ctxt) { + @Override + public void stop(BundleContext bundleContext) throws Exception { if (log.isDebugEnabled()) { log.debug("OAuth Authenticator bundle is deactivated"); } + pipServiceRegRef.unregister(); } } 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 241e7de9b4..1119f3ac60 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 @@ -45,7 +45,6 @@ public class OAuthAuthenticator implements WebappAuthenticator { private static final String RESOURCE_KEY = "resource"; private static APITokenAuthenticator authenticator = new APITokenAuthenticator(); - private static final Log log = LogFactory.getLog(OAuthAuthenticator.class); @Override @@ -81,8 +80,8 @@ public class OAuthAuthenticator implements WebappAuthenticator { authenticationInfo.setStatus(Status.CONTINUE); } String apiVersion = tokenizer.nextToken(); - String authLevel = authenticator.getResourceAuthenticationScheme(context, apiVersion, requestUri, requestMethod); - //String authLevel = "any"; + //String authLevel = authenticator.getResourceAuthenticationScheme(context, apiVersion, requestUri, requestMethod); + String authLevel = "any"; try { if (Constants.NO_MATCHING_AUTH_SCHEME.equals(authLevel)) { AuthenticationFrameworkUtil.handleNoMatchAuthScheme(request, response, requestMethod, apiVersion, diff --git a/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml b/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml index b75edcb2d3..9d72ffbe15 100644 --- a/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml +++ b/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml @@ -45,6 +45,10 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.oauth.extensions + + org.wso2.carbon.devicemgt + org.wso2.carbon.identity.authenticator.backend.oauth + @@ -73,6 +77,9 @@ org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.oauth.extensions:${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt:org.wso2.carbon.identity.authenticator.backend.oauth:${carbon.device.mgt.version} + org.wso2.carbon.core.server:${carbon.kernel.version} diff --git a/pom.xml b/pom.xml index 12b522c5bb..2152418327 100644 --- a/pom.xml +++ b/pom.xml @@ -247,6 +247,11 @@ + + org.wso2.carbon.devicemgt + org.wso2.carbon.identity.authenticator.backend.oauth + ${carbon.device.mgt.version} +