From a9d3d1543874c1b4056965f4147d8764ed6695ed Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 21 May 2015 17:46:57 +0530 Subject: [PATCH 1/3] Adding pofile operations --- .../policy/mgt/common/PolicyOperation.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyOperation.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyOperation.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyOperation.java new file mode 100644 index 0000000000..c0d37ef190 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyOperation.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015, 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.policy.mgt.common; + +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; + +import java.util.List; + +public class PolicyOperation extends ProfileOperation { + + private List profileOperations; + + public List getProfileOperations() { + return profileOperations; + } + + public void setProfileOperations(List profileOperations) { + this.profileOperations = profileOperations; + } +} From 7942fb4cbbbc020af7672db9a9f47e9a6a8d3bde Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 21 May 2015 18:53:02 +0530 Subject: [PATCH 2/3] Fixing issues surfaced when a proper authentication scheme is not defined for certain resources --- .../authenticator/framework/WebappAuthenticator.java | 2 +- .../framework/WebappAuthenticatorFactory.java | 2 +- .../framework/WebappAuthenticatorFrameworkValve.java | 9 ++++++--- .../authenticator/BasicAuthAuthenticator.java | 4 ++-- .../framework/authenticator/OAuthAuthenticator.java | 4 ++-- .../WebappAuthenticatorFrameworkBundleActivator.java | 11 +++++++++++ 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticator.java index 4d0f5a0ddb..5f2eecf8d1 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticator.java @@ -31,6 +31,6 @@ public interface WebappAuthenticator { Status authenticate(Request request, Response response); - String getAuthenticatorName(); + String getName(); } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFactory.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFactory.java index aade936742..5885a0e8fb 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFactory.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFactory.java @@ -29,7 +29,7 @@ import org.wso2.carbon.webapp.authenticator.framework.authenticator.OAuthAuthent public class WebappAuthenticatorFactory { public static WebappAuthenticator getAuthenticator(String authScheme) { - return new OAuthAuthenticator(); + return DataHolder.getWebappAuthenticatorRepository().getAuthenticator(authScheme); } } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java index 44af9195a9..dcfd51663d 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java @@ -29,14 +29,18 @@ import javax.servlet.http.HttpServletResponse; public class WebappAuthenticatorFrameworkValve extends CarbonTomcatValve { - private static final String AUTHENTICATION_SCHEME = "AuthenticationScheme"; - private static final Log log = LogFactory.getLog(WebappAuthenticatorFrameworkValve.class); + private static final String AUTHENTICATION_SCHEME = "authentication-scheme"; @Override public void invoke(Request request, Response response, CompositeValve compositeValve) { String authScheme = request.getContext().findParameter(WebappAuthenticatorFrameworkValve.AUTHENTICATION_SCHEME); + if (authScheme == null || "".equals(authScheme)) { + this.getNext().invoke(request, response, compositeValve); + return; + } WebappAuthenticator authenticator = WebappAuthenticatorFactory.getAuthenticator(authScheme); + WebappAuthenticator.Status status = authenticator.authenticate(request, response); this.processResponse(request, response, compositeValve, status); } @@ -55,5 +59,4 @@ public class WebappAuthenticatorFrameworkValve extends CarbonTomcatValve { } } - } 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 60cc95f3bb..d17827bd99 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 @@ -28,7 +28,7 @@ import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticator; public class BasicAuthAuthenticator implements WebappAuthenticator { - private static final String BASIC_AUTH_AUTHENTICATOR = "BasicAuthAuthenticator"; + private static final String BASIC_AUTH_AUTHENTICATOR = "BasicAuth"; @Override public boolean isAuthenticated(Request request) { @@ -41,7 +41,7 @@ public class BasicAuthAuthenticator implements WebappAuthenticator { } @Override - public String getAuthenticatorName() { + public String getName() { return BasicAuthAuthenticator.BASIC_AUTH_AUTHENTICATOR; } 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 e3fe120c3b..113c083c3a 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 @@ -37,7 +37,7 @@ import java.util.StringTokenizer; 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 final Log log = LogFactory.getLog(OAuthAuthenticator.class); @@ -97,7 +97,7 @@ public class OAuthAuthenticator implements WebappAuthenticator { } @Override - public String getAuthenticatorName() { + public String getName() { return OAuthAuthenticator.OAUTH_AUTHENTICATOR; } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkBundleActivator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkBundleActivator.java index 59479ac166..b9cab8d1f7 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkBundleActivator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkBundleActivator.java @@ -24,7 +24,10 @@ import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve; 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.WebappAuthenticatorRepository; +import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig; import org.wso2.carbon.webapp.authenticator.framework.config.WebappAuthenticatorConfig; import java.util.ArrayList; @@ -41,6 +44,14 @@ public class WebappAuthenticatorFrameworkBundleActivator implements BundleActiva } try { WebappAuthenticatorConfig.init(); + + WebappAuthenticatorRepository repository = new WebappAuthenticatorRepository(); + for (AuthenticatorConfig config : WebappAuthenticatorConfig.getInstance().getAuthenticators()) { + WebappAuthenticator authenticator = + (WebappAuthenticator) Class.forName(config.getClassName()).newInstance(); + repository.addAuthenticator(authenticator); + } + List valves = new ArrayList(); valves.add(new WebappAuthenticatorFrameworkValve()); TomcatValveContainer.addValves(valves); From abf1e3d2eaf6f4190c30f0ad4c61e3c14b6c17b7 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 21 May 2015 19:16:40 +0530 Subject: [PATCH 3/3] Fixing build failures --- .../WebappAuthenticatorRepository.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepository.java diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepository.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepository.java new file mode 100644 index 0000000000..02a86ce9cc --- /dev/null +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepository.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015, 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; + +import java.util.HashMap; +import java.util.Map; + +public class WebappAuthenticatorRepository { + + private Map authenticators; + + public WebappAuthenticatorRepository() { + this.authenticators = new HashMap(); + } + + public void addAuthenticator(WebappAuthenticator authenticator) { + authenticators.put(authenticator.getName(), authenticator); + } + + public WebappAuthenticator getAuthenticator(String name) { + return authenticators.get(name); + } + +}