org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil Java Examples

The following examples show how to use org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil. 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: SAML2SSOFederatedAuthenticatorConfig.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isValid() {

    if (IdentityApplicationManagementUtil.getProperty(properties,
            IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID) != null
            && !"".equals(IdentityApplicationManagementUtil.getProperty(properties,
            IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID))
            && IdentityApplicationManagementUtil.getProperty(properties,
            IdentityApplicationConstants.Authenticator.SAML2SSO.SP_ENTITY_ID) != null
            && !"".equals(IdentityApplicationManagementUtil.getProperty(properties,
            IdentityApplicationConstants.Authenticator.SAML2SSO.SP_ENTITY_ID))
            && IdentityApplicationManagementUtil.getProperty(properties,
            IdentityApplicationConstants.Authenticator.SAML2SSO.SSO_URL) != null
            && !"".equals(IdentityApplicationManagementUtil.getProperty(properties,
            IdentityApplicationConstants.Authenticator.SAML2SSO.SSO_URL))) {
        return true;
    }
    return false;
}
 
Example #2
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 #3
Source File: IdPManagementUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public static int getIdleSessionTimeOut(String tenantDomain) {

        IdentityProviderManager identityProviderManager = IdentityProviderManager.getInstance();
        int timeout = Integer.parseInt(IdentityApplicationConstants.SESSION_IDLE_TIME_OUT_DEFAULT);

        try {
            IdentityProvider identityProvider = identityProviderManager.getResidentIdP(tenantDomain);
            IdentityProviderProperty idpProperty = IdentityApplicationManagementUtil.getProperty(
                    identityProvider.getIdpProperties(), IdentityApplicationConstants.SESSION_IDLE_TIME_OUT);
            if (idpProperty != null) {
                timeout = Integer.parseInt(idpProperty.getValue());
            }
        } catch (IdentityProviderManagementException e) {
            log.error("Error when accessing the IdentityProviderManager for tenant : " + tenantDomain, e);
        }
        return timeout * 60;
    }
 
Example #4
Source File: IdPManagementUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public static int getRememberMeTimeout(String tenantDomain) {

        IdentityProviderManager identityProviderManager = IdentityProviderManager.getInstance();
        int rememberMeTimeout = Integer.parseInt(IdentityApplicationConstants.REMEMBER_ME_TIME_OUT_DEFAULT);

        try {
            IdentityProvider identityProvider = identityProviderManager.getResidentIdP(tenantDomain);
            IdentityProviderProperty idpProperty = IdentityApplicationManagementUtil.getProperty(
                    identityProvider.getIdpProperties(), IdentityApplicationConstants.REMEMBER_ME_TIME_OUT);
            if (idpProperty != null) {
                rememberMeTimeout = Integer.parseInt(idpProperty.getValue());
            }
        } catch (IdentityProviderManagementException e) {
            log.error("Error when accessing the IdentityProviderManager for tenant : " + tenantDomain, e);
        }
        return rememberMeTimeout * 60;
    }
 
Example #5
Source File: OpenIDConnectFederatedAuthenticatorConfig.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isValid() {
    if (IdentityApplicationManagementUtil.getProperty(properties,
            IdentityApplicationConstants.Authenticator.OIDC.CLIENT_ID) != null &&
            !"".equals(IdentityApplicationManagementUtil.getProperty(properties,
                    IdentityApplicationConstants.Authenticator.OIDC.CLIENT_ID)) &&
            IdentityApplicationManagementUtil.getProperty(properties,
                    IdentityApplicationConstants.Authenticator.OIDC.CLIENT_SECRET) != null &&
            !"".equals(IdentityApplicationManagementUtil.getProperty(properties,
                    IdentityApplicationConstants.Authenticator.OIDC.CLIENT_SECRET)) &&
            IdentityApplicationManagementUtil.getProperty(properties,
                    IdentityApplicationConstants.Authenticator.OIDC.OAUTH2_AUTHZ_URL) != null &&
            !"".equals(IdentityApplicationManagementUtil.getProperty(properties,
                    IdentityApplicationConstants.Authenticator.OIDC.OAUTH2_AUTHZ_URL)) &&
            IdentityApplicationManagementUtil.getProperty(properties,
                    IdentityApplicationConstants.Authenticator.OIDC.OAUTH2_TOKEN_URL) != null &&
            !"".equals(IdentityApplicationManagementUtil.getProperty(properties,
                    IdentityApplicationConstants.Authenticator.OIDC.OAUTH2_TOKEN_URL))) {
        return true;
    }
    return false;
}
 
