Skip to content

Commit

Permalink
Introduce role properties object to store role related properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanChathusanda93 committed Dec 12, 2024
1 parent ed0296a commit 55515c6
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ private RoleConstants() {
public static final String NEW_ROLE_NAME = "newRoleName";
public static final String FAILURE_REASON = "failureReason";

// Role properties
public static final String IS_SHARED_ROLE_PROP_NAME = "isSharedRole";

/**
* Grouping of constants related to database table names.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleAudience;
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleBasicInfo;
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleDTO;
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleProperty;
import org.wso2.carbon.identity.role.v2.mgt.core.model.UserBasicInfo;
import org.wso2.carbon.identity.role.v2.mgt.core.util.GroupIDResolver;
import org.wso2.carbon.identity.role.v2.mgt.core.util.UserIDResolver;
Expand Down Expand Up @@ -213,6 +214,7 @@ public class RoleDAOImpl implements RoleDAO {
private static final String GROUPS = "groups";
private static final String PERMISSIONS = "permissions";
private static final String ASSOCIATED_APPLICATIONS = "associatedApplications";
private static final String PROPERTIES = "properties";

@Override
public RoleBasicInfo addRole(String roleName, List<String> userList, List<String> groupList,
Expand Down Expand Up @@ -425,6 +427,10 @@ private List<Role> getRolesRequestedAttributes(List<RoleBasicInfo> roles, List<S
role.setAssociatedApplications(associatedApplications);
}
}
if (requiredAttributes.contains(PROPERTIES)) {
role.setRoleProperty(buildRoleProperty(RoleConstants.IS_SHARED_ROLE_PROP_NAME,
String.valueOf(isSharedRole(roleBasicInfo.getId(), tenantDomain))));
}
}
rolesList.add(role);
}
Expand Down Expand Up @@ -460,13 +466,25 @@ public Role getRole(String roleId, String tenantDomain) throws IdentityRoleManag
role.setGroups(getGroupListOfRole(roleId, tenantDomain));
role.setIdpGroups(getIdpGroupListOfRole(roleId, tenantDomain));
if (isSharedRole(roleId, tenantDomain)) {
role.setRoleProperty(buildRoleProperty(RoleConstants.IS_SHARED_ROLE_PROP_NAME,
String.valueOf(Boolean.TRUE)));
role.setPermissions(getPermissionsOfSharedRole(roleId, tenantDomain));
} else {
role.setRoleProperty(buildRoleProperty(RoleConstants.IS_SHARED_ROLE_PROP_NAME,
String.valueOf(Boolean.FALSE)));
role.setPermissions(getPermissions(roleId, tenantDomain));
}
return role;
}

private RoleProperty buildRoleProperty(String propertyName, String propertyValue) {

RoleProperty roleProperty = new RoleProperty();
roleProperty.setName(propertyName);
roleProperty.setValue(propertyValue);
return roleProperty;
}

@Override
public Role getRole(String roleId) throws IdentityRoleManagementException {

Expand Down Expand Up @@ -937,8 +955,12 @@ public Role getRoleWithoutUsers(String roleId, String tenantDomain) throws Ident
role.setGroups(getGroupListOfRole(roleId, tenantDomain));
role.setIdpGroups(getIdpGroupListOfRole(roleId, tenantDomain));
if (isSharedRole(roleId, tenantDomain)) {
role.setRoleProperty(buildRoleProperty(RoleConstants.IS_SHARED_ROLE_PROP_NAME,
String.valueOf(Boolean.TRUE)));
role.setPermissions(getPermissionsOfSharedRole(roleId, tenantDomain));
} else {
role.setRoleProperty(buildRoleProperty(RoleConstants.IS_SHARED_ROLE_PROP_NAME,
String.valueOf(Boolean.FALSE)));
role.setPermissions(getPermissions(roleId, tenantDomain));
}
return role;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-2024, 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
Expand All @@ -18,6 +18,7 @@

package org.wso2.carbon.identity.role.v2.mgt.core.model;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -37,6 +38,7 @@ public class Role {
private String audienceId;
private String audienceName;
private List<AssociatedApplication> associatedApplications;
private List<RoleProperty> roleProperties = new ArrayList<>();

public Role() {

Expand Down Expand Up @@ -281,4 +283,34 @@ public void setAssociatedApplications(List<AssociatedApplication> associatedAppl

this.associatedApplications = associatedApplications;
}

/**
* Get the role properties.
*
* @return properties list of a role.
*/
public List<RoleProperty> getRoleProperties() {

return roleProperties;
}

/**
* Set the role properties.
*
* @param roleProperties properties list of a role.
*/
public void setRoleProperties(List<RoleProperty> roleProperties) {

this.roleProperties = roleProperties;
}

/**
* Set a role property to the role properties list.
*
* @param roleProperty a property of a role.
*/
public void setRoleProperty(RoleProperty roleProperty) {

this.roleProperties.add(roleProperty);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2024, 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.role.v2.mgt.core.model;

import java.io.Serializable;

/**
* Role property object to store the role specific property details.
*/
public class RoleProperty implements Serializable {

private static final long serialVersionUID = 1231265490501221547L;
private String name;
private String value;

/**
* Get the value of the property.
*
* @return value.
*/
public String getValue() {

return value;
}

/**
* Set the value of the property.
*
* @param value Value of the property.
*/
public void setValue(String value) {

this.value = value;
}

/**
* Get the name of the property.
*
* @return Name (This is the key).
*/
public String getName() {

return name;
}

/**
* Set the name of the property.
*
* @param name (This is the key).
*/
public void setName(String name) {

this.name = name;
}
}

0 comments on commit 55515c6

Please sign in to comment.