Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application role management service #4859

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
~
~ WSO2 LLC. 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>application-role-mgt</artifactId>
<version>5.25.266-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.identity.application.role.mgt</artifactId>
<name>Application Role Management Service</name>
<packaging>bundle</packaging>

<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi.services</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.core</artifactId>
</dependency>
<!--Test Dependencies-->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Description>Application Role Management Service Bundle</Bundle-Description>
<Private-Package>org.wso2.carbon.identity.application.role.mgt.internal
</Private-Package>
<Export-Package>
!org.wso2.carbon.identity.application.role.mgt.internal,
org.wso2.carbon.identity.application.role.mgt.*;
version="${project.version}",
</Export-Package>
<Import-Package>
javax.sql,
org.osgi.framework; version="${osgi.framework.imp.pkg.version.range}",
org.osgi.service.component; version="${osgi.service.component.imp.pkg.version.range}",
org.apache.commons.lang; version="${commons-lang.wso2.osgi.version.range}",
org.apache.commons.logging; version="${import.package.version.commons.logging}",
org.wso2.carbon.context; version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.identity.core.*; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.database.utils.jdbc;
version="${org.wso2.carbon.database.utils.version.range}",
org.wso2.carbon.database.utils.jdbc.exceptions;version="${org.wso2.carbon.database.utils.version.range}",
org.wso2.carbon.utils; version="${carbon.kernel.package.import.version.range}",
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. 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.identity.application.role.mgt;

import org.wso2.carbon.identity.application.role.mgt.exceptions.ApplicationRoleManagementException;
import org.wso2.carbon.identity.application.role.mgt.model.ApplicationRole;

import java.util.List;

/**
* Application Role Manager.
*/
public interface ApplicationRoleManager {

/**
* Add application role.
*
* @param applicationRole Application role.
* @throws ApplicationRoleManagementException Error occurred while adding application role.
*/
void addApplicationRole(ApplicationRole applicationRole) throws ApplicationRoleManagementException;

/**
* Update application role.
*
* @param applicationRole Application role.
* @throws ApplicationRoleManagementException Error occurred while updating the application role.
*/
void updateApplicationRole(ApplicationRole applicationRole) throws ApplicationRoleManagementException;

/**
* Get the application role by role id.
*
* @param roleId Role id.
* @return Application role.
* @throws ApplicationRoleManagementException Error occurred while retrieving the application role.
*/
ApplicationRole getApplicationRoleById(String roleId) throws ApplicationRoleManagementException;

/**
* Get all the application roles by application id.
*
* @param applicationId Application id.
* @return Application roles.
* @throws ApplicationRoleManagementException Error occurred while retrieving the application roles of a given app.
*/
List<ApplicationRole> getApplicationRoles(String applicationId) throws ApplicationRoleManagementException;

/**
* Delete application role.
*
* @param roleId Role id.
* @throws ApplicationRoleManagementException Error occurred while deleting the application role.
*/
void deleteApplicationRole(String roleId) throws ApplicationRoleManagementException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. 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.identity.application.role.mgt;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.role.mgt.dao.ApplicationRoleMgtDAO;
import org.wso2.carbon.identity.application.role.mgt.dao.impl.ApplicationRoleMgtDAOImpl;
import org.wso2.carbon.identity.application.role.mgt.dao.impl.CacheBackedApplicationRoleMgtDAOImpl;
import org.wso2.carbon.identity.application.role.mgt.exceptions.ApplicationRoleManagementException;
import org.wso2.carbon.identity.application.role.mgt.model.ApplicationRole;

import java.util.List;

import static org.wso2.carbon.identity.application.role.mgt.constants.ApplicationRoleMgtConstants.ErrorMessages.ERROR_CODE_DUPLICATE_ROLE;
import static org.wso2.carbon.identity.application.role.mgt.util.ApplicationRoleMgtUtils.handleClientException;

/**
* Application role management service implementation.
*/
public class ApplicationRoleManagerImpl implements ApplicationRoleManager {

private final ApplicationRoleMgtDAO applicationRoleMgtDAO =
new CacheBackedApplicationRoleMgtDAOImpl(new ApplicationRoleMgtDAOImpl());

@Override
public void addApplicationRole(ApplicationRole applicationRole) throws ApplicationRoleManagementException {

String tenantDomain = getTenantDomain();
boolean existingRole =
applicationRoleMgtDAO.isExistingRole(applicationRole.getApplicationId(), applicationRole.getRoleName(),
tenantDomain);
if (existingRole) {
throw handleClientException(ERROR_CODE_DUPLICATE_ROLE, applicationRole.getRoleName(),
applicationRole.getApplicationId());
}
applicationRoleMgtDAO.addApplicationRole(applicationRole, tenantDomain);
}

@Override
public void updateApplicationRole(ApplicationRole applicationRole) throws ApplicationRoleManagementException {

// TODO.
}

@Override
public ApplicationRole getApplicationRoleById(String roleId) throws ApplicationRoleManagementException {

return applicationRoleMgtDAO.getApplicationRoleById(roleId, getTenantDomain());
}

@Override
public List<ApplicationRole> getApplicationRoles(String applicationId) throws ApplicationRoleManagementException {

return applicationRoleMgtDAO.getApplicationRoles(applicationId);
}

@Override
public void deleteApplicationRole(String roleId) throws ApplicationRoleManagementException {

applicationRoleMgtDAO.deleteApplicationRole(roleId, getTenantDomain());
}

private static String getTenantDomain() {

return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. 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.identity.application.role.mgt.cache;

import org.wso2.carbon.identity.core.cache.BaseCache;
import org.wso2.carbon.utils.CarbonUtils;

/**
* Cache implementation for application role cache.
*/
public class ApplicationRoleCache extends BaseCache<ApplicationRoleCacheKey, ApplicationRoleCacheEntry> {

private static final String CACHE_NAME = "ApplicationRoleCacheById";
private static final ApplicationRoleCache instance = new ApplicationRoleCache();

private ApplicationRoleCache() {

super(CACHE_NAME);
}

public static ApplicationRoleCache getInstance() {

CarbonUtils.checkSecurity();
return instance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. 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.identity.application.role.mgt.cache;

import org.wso2.carbon.identity.application.role.mgt.model.ApplicationRole;
import org.wso2.carbon.identity.core.cache.CacheEntry;

/**
* Cache entry which is kept in the application role cache.
*/
public class ApplicationRoleCacheEntry extends CacheEntry {

private static final long serialVersionUID = 3112605038259278777L;
private ApplicationRole applicationRole;

public ApplicationRoleCacheEntry(ApplicationRole applicationRole) {

this.applicationRole = applicationRole;
}

public ApplicationRole getApplicationRole() {

return applicationRole;
}

public void setApplicationRole(ApplicationRole applicationRole) {

this.applicationRole = applicationRole;
}
}
Loading
Loading