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]);
}
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);
}
}
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;
}
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);
}
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);
}
}
Aggregations