Search in sources :

Example 1 with AssociatedAccountDTO

use of org.wso2.carbon.identity.user.profile.mgt.AssociatedAccountDTO in project carbon-identity-framework by wso2.

the class UserProfileAdmin method getAssociatedAccounts.

private AssociatedAccountDTO[] getAssociatedAccounts(User user) throws FederatedAssociationManagerException, UserProfileException {
    FederatedAssociation[] federatedAssociations = getFederatedAssociationManager().getFederatedAssociationsOfUser(user);
    List<AssociatedAccountDTO> associatedAccountDTOS = new ArrayList<>();
    for (FederatedAssociation federatedAssociation : federatedAssociations) {
        String identityProviderName = getIdentityProviderName(getTenantDomain(), federatedAssociation.getIdp().getId());
        associatedAccountDTOS.add(new AssociatedAccountDTO(federatedAssociation.getId(), identityProviderName, federatedAssociation.getFederatedUserId()));
    }
    return associatedAccountDTOS.toArray(new AssociatedAccountDTO[0]);
}
Also used : FederatedAssociation(org.wso2.carbon.identity.user.profile.mgt.association.federation.model.FederatedAssociation) ArrayList(java.util.ArrayList)

Example 2 with AssociatedAccountDTO

use of org.wso2.carbon.identity.user.profile.mgt.AssociatedAccountDTO in project carbon-identity-framework by wso2.

the class UserProfileAdmin method getAssociatedIDs.

/**
 * Return an array of federated identifiers associated with the logged in user.
 *
 * @return an array of AssociatedAccountDTO objects which contains the federated identifier info
 * @throws UserProfileException
 */
public AssociatedAccountDTO[] getAssociatedIDs() throws UserProfileException {
    String tenantAwareUsername = CarbonContext.getThreadLocalCarbonContext().getUsername();
    User user = getUser(tenantAwareUsername);
    try {
        return getAssociatedAccounts(user);
    } catch (FederatedAssociationManagerException e) {
        String msg = "Error while retrieving federated identifiers associated for user: " + tenantAwareUsername + " in tenant: " + getTenantDomain();
        throw new UserProfileException(msg, e);
    }
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) FederatedAssociationManagerException(org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException)

Example 3 with AssociatedAccountDTO

use of org.wso2.carbon.identity.user.profile.mgt.AssociatedAccountDTO in project carbon-identity-framework by wso2.

the class UserProfileMgtDAO method getAssociatedFederatedAccountsForUser.

/**
 * Retun a list of federated identities associated with the given user.
 *
 * @param tenantId           tenant identifier
 * @param userStoreDomain    user store domain name
 * @param domainFreeUsername username without user store domain
 * @return a list of AssociatedAccountDTO objects which includes federated identity info
 * @throws UserProfileException
 */
