use of org.wso2.carbon.identity.application.common.model.RoleMapping in project carbon-apimgt by wso2.
the class SystemScopesApiServiceImpl method systemScopesRoleAliasesPut.
@Override
public Response systemScopesRoleAliasesPut(RoleAliasListDTO body, MessageContext messageContext) throws APIManagementException {
RoleAliasListDTO roleAliasListDTO = new RoleAliasListDTO();
JSONObject newRoleMappingJson = SystemScopesMappingUtil.createJsonObjectOfRoleMapping(body);
String username = RestApiCommonUtil.getLoggedInUsername();
String tenantDomain = MultitenantUtils.getTenantDomain(username);
APIUtil.updateTenantConfRoleAliasMapping(newRoleMappingJson, username);
JSONObject tenantConfig = APIUtil.getTenantConfig(tenantDomain);
JSONObject roleMapping = (JSONObject) tenantConfig.get(APIConstants.REST_API_ROLE_MAPPINGS_CONFIG);
if (roleMapping != null) {
roleAliasListDTO = SystemScopesMappingUtil.fromRoleAliasListToRoleAliasListDTO(SystemScopesMappingUtil.createMapOfRoleMapping((roleMapping)));
}
return Response.ok().entity(roleAliasListDTO).build();
}
use of org.wso2.carbon.identity.application.common.model.RoleMapping in project carbon-apimgt by wso2.
the class SystemScopesMappingUtil method fromRoleAliasObjectToRoleAliasDTOList.
/**
* Converts api scope-role mapping to RoleScopeDTO List.
*
* @param roleMapping Map of a Role Scope Mapping
* @return RoleScopeDTO list
*/
private static List<RoleAliasDTO> fromRoleAliasObjectToRoleAliasDTOList(Map<String, List<String>> roleMapping) {
List<RoleAliasDTO> roleAliasDTOS = new ArrayList<>(roleMapping.size());
for (Map.Entry<String, List<String>> mapping : roleMapping.entrySet()) {
RoleAliasDTO roleAliasDTO = new RoleAliasDTO();
roleAliasDTO.setRole(mapping.getKey());
roleAliasDTO.setAliases(mapping.getValue());
roleAliasDTOS.add(roleAliasDTO);
}
return roleAliasDTOS;
}
use of org.wso2.carbon.identity.application.common.model.RoleMapping in project carbon-identity-framework by wso2.
the class IdentityProviderManager method getMappedLocalRoles.
/**
* Retrieves Identity provider information about a given tenant
*
* @param idPName Unique name of the IdP to which the given IdP roles need to be mapped
* @param tenantDomain The tenant domain of whose local roles to be mapped
* @param idPRoles IdP roles which need to be mapped to local roles
* @throws IdentityProviderManagementException Error when getting role mappings
*/
@Override
public Set<RoleMapping> getMappedLocalRoles(String idPName, String tenantDomain, String[] idPRoles) throws IdentityProviderManagementException {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
if (StringUtils.isEmpty(idPName)) {
String msg = "Invalid argument: Identity Provider Name value is empty";
throw new IdentityProviderManagementException(msg);
}
IdentityProvider identityProvider = dao.getIdPByName(null, idPName, tenantId, tenantDomain);
if (identityProvider == null) {
identityProvider = new FileBasedIdPMgtDAO().getIdPByName(idPName, tenantDomain);
}
if (identityProvider == null) {
identityProvider = IdPManagementServiceComponent.getFileBasedIdPs().get(IdentityApplicationConstants.DEFAULT_IDP_CONFIG);
}
PermissionsAndRoleConfig roleConfiguration = identityProvider.getPermissionAndRoleConfig();
if (roleConfiguration != null) {
RoleMapping[] roleMappings = roleConfiguration.getRoleMappings();
if (roleMappings != null && roleMappings.length > 0 && idPRoles != null) {
Set<RoleMapping> returnSet = new HashSet<RoleMapping>();
for (String idPRole : idPRoles) {
for (RoleMapping roleMapping : roleMappings) {
if (roleMapping.getRemoteRole().equals(idPRole)) {
returnSet.add(roleMapping);
break;
}
}
}
return returnSet;
}
}
return new HashSet<RoleMapping>();
}
use of org.wso2.carbon.identity.application.common.model.RoleMapping in project carbon-identity-framework by wso2.
the class IdentityProviderManager method getMappedIdPRoles.
/**
* Retrieves Identity provider information about a given tenant
*
* @param idPName Unique name of the IdP to which the given local roles need to be mapped
* @param tenantDomain The tenant domain of whose local roles need to be mapped
* @param localRoles Local roles which need to be mapped to IdP roles
* @throws IdentityProviderManagementException Error when getting role mappings
*/
@Override
public Set<RoleMapping> getMappedIdPRoles(String idPName, String tenantDomain, LocalRole[] localRoles) throws IdentityProviderManagementException {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
if (StringUtils.isEmpty(idPName)) {
String msg = "Invalid argument: Identity Provider Name value is empty";
throw new IdentityProviderManagementException(msg);
}
IdentityProvider identityProvider = dao.getIdPByName(null, idPName, tenantId, tenantDomain);
if (identityProvider == null) {
identityProvider = new FileBasedIdPMgtDAO().getIdPByName(idPName, tenantDomain);
}
if (identityProvider == null) {
identityProvider = IdPManagementServiceComponent.getFileBasedIdPs().get(IdentityApplicationConstants.DEFAULT_IDP_CONFIG);
}
PermissionsAndRoleConfig roleConfiguration = identityProvider.getPermissionAndRoleConfig();
if (roleConfiguration != null) {
RoleMapping[] roleMappings = roleConfiguration.getRoleMappings();
if (roleMappings != null && roleMappings.length > 0 && localRoles != null) {
Set<RoleMapping> returnSet = new HashSet<RoleMapping>();
for (LocalRole localRole : localRoles) {
for (RoleMapping roleMapping : roleMappings) {
if (roleMapping.getLocalRole().equals(localRole)) {
returnSet.add(roleMapping);
break;
}
}
}
return returnSet;
}
}
return new HashSet<RoleMapping>();
}
use of org.wso2.carbon.identity.application.common.model.RoleMapping in project carbon-identity-framework by wso2.
the class IdentityProviderManager method getMappedIdPRolesMap.
/**
* Retrieves Identity provider information about a given tenant
*
* @param idPName Unique name of the IdP to which the given local roles need to be mapped
* @param tenantDomain The tenant domain of whose local roles need to be mapped
* @param localRoles Local roles which need to be mapped to IdP roles
* @throws IdentityProviderManagementException Error when getting role mappings
*/
@Override
public Map<LocalRole, String> getMappedIdPRolesMap(String idPName, String tenantDomain, LocalRole[] localRoles) throws IdentityProviderManagementException {
Set<RoleMapping> roleMappings = getMappedIdPRoles(idPName, tenantDomain, localRoles);
Map<LocalRole, String> returnMap = new HashMap<LocalRole, String>();
for (RoleMapping roleMapping : roleMappings) {
returnMap.put(roleMapping.getLocalRole(), roleMapping.getRemoteRole());
}
return returnMap;
}
Aggregations