mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Refactored Dynamic-client registration service to use AppMgt osgi service
This commit is contained in:
parent
69ba3e83ea
commit
1c8bb7551d
@ -67,7 +67,8 @@ public class APIPublisherUtil {
|
||||
api.setEndpointSecured(true);
|
||||
api.setStatus(APIStatus.PUBLISHED);
|
||||
api.setTransports(config.getTransports());
|
||||
|
||||
api.setAsDefaultVersion(true);
|
||||
api.setAsPublishedDefaultVersion(true);
|
||||
return api;
|
||||
}
|
||||
|
||||
|
||||
@ -36,6 +36,10 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
@ -47,7 +51,6 @@
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>Dynamic Client Registration Bundle</Bundle-Description>
|
||||
<Bundle-Activator>org.wso2.carbon.dynamic.client.registration.internal.DynamicClientRegistrationBundleActivator</Bundle-Activator>
|
||||
<Private-Package>org.wso2.carbon.dynamic.client.registration.internal</Private-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.dynamic.client.registration.internal,
|
||||
|
||||
@ -25,6 +25,7 @@ import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.context.RegistryType;
|
||||
import org.wso2.carbon.dynamic.client.registration.*;
|
||||
import org.wso2.carbon.dynamic.client.registration.internal.DynamicClientRegistrationDataHolder;
|
||||
import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile;
|
||||
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
|
||||
import org.wso2.carbon.identity.application.common.model.*;
|
||||
@ -153,7 +154,8 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
||||
|
||||
serviceProvider.setDescription("Service Provider for application " + applicationName);
|
||||
|
||||
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
|
||||
ApplicationManagementService appMgtService = DynamicClientRegistrationDataHolder.
|
||||
getInstance().getApplicationManagementService();
|
||||
if (appMgtService == null) {
|
||||
throw new IllegalStateException(
|
||||
"Error occurred while retrieving Application Management" +
|
||||
@ -164,7 +166,7 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
||||
applicationName, tenantDomain);
|
||||
|
||||
if (existingServiceProvider == null) {
|
||||
appMgtService.createApplication(serviceProvider, userName, tenantDomain);
|
||||
appMgtService.createApplication(serviceProvider, tenantDomain, userName);
|
||||
}
|
||||
|
||||
ServiceProvider createdServiceProvider = appMgtService.getServiceProvider(
|
||||
@ -324,7 +326,8 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
||||
try {
|
||||
oAuthAdminService.removeOAuthApplicationData(consumerKey);
|
||||
|
||||
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
|
||||
ApplicationManagementService appMgtService = DynamicClientRegistrationDataHolder.
|
||||
getInstance().getApplicationManagementService();
|
||||
|
||||
if (appMgtService == null) {
|
||||
throw new IllegalStateException(
|
||||
@ -357,15 +360,17 @@ public class DynamicClientRegistrationImpl implements DynamicClientRegistrationS
|
||||
|
||||
@Override
|
||||
public boolean isOAuthApplicationExists(String applicationName) throws DynamicClientRegistrationException {
|
||||
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
|
||||
ApplicationManagementService appMgtService = DynamicClientRegistrationDataHolder.
|
||||
getInstance().getApplicationManagementService();
|
||||
if (appMgtService == null) {
|
||||
throw new IllegalStateException(
|
||||
"Error occurred while retrieving Application Management" +
|
||||
"Service");
|
||||
}
|
||||
try {
|
||||
if (ApplicationManagementService.getInstance().getServiceProvider(applicationName,
|
||||
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()) != null) {
|
||||
if (appMgtService.getServiceProvider(applicationName,
|
||||
CarbonContext.getThreadLocalCarbonContext()
|
||||
.getTenantDomain()) != null) {
|
||||
return true;
|
||||
}
|
||||
} catch (IdentityApplicationManagementException e) {
|
||||
|
||||
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.dynamic.client.registration.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService;
|
||||
import org.wso2.carbon.dynamic.client.registration.impl.DynamicClientRegistrationImpl;
|
||||
|
||||
/**
|
||||
* BundleActivator class of DynamicClientRegistration component.
|
||||
*/
|
||||
public class DynamicClientRegistrationBundleActivator implements BundleActivator{
|
||||
|
||||
private static final Log log = LogFactory.getLog(DynamicClientRegistrationBundleActivator.class);
|
||||
|
||||
@Override
|
||||
public void start(BundleContext bundleContext) throws Exception {
|
||||
DynamicClientRegistrationService dynamicClientRegistrationService =
|
||||
new DynamicClientRegistrationImpl();
|
||||
bundleContext.registerService(DynamicClientRegistrationService.class.getName(),
|
||||
dynamicClientRegistrationService, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(BundleContext bundleContext) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.dynamic.client.registration.internal;
|
||||
|
||||
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
|
||||
|
||||
/**
|
||||
* DataHolder class of DynamicClientRegistration bundle. This hold a reference to
|
||||
* ApplicationManagementService.
|
||||
*/
|
||||
public class DynamicClientRegistrationDataHolder {
|
||||
|
||||
private ApplicationManagementService applicationManagementService;
|
||||
|
||||
private static DynamicClientRegistrationDataHolder thisInstance =
|
||||
new DynamicClientRegistrationDataHolder();
|
||||
|
||||
private DynamicClientRegistrationDataHolder() {
|
||||
}
|
||||
|
||||
public static DynamicClientRegistrationDataHolder getInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public ApplicationManagementService getApplicationManagementService() {
|
||||
if (applicationManagementService == null) {
|
||||
throw new IllegalStateException("ApplicationManagementService is not initialized properly");
|
||||
}
|
||||
return applicationManagementService;
|
||||
}
|
||||
|
||||
public void setApplicationManagementService(ApplicationManagementService realmService) {
|
||||
this.applicationManagementService = realmService;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.dynamic.client.registration.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService;
|
||||
import org.wso2.carbon.dynamic.client.registration.impl.DynamicClientRegistrationImpl;
|
||||
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.dynamic.client.registration" immediate="true"
|
||||
* @scr.reference name="identity.application.management.service"
|
||||
* interface="org.wso2.carbon.identity.application.mgt.ApplicationManagementService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setApplicationManagementService"
|
||||
* unbind="unsetApplicationManagementService"
|
||||
*/
|
||||
public class DynamicClientRegistrationServiceComponent {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DynamicClientRegistrationServiceComponent.class);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
if(log.isDebugEnabled()){
|
||||
log.debug("Starting DynamicClientRegistrationServiceComponent");
|
||||
}
|
||||
DynamicClientRegistrationService dynamicClientRegistrationService =
|
||||
new DynamicClientRegistrationImpl();
|
||||
componentContext.getBundleContext().registerService(DynamicClientRegistrationService.class.getName(),
|
||||
dynamicClientRegistrationService, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void deactivate(ComponentContext componentContext) {
|
||||
if(log.isDebugEnabled()){
|
||||
log.debug("Stopping DynamicClientRegistrationServiceComponent");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ApplicationManagement Service.
|
||||
*
|
||||
* @param applicationManagementService An instance of ApplicationManagementService
|
||||
*/
|
||||
protected void setApplicationManagementService(ApplicationManagementService
|
||||
applicationManagementService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting ApplicationManagement Service");
|
||||
}
|
||||
DynamicClientRegistrationDataHolder.getInstance().
|
||||
setApplicationManagementService(applicationManagementService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets ApplicationManagement Service.
|
||||
*
|
||||
* @param applicationManagementService An instance of ApplicationManagementService
|
||||
*/
|
||||
protected void unsetApplicationManagementService(ApplicationManagementService
|
||||
applicationManagementService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Unsetting ApplicationManagement Service");
|
||||
}
|
||||
DynamicClientRegistrationDataHolder.getInstance().setApplicationManagementService(null);
|
||||
}
|
||||
}
|
||||
@ -37,7 +37,7 @@ import java.util.Properties;
|
||||
* Custom OAuth2Token Scope validation implementation for DeviceManagement. This will validate the
|
||||
* user permissions before dispatching the HTTP request to the actual endpoint.
|
||||
*/
|
||||
public class ScopeValidator extends OAuth2ScopeValidator {
|
||||
public class PermissionBasedScopeValidator extends OAuth2ScopeValidator {
|
||||
|
||||
private static final String URL_PROPERTY = "URL";
|
||||
private static final String HTTP_METHOD_PROPERTY = "HTTP_METHOD";
|
||||
@ -52,7 +52,7 @@ public class ScopeValidator extends OAuth2ScopeValidator {
|
||||
public static final String ACTION = "action";
|
||||
}
|
||||
|
||||
private static final Log log = LogFactory.getLog(ScopeValidator.class);
|
||||
private static final Log log = LogFactory.getLog(PermissionBasedScopeValidator.class);
|
||||
|
||||
@Override
|
||||
public boolean validateScope(AccessTokenDO accessTokenDO, String resource)
|
||||
@ -64,8 +64,8 @@ public class ScopeValidator extends OAuth2ScopeValidator {
|
||||
String method = resource.substring(++idx, resource.length());
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.put(ScopeValidator.URL_PROPERTY, url);
|
||||
properties.put(ScopeValidator.HTTP_METHOD_PROPERTY, method);
|
||||
properties.put(PermissionBasedScopeValidator.URL_PROPERTY, url);
|
||||
properties.put(PermissionBasedScopeValidator.HTTP_METHOD_PROPERTY, method);
|
||||
PermissionManagerService permissionManagerService = OAuthExtensionsDataHolder.getInstance().
|
||||
getPermissionManagerService();
|
||||
try {
|
||||
Loading…
Reference in New Issue
Block a user