Example #6
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param conn
 * @param tenantId
 * @param authenticatorId
 * @return
 * @throws SQLException
 */
private Map<String, String> getAuthenticatorInfo(Connection conn, int tenantId,
                                                 int authenticatorId) throws SQLException {
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    String sqlStmt = ApplicationMgtDBQueries.LOAD_IDP_AND_AUTHENTICATOR_NAMES;
    Map<String, String> returnData = new HashMap<String, String>();
    try {
        prepStmt = conn.prepareStatement(sqlStmt);
        prepStmt.setInt(1, authenticatorId);
        prepStmt.setInt(2, tenantId);
        prepStmt.setInt(3, tenantId);
        prepStmt.setInt(4, MultitenantConstants.SUPER_TENANT_ID);
        prepStmt.setInt(5, MultitenantConstants.SUPER_TENANT_ID);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            returnData.put(ApplicationConstants.IDP_NAME, rs.getString(1));
            returnData.put(ApplicationConstants.IDP_AUTHENTICATOR_NAME, rs.getString(2));
            returnData
                    .put(ApplicationConstants.IDP_AUTHENTICATOR_DISPLAY_NAME, rs.getString(3));
        }
    } finally {
        IdentityApplicationManagementUtil.closeStatement(prepStmt);
    }
    return returnData;
}
 
Example #7
Source File: FileBasedIdPMgtDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public IdentityProvider getIdPByAuthenticatorPropertyValue(String property, String value, String tenantDomain,
                                                           String authenticatorName) {

    Map<String, IdentityProvider> identityProviders = IdPManagementServiceComponent.getFileBasedIdPs();
    for (Entry<String, IdentityProvider> entry : identityProviders.entrySet()) {
        FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = entry.getValue().
                getFederatedAuthenticatorConfigs();
        // Get SAML2 Web SSO authenticator
        FederatedAuthenticatorConfig samlAuthenticatorConfig = IdentityApplicationManagementUtil.
                getFederatedAuthenticator(federatedAuthenticatorConfigs, authenticatorName);
        if (samlAuthenticatorConfig != null) {
            Property samlProperty = IdentityApplicationManagementUtil.getProperty(samlAuthenticatorConfig.
                    getProperties(), property);
            if (samlProperty != null) {
                if (value.equalsIgnoreCase(samlProperty.getValue())) {
                    return entry.getValue();
                }
            }
        }
    }
    return null;
}
 
Example #8
Source File: IdPManagementUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public static int getIdleSessionTimeOut(String tenantDomain) {

        IdentityProviderManager identityProviderManager = IdentityProviderManager.getInstance();
        int timeout = Integer.parseInt(IdentityApplicationConstants.SESSION_IDLE_TIME_OUT_DEFAULT);

        try {
            IdentityProvider identityProvider = identityProviderManager.getResidentIdP(tenantDomain);
            IdentityProviderProperty idpProperty = IdentityApplicationManagementUtil.getProperty(
                    identityProvider.getIdpProperties(), IdentityApplicationConstants.SESSION_IDLE_TIME_OUT);
            if (idpProperty != null) {
                timeout = Integer.parseInt(idpProperty.getValue());
            }
        } catch (IdentityProviderManagementException e) {
            log.error("Error when accessing the IdentityProviderManager for tenant : " + tenantDomain, e);
        }
        return timeout * 60;
    }
 
