Java Code Examples for org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil#rollBack()

The following examples show how to use org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil#rollBack() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProvisioningManagementDAO.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Get provisioned entity name by providing SCIM ID (ENTITY_LOCAL_ID)
 * @param localId
 * @return
 * @throws IdentityApplicationManagementException
 */
public String getProvisionedEntityNameByLocalId(String localId) throws IdentityApplicationManagementException {
    Connection dbConnection = null;
    String sqlStmt = null;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    try {
        dbConnection = JDBCPersistenceManager.getInstance().getDBConnection();
        sqlStmt = IdentityProvisioningConstants.SQLQueries.GET_PROVISIONED_ENTITY_NAME_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setString(1, localId);
        rs = prepStmt.executeQuery();
        if (rs.next()) {
            return rs.getString(1);
        } else {
            throw new IdentityApplicationManagementException("Given Local ID :"+localId+" does not exist");
        }
    } catch (SQLException e) {
        IdentityApplicationManagementUtil.rollBack(dbConnection);
        throw new IdentityApplicationManagementException(
                "Error occurred while loading Provisioned Entity Name from DB", e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
    }
}
 
Example 2
Source File: IdPManagementDAO.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param idPName
 * @param tenantId
 * @param tenantDomain
 * @throws IdentityProviderManagementException
 */
public void deleteIdP(String idPName, int tenantId, String tenantDomain)
        throws IdentityProviderManagementException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    try {
        IdentityProvider identityProvider = getIdPByName(dbConnection, idPName, tenantId,
                tenantDomain);
        if (identityProvider == null) {
            String msg = "Trying to delete non-existent Identity Provider for tenant "
                    + tenantDomain;
            log.error(msg);
            return;
        }
        deleteIdP(dbConnection, tenantId, idPName);
        dbConnection.commit();
    } catch (SQLException e) {
        IdentityApplicationManagementUtil.rollBack(dbConnection);
        throw new IdentityProviderManagementException("Error occurred while deleting Identity Provider of tenant "
                + tenantDomain, e);
    } finally {
        IdentityDatabaseUtil.closeConnection(dbConnection);
    }
}
 
Example 3
Source File: IdPManagementDAO.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public void deleteTenantRole(int tenantId, String role, String tenantDomain)
        throws IdentityProviderManagementException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    try {
        String sqlStmt = IdPManagementConstants.SQLQueries.DELETE_ROLE_LISTENER_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setString(2, role);
        prepStmt.executeUpdate();
        dbConnection.commit();
    } catch (SQLException e) {
        IdentityApplicationManagementUtil.rollBack(dbConnection);
        throw new IdentityProviderManagementException("Error occurred while deleting tenant role " + role +
                " of tenant " + tenantDomain, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(dbConnection, null, prepStmt);
    }
}
 
Example 4
Source File: IdPManagementDAO.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public void renameTenantRole(String newRoleName, String oldRoleName, int tenantId,
                             String tenantDomain) throws IdentityProviderManagementException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    try {
        String sqlStmt = IdPManagementConstants.SQLQueries.RENAME_ROLE_LISTENER_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setString(1, newRoleName);
        prepStmt.setInt(2, tenantId);
        prepStmt.setString(3, oldRoleName);
        prepStmt.executeUpdate();
        dbConnection.commit();
    } catch (SQLException e) {
        IdentityApplicationManagementUtil.rollBack(dbConnection);
        throw new IdentityProviderManagementException("Error occurred while renaming tenant role " + oldRoleName + " to "
                + newRoleName + " of tenant " + tenantDomain, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(dbConnection, null, prepStmt);
    }
}
 
Example 5
Source File: ProvisioningManagementDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param identityProviderName
 * @param connectorType
 * @param provisioningEntity
 * @param tenantId
 * @throws IdentityApplicationManagementException
 */