public List<AssociatedAccountDTO> getAssociatedFederatedAccountsForUser(int tenantId, String userStoreDomain, String domainFreeUsername) throws UserProfileException {
    List<AssociatedAccountDTO> associatedFederatedAccounts = new ArrayList<>();
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
        try (PreparedStatement prepStmt = connection.prepareStatement(Constants.SQLQueries.RETRIEVE_ASSOCIATIONS_FOR_USER)) {
            prepStmt.setInt(1, tenantId);
            prepStmt.setString(2, domainFreeUsername);
            prepStmt.setString(3, userStoreDomain);
            try (ResultSet resultSet = prepStmt.executeQuery()) {
                while (resultSet.next()) {
                    associatedFederatedAccounts.add(new AssociatedAccountDTO(resultSet.getString("ASSOCIATION_ID"), resultSet.getString("NAME"), resultSet.getString("IDP_USER_ID")));
                }
            }
        } catch (SQLException e1) {
            throw new UserProfileException("Error occurred while retrieving federated accounts associated for " + "user: " + domainFreeUsername + " of user store domain: " + userStoreDomain + " in tenant: " + tenantId, e1);
        }
    } catch (SQLException e) {
        throw new UserProfileException("Error occurred while retrieving federated accounts associated for " + "user: " + domainFreeUsername + " of user store domain: " + userStoreDomain + " in tenant: " + tenantId, e);
    }
    return associatedFederatedAccounts;
}
Also used : AssociatedAccountDTO(org.wso2.carbon.identity.user.profile.mgt.AssociatedAccountDTO) SQLException(java.sql.SQLException) UserProfileException(org.wso2.carbon.identity.user.profile.mgt.UserProfileException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 4 with AssociatedAccountDTO

use of org.wso2.carbon.identity.user.profile.mgt.AssociatedAccountDTO in project product-is by wso2.

the class UserProfileAdminTestCase method testUserAccountAssociationAdd.

@Test(priority = 4, groups = "wso2.is", description = "Check Fed User Account Association")
public void testUserAccountAssociationAdd() throws Exception {
    super.init();
    userProfileMgtClient = new UserProfileMgtServiceClient(backendURL, sessionCookie);
    userMgtClient = new UserManagementClient(backendURL, sessionCookie);
    String username = "testUser2";
    String password = "passWord1@";
    String idpName = "idp1";
    // create a user
    userMgtClient.addUser(username, password, new String[] { "admin" }, "default");
    Assert.assertTrue(userMgtClient.getUserList().contains(username));
    idpMgtClient = new IdentityProviderMgtServiceClient(username, password, backendURL);
    userProfileMgtClient = new UserProfileMgtServiceClient(backendURL, username, password);
    IdentityProvider idp = new IdentityProvider();
    idp.setIdentityProviderName(idpName);
    idpMgtClient.addIdP(idp);
    Assert.assertNotNull(idpMgtClient.getIdPByName(idpName));
    // create a federated user account association
    userProfileMgtClient.addFedIdpAccountAssociation(idpName, "dummy_idp_account_1");
    userProfileMgtClient.addFedIdpAccountAssociation(idpName, "dummy_idp_account_2");
    AssociatedAccountDTO[] associatedFedUserAccountIds = userProfileMgtClient.getAssociatedFedUserAccountIds();
    Assert.assertNotNull(associatedFedUserAccountIds);
    Assert.assertEquals(associatedFedUserAccountIds.length, 2);
    // delete the user, this should clear the federated idp account associations
    userMgtClient.deleteUser(username);
    Assert.assertEquals(userMgtClient.getUserList().contains(username), false);
    // create the same user
    userMgtClient.addUser(username, password, new String[] { "admin" }, "default");
    userProfileMgtClient = new UserProfileMgtServiceClient(backendURL, username, password);
    associatedFedUserAccountIds = userProfileMgtClient.getAssociatedFedUserAccountIds();
    // assert to make sure there are no federated idp user account associations for this user
    Assert.assertEquals(associatedFedUserAccountIds == null || associatedFedUserAccountIds.length == 0, true);
}
Also used : UserProfileMgtServiceClient(org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient) AssociatedAccountDTO(org.wso2.carbon.identity.user.profile.stub.types.AssociatedAccountDTO) UserManagementClient(org.wso2.identity.integration.common.clients.UserManagementClient) IdentityProvider(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider) IdentityProviderMgtServiceClient(org.wso2.identity.integration.common.clients.Idp.IdentityProviderMgtServiceClient) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 5 with AssociatedAccountDTO

use of org.wso2.carbon.identity.user.profile.mgt.AssociatedAccountDTO in project carbon-identity-framework by wso2.

the class FederatedAssociationManagerImpl method getFederatedAssociationsOfUser.

@Override
public FederatedAssociation[] getFederatedAssociationsOfUser(User user) throws FederatedAssociationManagerException {
    validateUserObject(user);
    int tenantId = getValidatedTenantId(user);
    validateUserExistence(user, tenantId);
    try {
        List<FederatedAssociation> federatedAssociations = new ArrayList<>();
        List<AssociatedAccountDTO> associatedAccountDTOS = UserProfileMgtDAO.getInstance().getAssociatedFederatedAccountsForUser(tenantId, user.getUserStoreDomain(), user.getUserName());
        for (AssociatedAccountDTO associatedAccount : associatedAccountDTOS) {
            AssociatedIdentityProvider idp = getAssociatedIdentityProvider(user.getTenantDomain(), associatedAccount.getIdentityProviderName());
            federatedAssociations.add(new FederatedAssociation(associatedAccount.getId(), idp, associatedAccount.getUsername()));
        }
        return federatedAssociations.toArray(new FederatedAssociation[0]);
    } catch (UserProfileException e) {
        if (log.isDebugEnabled()) {
            String msg = "Error while retrieving federated account associations of user: " + user.toFullQualifiedUsername();
            log.debug(msg);
        }
        throw handleFederatedAssociationManagerServerException(ERROR_WHILE_RETRIEVING_FEDERATED_ASSOCIATION_OF_USER, e, true);
    }
}
Also used : AssociatedAccountDTO(org.wso2.carbon.identity.user.profile.mgt.AssociatedAccountDTO) FederatedAssociation(org.wso2.carbon.identity.user.profile.mgt.association.federation.model.FederatedAssociation) UserProfileException(org.wso2.carbon.identity.user.profile.mgt.UserProfileException) ArrayList(java.util.ArrayList) AssociatedIdentityProvider(org.wso2.carbon.identity.user.profile.mgt.association.federation.model.AssociatedIdentityProvider)

Aggregations

ArrayList (java.util.ArrayList)3 AssociatedAccountDTO (org.wso2.carbon.identity.user.profile.mgt.AssociatedAccountDTO)2 UserProfileException (org.wso2.carbon.identity.user.profile.mgt.UserProfileException)2 FederatedAssociation (org.wso2.carbon.identity.user.profile.mgt.association.federation.model.FederatedAssociation)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Test (org.testng.annotations.Test)1 User (org.wso2.carbon.identity.application.common.model.User)1 IdentityProvider (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider)1 FederatedAssociationManagerException (org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException)1 AssociatedIdentityProvider (org.wso2.carbon.identity.user.profile.mgt.association.federation.model.AssociatedIdentityProvider)1 AssociatedAccountDTO (org.wso2.carbon.identity.user.profile.stub.types.AssociatedAccountDTO)1 IdentityProviderMgtServiceClient (org.wso2.identity.integration.common.clients.Idp.IdentityProviderMgtServiceClient)1 UserManagementClient (org.wso2.identity.integration.common.clients.UserManagementClient)1 UserProfileMgtServiceClient (org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient)1 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)1