Example #9
Source File: UserProfileMgtDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public void deleteAssociationsFromDomain(int tenantId, String domainName) throws
                                                                          UserProfileException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement preparedStatement = null;

    try {
        preparedStatement = dbConnection.prepareStatement(Constants.SQLQueries.DELETE_ASSOCIATED_ID_FROM_DOMAIN);
        preparedStatement.setInt(1, tenantId);
        preparedStatement.setString(2, domainName);
        preparedStatement.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(dbConnection);

    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(dbConnection);
        throw new UserProfileException(String.format("Database error occurred while deleting associated ids with " +
                                                     "domain '%s'", domainName), e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(preparedStatement);
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
}
 
Example #10
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param applicationID
 * @param connection
 * @throws SQLException
 */
private void deleteRequestPathAuthenticators(int applicationID, Connection connection)
        throws SQLException {

    if (log.isDebugEnabled()) {
        log.debug("Deleting request path authenticators " + applicationID);
    }

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    PreparedStatement deleteReqAuthPrepStmt = null;
    try {
        deleteReqAuthPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.REMOVE_REQ_PATH_AUTHENTICATOR);
        deleteReqAuthPrepStmt.setInt(1, applicationID);
        deleteReqAuthPrepStmt.setInt(2, tenantID);
        deleteReqAuthPrepStmt.execute();

    } finally {
        IdentityApplicationManagementUtil.closeStatement(deleteReqAuthPrepStmt);
    }
}
 
Example #11
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Deleting Clients of the Application
 *
 * @param applicationID
 * @param connection
 * @throws IdentityApplicationManagementException
 */
private void deleteInboundAuthRequestConfiguration(int applicationID, Connection connection)
        throws SQLException {

    if (log.isDebugEnabled()) {
        log.debug("Deleting Clients of the Application " + applicationID);
    }

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    PreparedStatement deleteClientPrepStmt = null;

    try {
        deleteClientPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.REMOVE_CLIENT_FROM_APPMGT_CLIENT);
        // APP_ID = ? AND TENANT_ID = ?
        deleteClientPrepStmt.setInt(1, applicationID);
        deleteClientPrepStmt.setInt(2, tenantID);
        deleteClientPrepStmt.execute();
    } finally {
        IdentityApplicationManagementUtil.closeStatement(deleteClientPrepStmt);
    }
}
 
Example #12
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Add Service provider properties
 *
 * @param dbConnection
 * @param spId
 * @param properties
 * @throws SQLException
 */
private void addServiceProviderProperties(Connection dbConnection, int spId,
        List<ServiceProviderProperty> properties, int tenantId)
        throws SQLException {
    String sqlStmt = ApplicationMgtDBQueries.ADD_SP_METADATA;
    PreparedStatement prepStmt = null;
    try {
        prepStmt = dbConnection.prepareStatement(sqlStmt);

        for (ServiceProviderProperty property : properties) {
            prepStmt.setInt(1, spId);
            prepStmt.setString(2, property.getName());
            prepStmt.setString(3, property.getValue());
            prepStmt.setString(4, property.getDisplayName());
            prepStmt.setInt(5, tenantId);
            prepStmt.addBatch();
        }
        prepStmt.executeBatch();

    } finally {
        IdentityApplicationManagementUtil.closeStatement(prepStmt);
    }
}
 
Example #13
Source File: FileBasedConfigurationBuilder.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private void readTenantDataListenerURLs(OMElement documentElement) {
    OMElement tenantDataURLsElem =
            documentElement.getFirstChildWithName(IdentityApplicationManagementUtil.
                    getQNameWithIdentityApplicationNS(
                            FrameworkConstants.Config.QNAME_TENANT_DATA_LISTENER_URLS));

    if (tenantDataURLsElem != null) {
        for (Iterator tenantDataURLElems = tenantDataURLsElem.getChildrenWithLocalName(
                FrameworkConstants.Config.ELEM_TENANT_DATA_LISTENER_URL);
             tenantDataURLElems.hasNext(); ) {

            OMElement tenantDataListenerURLElem = (OMElement) tenantDataURLElems.next();
            if (tenantDataListenerURLElem != null &&
                    StringUtils.isNotEmpty(tenantDataListenerURLElem.getText())) {
                tenantDataEndpointURLs.add(IdentityUtil.fillURLPlaceholders(tenantDataListenerURLElem.getText()));
            }
        }
    }
}
 