public void deleteProvisioningEntity(String identityProviderName, String connectorType,
                                     ProvisioningEntity provisioningEntity, int tenantId)
        throws IdentityApplicationManagementException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    try {

        PreparedStatement prepStmt = null;

        // id of the identity provider
        int idpId = getIdentityProviderIdentifier(dbConnection, identityProviderName, tenantId);

        // id of the provisioning configuration
        int provisioningConfigId = getProvisioningConfigurationIdentifier(dbConnection, idpId,
                connectorType);

        // PROVISIONING_CONFIG_ID, ENTITY_TYPE,
        // ENTITY_LOCAL_USERSTORE, ENTITY_NAME, TENANT_ID
        String sqlStmt = IdentityProvisioningConstants.SQLQueries.DELETE_PROVISIONING_ENTITY_SQL;

        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, provisioningConfigId);
        prepStmt.setString(2, provisioningEntity.getEntityType().toString());
        prepStmt.setString(3, IdentityUtil.extractDomainFromName(provisioningEntity.getEntityName()));
        prepStmt.setString(4, UserCoreUtil.removeDomainFromName(provisioningEntity.getEntityName()));
        prepStmt.setInt(5, tenantId);

        prepStmt.execute();
        dbConnection.commit();
    } catch (SQLException e) {
        IdentityApplicationManagementUtil.rollBack(dbConnection);
        String msg = "Error occurred while deleting Provisioning entity for tenant " + tenantId;
        throw new IdentityApplicationManagementException(msg, e);
    } finally {
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
}
 
Example 6
Source File: ProvisioningManagementDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Applicable for only group name update
 *
 * @param provisioningEntity
 * @throws IdentityApplicationManagementException
 */
public void updateProvisioningEntityName(ProvisioningEntity provisioningEntity) throws
                                                                                IdentityApplicationManagementException {

    Connection dbConnection = null;
    String provisioningEntityName = null;
    String entityLocalID = null;
    PreparedStatement prepStmt = null;
    try {
        dbConnection = JDBCPersistenceManager.getInstance().getDBConnection();

        String sqlStmt = IdentityProvisioningConstants.SQLQueries.UPDATE_PROVISIONED_ENTITY_NAME_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);

        provisioningEntityName = ProvisioningUtil.getAttributeValue(provisioningEntity,
                                                                    IdentityProvisioningConstants.NEW_GROUP_NAME_CLAIM_URI);
        entityLocalID = ProvisioningUtil.getAttributeValue(provisioningEntity,
                                                           IdentityProvisioningConstants.ID_CLAIM_URI);

        prepStmt.setString(1, provisioningEntityName);
        prepStmt.setString(2, entityLocalID);

        prepStmt.execute();
        dbConnection.commit();
    } catch (SQLException e) {
        IdentityApplicationManagementUtil.rollBack(dbConnection);
        String msg = "Error occurred while Updating Provisioning entity name to " + provisioningEntityName +
                     " for Entity Local Id :" + entityLocalID;
        throw new IdentityApplicationManagementException(msg, e);
    } finally {
        DatabaseUtil.closeAllConnections(dbConnection, prepStmt);
    }
}
 
Example 7
Source File: ProvisioningManagementDAO.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param identityProviderName
 * @param connectorType
 * @param provisioningEntity
 * @param tenantId
 * @throws IdentityApplicationManagementException
 */
public void addProvisioningEntity(String identityProviderName, String connectorType,
                                  ProvisioningEntity provisioningEntity, int tenantId)
        throws IdentityApplicationManagementException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    try {

        PreparedStatement prepStmt = null;

        // id of the identity provider
        int idpId = getIdentityProviderIdentifier(dbConnection, identityProviderName, tenantId);

        // id of the provisioning configuration
        int provisioningConfigId = getProvisioningConfigurationIdentifier(dbConnection, idpId,
                connectorType);

        String localId = getLocalIdFromProvisioningEntity(provisioningEntity);
        // PROVISIONING_CONFIG_ID, ENTITY_TYPE,
        // ENTITY_LOCAL_USERSTORE, ENTITY_NAME, ENTITY_VALUE,
        // TENANT_ID
        String sqlStmt = IdentityProvisioningConstants.SQLQueries.ADD_PROVISIONING_ENTITY_SQL;

        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, provisioningConfigId);
        prepStmt.setString(2, provisioningEntity.getEntityType().toString());
        prepStmt.setString(3, IdentityUtil.extractDomainFromName(provisioningEntity.getEntityName()));
        prepStmt.setString(4, UserCoreUtil.removeDomainFromName(provisioningEntity.getEntityName()));
        prepStmt.setString(5, provisioningEntity.getIdentifier().getIdentifier());
        prepStmt.setInt(6, tenantId);
        prepStmt.setString(7, localId);

        prepStmt.execute();
        dbConnection.commit();
    } catch (SQLException e) {
        IdentityApplicationManagementUtil.rollBack(dbConnection);
        String msg = "Error occurred while adding Provisioning entity for tenant " + tenantId;
        throw new IdentityApplicationManagementException(msg, e);
    } finally {
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
}
 
Example 8
Source File: ProvisioningManagementDAO.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param identityProviderName
 * @param connectorType
 * @param provisioningEntity
 * @param tenantId
 * @throws IdentityApplicationManagementException
 */
