use of org.wso2.carbon.identity.role.mgt.core.Role 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.role.mgt.core.Role 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;
}
use of org.wso2.carbon.identity.role.mgt.core.Role in project carbon-identity-framework by wso2.
the class IdPManagementDAO method populateRequiredAttributesForIdentityProviderList.
/**
* @param resultSet ResultSet.
* @param dbConnection Database Connection.
* @param requiredAttributes Required attributes which needs to be return.
* @param tenantId Tenant Id of the identity provider.
* @param identityProvider Identity Provider Object.
* @throws SQLException
* @throws IdentityProviderManagementServerException
*/
private void populateRequiredAttributesForIdentityProviderList(ResultSet resultSet, Connection dbConnection, List<String> requiredAttributes, int tenantId, IdentityProvider identityProvider) throws SQLException, IdentityProviderManagementServerException {
int idpId = Integer.parseInt(identityProvider.getId());
String idPName = identityProvider.getIdentityProviderName();
try {
if (CollectionUtils.isNotEmpty(requiredAttributes)) {
for (String attribute : requiredAttributes) {
switch(attribute) {
case IdPManagementConstants.IDP_IS_PRIMARY:
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("IS_PRIMARY"))) {
identityProvider.setPrimary(true);
} else {
identityProvider.setPrimary(false);
}
break;
case IdPManagementConstants.IDP_HOME_REALM_ID:
identityProvider.setHomeRealmId(resultSet.getString("HOME_REALM_ID"));
break;
case IdPManagementConstants.IDP_IS_FEDERATION_HUB:
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("IS_FEDERATION_HUB"))) {
identityProvider.setFederationHub(false);
}
break;
case IdPManagementConstants.IDP_CERTIFICATE:
identityProvider.setCertificate(getBlobValue(resultSet.getBinaryStream("CERTIFICATE")));
break;
case IdPManagementConstants.IDP_ALIAS:
identityProvider.setAlias(resultSet.getString("ALIAS"));
break;
case IdPManagementConstants.IDP_CLAIMS:
if (identityProvider.getClaimConfig() == null) {
identityProvider.setClaimConfig(new ClaimConfig());
}
if (IdPManagementConstants.IS_TRUE_VALUE.equals(resultSet.getString("IS_LOCAL_CLAIM_DIALECT"))) {
identityProvider.getClaimConfig().setLocalClaimDialect(true);
} else {
identityProvider.getClaimConfig().setLocalClaimDialect(false);
}
String userClaimUri = resultSet.getString("USER_CLAIM_URI");
String roleClaimUri = resultSet.getString("ROLE_CLAIM_URI");
if (identityProvider.getClaimConfig().isLocalClaimDialect()) {
identityProvider.setClaimConfig(getLocalIdPDefaultClaimValues(dbConnection, idPName, userClaimUri, roleClaimUri, idpId, tenantId));
} else {
// Get claim configuration.
identityProvider.setClaimConfig(getIdPClaimConfiguration(dbConnection, idPName, userClaimUri, roleClaimUri, idpId, tenantId));
}
break;
case IdPManagementConstants.IDP_ROLES:
identityProvider.setProvisioningRole(resultSet.getString("PROVISIONING_ROLE"));
// Get permission and role configuration.
identityProvider.setPermissionAndRoleConfig(getPermissionsAndRoleConfiguration(dbConnection, idPName, idpId, tenantId));
break;
case IdPManagementConstants.IDP_FEDERATED_AUTHENTICATORS:
String defaultAuthenticatorName = resultSet.getString("DEFAULT_AUTHENTICATOR_NAME");
// Get federated authenticators.
identityProvider.setFederatedAuthenticatorConfigs(getFederatedAuthenticatorConfigs(dbConnection, idPName, identityProvider, tenantId));
if (defaultAuthenticatorName != null && identityProvider.getFederatedAuthenticatorConfigs() != null) {
identityProvider.setDefaultAuthenticatorConfig(IdentityApplicationManagementUtil.getFederatedAuthenticator(identityProvider.getFederatedAuthenticatorConfigs(), defaultAuthenticatorName));
}
break;
case IdPManagementConstants.IDP_PROVISIONING:
JustInTimeProvisioningConfig jitProConfig = new JustInTimeProvisioningConfig();
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("INBOUND_PROV_ENABLED"))) {
jitProConfig.setProvisioningEnabled(true);
} else {
jitProConfig.setProvisioningEnabled(false);
}
jitProConfig.setProvisioningUserStore(resultSet.getString("INBOUND_PROV_USER_STORE_ID"));
identityProvider.setJustInTimeProvisioningConfig(jitProConfig);
String defaultProvisioningConnectorConfigName = resultSet.getString("DEFAULT_PRO_CONNECTOR_NAME");
if (defaultProvisioningConnectorConfigName != null) {
ProvisioningConnectorConfig defaultProConnector = new ProvisioningConnectorConfig();
defaultProConnector.setName(defaultProvisioningConnectorConfigName);
identityProvider.setDefaultProvisioningConnectorConfig(defaultProConnector);
}
// Get provisioning connectors.
identityProvider.setProvisioningConnectorConfigs(getProvisioningConnectorConfigs(dbConnection, idPName, idpId, tenantId));
break;
}
}
}
} catch (IdentityProviderManagementException e) {
throw new IdentityProviderManagementServerException("Error occurred while performing required " + "attribute filter", e);
}
}
use of org.wso2.carbon.identity.role.mgt.core.Role in project carbon-identity-framework by wso2.
the class IdPManagementDAO method getPermissionsAndRoleConfiguration.
/**
* @param dbConnection
* @param idPName
* @param tenantId
* @return
* @throws IdentityProviderManagementException
* @throws SQLException
*/
public PermissionsAndRoleConfig getPermissionsAndRoleConfiguration(Connection dbConnection, String idPName, int idPId, int tenantId) throws SQLException {
PreparedStatement prepStmt1 = null;
PreparedStatement prepStmt2 = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
PermissionsAndRoleConfig permissionRoleConfiguration = new PermissionsAndRoleConfig();
try {
List<String> idpRoleList = new ArrayList<String>();
// SP_IDP_ROLE
String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_ROLES_SQL;
prepStmt1 = dbConnection.prepareStatement(sqlStmt);
prepStmt1.setInt(1, idPId);
rs1 = prepStmt1.executeQuery();
while (rs1.next()) {
idpRoleList.add(rs1.getString("ROLE"));
}
permissionRoleConfiguration.setIdpRoles(idpRoleList.toArray(new String[idpRoleList.size()]));
List<RoleMapping> roleMappings = new ArrayList<RoleMapping>();
// SP_IDP_ROLE_MAPPINGS.SP_USER_STORE_ID, SP_IDP_ROLE_MAPPINGS.SP_LOCAL_ROLE,
// SP_IDP_ROLES.SP_IDP_ROLE
sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_ROLE_MAPPINGS_SQL;
prepStmt2 = dbConnection.prepareStatement(sqlStmt);
prepStmt2.setInt(1, idPId);
rs2 = prepStmt2.executeQuery();
while (rs2.next()) {
LocalRole localRole = new LocalRole(rs2.getString("USER_STORE_ID"), rs2.getString("LOCAL_ROLE"));
RoleMapping roleMapping = new RoleMapping(localRole, rs2.getString("ROLE"));
roleMappings.add(roleMapping);
}
permissionRoleConfiguration.setRoleMappings(roleMappings.toArray(new RoleMapping[roleMappings.size()]));
return permissionRoleConfiguration;
} finally {
IdentityDatabaseUtil.closeAllConnections(null, rs2, prepStmt2);
IdentityDatabaseUtil.closeAllConnections(null, rs1, prepStmt1);
}
}
use of org.wso2.carbon.identity.role.mgt.core.Role in project carbon-identity-framework by wso2.
the class IdPManagementDAO method renameClaimURI.
/**
* @param newClaimURI
* @param oldClaimURI
* @param tenantId
* @param tenantDomain
* @throws IdentityProviderManagementException
*/
public void renameClaimURI(String newClaimURI, String oldClaimURI, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
;
PreparedStatement prepStmt = null;
try {
String sqlStmt = IdPManagementConstants.SQLQueries.RENAME_CLAIM_SQL;
prepStmt = dbConnection.prepareStatement(sqlStmt);
prepStmt.setString(1, newClaimURI);
prepStmt.setInt(2, tenantId);
prepStmt.setString(3, oldClaimURI);
prepStmt.executeUpdate();
IdentityDatabaseUtil.commitTransaction(dbConnection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
throw new IdentityProviderManagementException("Error occurred while renaming tenant role " + oldClaimURI + " to " + newClaimURI + " of tenant " + tenantDomain, e);
} finally {
IdentityDatabaseUtil.closeAllConnections(dbConnection, null, prepStmt);
}
}
Aggregations