Example #14
Source File: ProvisioningManagementDAO.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param dbConnection
 * @param idPId
 * @param connectorType
 * @return
 * @throws SQLException
 * @throws IdentityApplicationManagementException
 */
private int getProvisioningConfigurationIdentifier(Connection dbConnection, int idPId,
                                                   String connectorType) throws SQLException,
        IdentityApplicationManagementException {

    String sqlStmt = null;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    try {
        sqlStmt = IdentityProvisioningConstants.SQLQueries.GET_IDP_PROVISIONING_CONFIG_ID_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, idPId);
        prepStmt.setString(2, connectorType);
        rs = prepStmt.executeQuery();
        if (rs.next()) {
            return rs.getInt(1);
        } else {
            throw new IdentityApplicationManagementException("Invalid connector type " +
                    connectorType);
        }
    } finally {
        IdentityApplicationManagementUtil.closeResultSet(rs);
        IdentityApplicationManagementUtil.closeStatement(prepStmt);
    }
}
 
Example #15
Source File: CellerySignedJWTValidator.java    From cellery-security with Apache License 2.0 6 votes vote down vote up
private IdentityProvider getLocalIdpForIssuer(String jwtIssuer,
                                              String tenantDomain) throws IdentityOAuth2Exception {

    String residentIdpIssuer = null;
    IdentityProvider residentIdentityProvider;
    try {
        residentIdentityProvider = IdentityProviderManager.getInstance().getResidentIdP(tenantDomain);
    } catch (IdentityProviderManagementException e) {
        throw new IdentityOAuth2Exception("Error retrieving resident IDP information for issuer: " + jwtIssuer +
                " of tenantDomain: " + tenantDomain, e);
    }

    FederatedAuthenticatorConfig[] fedAuthnConfigs = residentIdentityProvider.getFederatedAuthenticatorConfigs();
    FederatedAuthenticatorConfig oauthAuthenticatorConfig =
            IdentityApplicationManagementUtil.getFederatedAuthenticator(fedAuthnConfigs,
                    IdentityApplicationConstants.Authenticator.OIDC.NAME);
    if (oauthAuthenticatorConfig != null) {
        residentIdpIssuer = IdentityApplicationManagementUtil.getProperty(oauthAuthenticatorConfig.getProperties(),
                Utils.OPENID_IDP_ENTITY_ID).getValue();
    }
    return StringUtils.equalsIgnoreCase(residentIdpIssuer, jwtIssuer) ? residentIdentityProvider : null;
}
 
Example #16
Source File: ProvisioningManagementDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @param dbConnection
 * @param idPName
 * @param tenantId
 * @return
 * @throws SQLException
 * @throws IdentityApplicationManagementException
 */
private int getIdentityProviderIdentifier(Connection dbConnection, String idPName, int tenantId)
        throws SQLException,
        IdentityApplicationManagementException {

    String sqlStmt;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    try {
        sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_ID_BY_NAME_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setString(2, idPName);
        rs = prepStmt.executeQuery();
        if (rs.next()) {
            return rs.getInt(1);
        } else {
            throw new IdentityApplicationManagementException("Invalid Identity Provider Name " +
                    idPName);
        }
    } finally {
        IdentityApplicationManagementUtil.closeResultSet(rs);
        IdentityApplicationManagementUtil.closeStatement(prepStmt);
    }
}
 
Example #17
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param applicationID
 * @param connection
 * @throws IdentityApplicationManagementException
 */