public ProvisionedIdentifier getProvisionedIdentifier(String identityProviderName, String connectorType,
                                                      ProvisioningEntity provisioningEntity, int tenantId)
        throws IdentityApplicationManagementException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    try {

        PreparedStatement prepStmt = null;

        // id of the identity provider
        int idpId = getIdentityProviderIdentifier(dbConnection, identityProviderName, tenantId);

        // id of the provisioning configuration
        int provisioningConfigId = getProvisioningConfigurationIdentifier(dbConnection, idpId,
                connectorType);

        // PROVISIONING_CONFIG_ID, ENTITY_TYPE,
        // ENTITY_LOCAL_USERSTORE, ENTITY_NAME, ENTITY_VALUE,
        // TENANT_ID
        String sqlStmt = IdentityProvisioningConstants.SQLQueries.GET_PROVISIONING_ENTITY_SQL;

        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, provisioningConfigId);
        prepStmt.setString(2, provisioningEntity.getEntityType().toString());
        prepStmt.setString(3, IdentityUtil.extractDomainFromName(provisioningEntity.getEntityName()));
        prepStmt.setString(4, UserCoreUtil.removeDomainFromName(provisioningEntity.getEntityName()));
        prepStmt.setInt(5, tenantId);


        ResultSet rs = prepStmt.executeQuery();
        dbConnection.commit();
        if (rs.next()) {
            String entityId = rs.getString(1);
            ProvisionedIdentifier provisionedIdentifier = new ProvisionedIdentifier();
            provisionedIdentifier.setIdentifier(entityId);
            return provisionedIdentifier;
        } else {
            return null;
        }

    } catch (SQLException e) {
        IdentityApplicationManagementUtil.rollBack(dbConnection);
        String msg = "Error occurred while adding Provisioning entity for tenant " + tenantId;
        throw new IdentityApplicationManagementException(msg, e);
    } finally {
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
}
 
Example 9
Source File: IdPManagementDAO.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param dbConnection
 * @param tenantId
 * @param tenantDomain
 * @return
 * @throws IdentityProviderManagementException
 */
public List<IdentityProvider> getIdPs(Connection dbConnection, int tenantId, String tenantDomain)
        throws IdentityProviderManagementException {

    boolean dbConnInitialized = true;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    List<IdentityProvider> idps = new ArrayList<IdentityProvider>();
    if (dbConnection == null) {
        dbConnection = IdentityDatabaseUtil.getDBConnection();
    } else {
        dbConnInitialized = false;
    }
    try {

        String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDPS_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setInt(2, MultitenantConstants.SUPER_TENANT_ID);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            IdentityProvider identityProvider = new IdentityProvider();
            identityProvider.setIdentityProviderName(rs.getString(1));
            if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_PRIMARY"))) {
                identityProvider.setPrimary(true);
            } else {
                identityProvider.setPrimary(false);
            }
            identityProvider.setHomeRealmId(rs.getString("HOME_REALM_ID"));
            identityProvider.setIdentityProviderDescription(rs.getString("DESCRIPTION"));

            // IS_FEDERATION_HUB_IDP
            if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_FEDERATION_HUB"))) {
                identityProvider.setFederationHub(false);
            }

            // IS_LOCAL_CLAIM_DIALECT
            if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_LOCAL_CLAIM_DIALECT"))) {
                if (identityProvider.getClaimConfig() == null) {
                    identityProvider.setClaimConfig(new ClaimConfig());
                }
                identityProvider.getClaimConfig().setLocalClaimDialect(true);
            }

            // IS_ENABLE
            if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_ENABLED"))) {
                identityProvider.setEnable(true);
            } else {
                identityProvider.setEnable(false);
            }

            identityProvider.setDisplayName(rs.getString("DISPLAY_NAME"));

            if (!IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME
                    .equals(identityProvider.getIdentityProviderName())) {
                idps.add(identityProvider);
            }
            List<IdentityProviderProperty> propertyList = getIdentityPropertiesByIdpId(dbConnection,
                    Integer.parseInt(rs.getString("ID")));
            identityProvider
                    .setIdpProperties(propertyList.toArray(new IdentityProviderProperty[propertyList.size()]));

        }
        dbConnection.commit();
        return idps;
    } catch (SQLException e) {
        IdentityApplicationManagementUtil.rollBack(dbConnection);
        throw new IdentityProviderManagementException("Error occurred while retrieving registered Identity " +
                "Provider Entity IDs " + "for tenant " + tenantDomain, e);
    } finally {
        if (dbConnInitialized) {
            IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
        }else{
            IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
        }
    }
}