public void deletePermissionAndRoleConfiguration(int applicationID, Connection connection)
        throws SQLException {

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    if (log.isDebugEnabled()) {
        log.debug("Deleting Role Mapping of Application " + applicationID);
    }

    PreparedStatement deleteRoleMappingPrepStmt = null;
    try {
        deleteRoleMappingPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.REMOVE_ROLE_MAPPINGS_FROM_APPMGT_ROLE_MAPPING);
        deleteRoleMappingPrepStmt.setInt(1, applicationID);
        deleteRoleMappingPrepStmt.setInt(2, tenantID);
        deleteRoleMappingPrepStmt.execute();
    } finally {
        IdentityApplicationManagementUtil.closeStatement(deleteRoleMappingPrepStmt);
    }
}
 
Example #18
Source File: RandomPasswordProcessor.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Remove original passwords with random passwords when sending password properties to UI front-end
 *
 * @param properties
 */
public Property[] removeOriginalPasswords(Property[] properties) {

    if (ArrayUtils.isEmpty(properties)) {
        return new Property[0];
    }

    properties = addUniqueIdProperty(properties);
    String uuid = IdentityApplicationManagementUtil
            .getPropertyValue(properties, IdentityApplicationConstants.UNIQUE_ID_CONSTANT);
    String randomPhrase = IdentityApplicationConstants.RANDOM_PHRASE_PREFIX + uuid;
    RandomPassword[] randomPasswords = replaceOriginalPasswordsWithRandomPasswords(
            randomPhrase, properties);
    if (!ArrayUtils.isEmpty(randomPasswords)) {
        addPasswordContainerToCache(randomPasswords, uuid);
    }

    return properties;
}
 
Example #19
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param applicationId
 * @param connection
 * @throws SQLException
 */
private void deleteLocalAndOutboundAuthenticationConfiguration(int applicationId,
                                                               Connection connection) throws SQLException {

    if (log.isDebugEnabled()) {
        log.debug("Deleting Steps of Application " + applicationId);
    }

    PreparedStatement deleteLocalAndOutboundAuthConfigPrepStmt = null;
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    try {
        deleteLocalAndOutboundAuthConfigPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.REMOVE_STEP_FROM_APPMGT_STEP);
        deleteLocalAndOutboundAuthConfigPrepStmt.setInt(1, applicationId);
        deleteLocalAndOutboundAuthConfigPrepStmt.setInt(2, tenantId);
        deleteLocalAndOutboundAuthConfigPrepStmt.execute();

    } finally {
        IdentityApplicationManagementUtil
                .closeStatement(deleteLocalAndOutboundAuthConfigPrepStmt);
    }
}
 
Example #20
Source File: SCIMUserManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private ServiceProvider getServiceProvider(boolean isBulkUserAdd) throws CharonException {

        ThreadLocalProvisioningServiceProvider threadLocalSP = IdentityApplicationManagementUtil
                .getThreadLocalProvisioningServiceProvider();
        //isBulkUserAdd is true indicates bulk user add
        if (isBulkUserAdd) {
            threadLocalSP.setBulkUserAdd(true);
        }
        try {
            if (threadLocalSP.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
                return ApplicationManagementService.getInstance().getServiceProviderByClientId(
                                                           threadLocalSP.getServiceProviderName(),
                                                           "oauth2", threadLocalSP.getTenantDomain());
            } else {
                return ApplicationManagementService.getInstance().getServiceProvider(
                        threadLocalSP.getServiceProviderName(), threadLocalSP.getTenantDomain());
            }
        } catch (IdentityApplicationManagementException e) {
            throw new CharonException("Error retrieving Service Provider. ", e);
        }
    }
 
Example #21
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 #22
Source File: FileBasedConfigurationBuilder.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private void readAuthenticationEndpointURL(OMElement documentElement) {
    OMElement authEndpointURLElem = documentElement.getFirstChildWithName(IdentityApplicationManagementUtil.
            getQNameWithIdentityApplicationNS(FrameworkConstants.Config.QNAME_AUTHENTICATION_ENDPOINT_URL));

    if (authEndpointURLElem != null) {
        authenticationEndpointURL = IdentityUtil.fillURLPlaceholders(authEndpointURLElem.getText());
    }
}
 
Example #23
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param applicationID
 * @return
 * @throws IdentityApplicationManagementException
 */
@Override
public String getApplicationName(int applicationID)
        throws IdentityApplicationManagementException {
    Connection connection = IdentityDatabaseUtil.getDBConnection();
    try {
        return getApplicationName(applicationID, connection);
    } catch (SQLException e) {
        throw new IdentityApplicationManagementException("Failed loading the application with "
                + applicationID, e);
    } finally {
        IdentityApplicationManagementUtil.closeConnection(connection);
    }
}
 
Example #24
Source File: ProvisioningManagementDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param conn
 * @param tenantId
 * @param idPName
 * @throws SQLException
 */
private void deleteIdP(Connection conn, int tenantId, String idPName) throws SQLException {

    PreparedStatement prepStmt = null;
    String sqlStmt = IdPManagementConstants.SQLQueries.DELETE_IDP_SQL;

    try {
        prepStmt = conn.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setString(2, idPName);
        prepStmt.executeUpdate();
    } finally {
        IdentityApplicationManagementUtil.closeStatement(prepStmt);
    }
}
 
Example #25
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the application ID for a given application name
 *
 * @param applicationName
 * @param tenantID
 * @param connection
 * @return
 * @throws IdentityApplicationManagementException
 */
private int getApplicationIDByName(String applicationName, int tenantID, Connection connection)
        throws IdentityApplicationManagementException {

    int applicationId = 0;
    PreparedStatement getAppIDPrepStmt = null;
    ResultSet appidResult = null;

    try {
        getAppIDPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.LOAD_APP_ID_BY_APP_NAME);
        getAppIDPrepStmt.setString(1, applicationName);
        getAppIDPrepStmt.setInt(2, tenantID);
        appidResult = getAppIDPrepStmt.executeQuery();

        if (!connection.getAutoCommit()) {
            connection.commit();
        }

        if (appidResult.next()) {
            applicationId = appidResult.getInt(1);
        }

    } catch (SQLException e) {
        IdentityApplicationManagementUtil.closeConnection(connection);
        log.error("Error in storing the application", e);
        throw new IdentityApplicationManagementException("Error while storing application", e);
    } finally {
        IdentityApplicationManagementUtil.closeResultSet(appidResult);
        IdentityApplicationManagementUtil.closeStatement(getAppIDPrepStmt);
    }

    return applicationId;
}
 
Example #26
Source File: UserAccountAssociationDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve association key of a user
 *
 * @param domainName  User store domain of user
 * @param tenantId  Tenant ID of user
 * @param userName  User name
 * @return
 * @throws UserAccountAssociationException
 */
public String getAssociationKeyOfUser(String domainName, int tenantId,
                                      String userName) throws UserAccountAssociationException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    String associationKey = null;

    try {
        preparedStatement = dbConnection.prepareStatement(UserAccountAssociationConstants
                .SQLQueries.GET_ASSOCIATION_KEY_OF_USER);

        preparedStatement.setInt(1, tenantId);
        preparedStatement.setString(2, domainName);
        preparedStatement.setString(3, userName);
        resultSet = preparedStatement.executeQuery();

        if (resultSet.next()) {
            associationKey = resultSet.getString(1);
        }
        dbConnection.commit();
    } catch (SQLException e) {
        throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages
                .ERROR_WHILE_RETRIEVING_ASSOC_KEY.getDescription
                        (), e);
    } finally {
        IdentityApplicationManagementUtil.closeResultSet(resultSet);
        IdentityApplicationManagementUtil.closeStatement(preparedStatement);
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
    return associationKey;
}
 
Example #27
Source File: UserAccountAssociationDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Check if logged user can be associated with a given user
 *
 * @param domainName  User store domain of user
 * @param tenantId  Tenant ID of user
 * @param userName  User name
 * @return
 * @throws UserAccountAssociationException
 */
public boolean isValidUserAssociation(String domainName, int tenantId,
                                      String userName) throws UserAccountAssociationException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    boolean valid = false;

    try {
        preparedStatement = dbConnection.prepareStatement(UserAccountAssociationConstants
                .SQLQueries.IS_VALID_ASSOCIATION);

        preparedStatement.setInt(1, tenantId);
        preparedStatement.setString(2, domainName);
        preparedStatement.setString(3, userName);
        preparedStatement.setInt(4, CarbonContext.getThreadLocalCarbonContext().getTenantId());
        preparedStatement.setString(5, IdentityUtil.extractDomainFromName(CarbonContext
                .getThreadLocalCarbonContext()
                .getUsername()));
        preparedStatement.setString(6, UserAccountAssociationUtil.getUsernameWithoutDomain(CarbonContext
                .getThreadLocalCarbonContext().getUsername()));
        resultSet = preparedStatement.executeQuery();

        if (resultSet.next()) {
            valid = resultSet.getInt(1) > 0;
        }
        dbConnection.commit();
    } catch (SQLException e) {
        throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages
                .CHECK_ASSOCIATION_DB_ERROR.getDescription(), e);
    } finally {
        IdentityApplicationManagementUtil.closeResultSet(resultSet);
        IdentityApplicationManagementUtil.closeStatement(preparedStatement);
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }

    return valid;
}
 
Example #28
Source File: UserAccountAssociationDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Delete account association
 *
 * @param domainName  User store domain of user
 * @param tenantId  Tenant ID of user
 * @param userName  User name
 * @throws UserAccountAssociationException
 */
public void deleteUserAssociation(String domainName, int tenantId,
                                  String userName) throws UserAccountAssociationException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement preparedStatement = null;

    try {
        preparedStatement = dbConnection.prepareStatement(UserAccountAssociationConstants
                .SQLQueries.DELETE_CONNECTION);

        preparedStatement.setInt(1, tenantId);
        preparedStatement.setString(2, domainName);
        preparedStatement.setString(3, userName);
        preparedStatement.executeUpdate();

        if (!dbConnection.getAutoCommit()) {
            dbConnection.commit();
        }
    } catch (SQLException e) {
        throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages
                .CONN_DELETE_DB_ERROR.getDescription(), e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(preparedStatement);
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
}
 
Example #29
Source File: FileBasedIdPMgtDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param property
 * @param value
 * @param tenantDomain
 * @return
 */
public IdentityProvider getIdPByAuthenticatorPropertyValue(String property, String value, String tenantDomain) {

    Map<String, IdentityProvider> identityProviders = IdPManagementServiceComponent.getFileBasedIdPs();
    for (Iterator<Entry<String, IdentityProvider>> iterator = identityProviders.entrySet().iterator(); iterator
            .hasNext(); ) {
        Entry<String, IdentityProvider> entry = iterator.next();
        FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = entry.getValue().
                getFederatedAuthenticatorConfigs();
        // Get SAML2 Web SSO authenticator
        FederatedAuthenticatorConfig samlAuthenticatorConfig = IdentityApplicationManagementUtil.
                getFederatedAuthenticator(
                        federatedAuthenticatorConfigs, IdentityApplicationConstants.Authenticator.SAML2SSO.NAME);

        if (samlAuthenticatorConfig != null) {
            Property samlProperty = IdentityApplicationManagementUtil.getProperty(samlAuthenticatorConfig.
                            getProperties(),
                    property);
            if (samlProperty != null) {
                if (value.equalsIgnoreCase(samlProperty.getValue())) {
                    return entry.getValue();
                }
            }
        }
    }
    return null;
}
 
Example #30
Source File: IdPManagementUIUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * get extracted certificate values from decodedCertificate
 *
 * @param decodedCertificate decoded series of certificate value.
 * @return list of decoded certificate values.
 */
private static List<String> getExtractedCertificateValues(String decodedCertificate) {

    int numOfCertificates = StringUtils.countMatches(decodedCertificate, IdentityUtil.PEM_BEGIN_CERTFICATE);
    List<String> extractedCertificateValues = new ArrayList<>();
    for (int i = 1; i <= numOfCertificates; i++) {
        extractedCertificateValues.add(IdentityApplicationManagementUtil.extractCertificate
                (decodedCertificate, i));
    }
    return extractedCertificateValues;
}