Search in sources :

Example 1 with FederatedAssociationManagerException

use of org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException in project carbon-identity-framework by wso2.

the class UserProfileAdmin method removeAssociateIDForUser.

/**
 * Remove the association with the given federated identifier for the given user.
 *
 * @param username     username of the user to be associated with
 * @param idpID        Identity Provider ID
 * @param associatedID Federated Identity ID
 * @throws UserProfileException
 */
public void removeAssociateIDForUser(String username, String idpID, String associatedID) throws UserProfileException {
    String auditData = getAuditData(username, idpID, associatedID);
    validateFederatedAssociationParameters(username, idpID, associatedID, auditData);
    User user = getUser(username);
    try {
        getFederatedAssociationManager().deleteFederatedAssociation(user, idpID, associatedID);
        audit(auditActionForDeleteAssociation, username, auditData, AUDIT_SUCCESS);
    } catch (FederatedAssociationManagerException e) {
        // order to preserve backward compatibility, this error is silently ignored.
        if (!isFederatedAssociationDoesNotExistsError(e)) {
            audit(auditActionForDeleteAssociation, username, auditData, AUDIT_FAIL);
            String msg = "Error while removing association with federated IdP: " + idpID + " for user: " + username + " 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 2 with FederatedAssociationManagerException

use of org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException in project carbon-identity-framework by wso2.

the class UserProfileAdmin method associateIDForUser.

/**
 * Associate the given user with the given federated identifier.
 *
 * @param username     username of the user to be associated with
 * @param idpID        Identity Provider ID
 * @param associatedID Federated Identity ID
 * @throws UserProfileException
 */
public void associateIDForUser(String username, String idpID, String associatedID) throws UserProfileException {
    User user = getUser(username);
    String auditData = getAuditData(username, idpID, associatedID);
    try {
        getFederatedAssociationManager().createFederatedAssociation(user, idpID, associatedID);
        audit(auditActionForCreateAssociation, username, auditData, AUDIT_SUCCESS);
    } catch (FederatedAssociationManagerException e) {
        audit(auditActionForCreateAssociation, username, auditData, AUDIT_FAIL);
        String msg = "Error while creating association for user: " + username + " with federated IdP: " + idpID + " 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 FederatedAssociationManagerException

use of org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException 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 4 with FederatedAssociationManagerException

use of org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException 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 5 with FederatedAssociationManagerException

use of org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException in project carbon-identity-framework by wso2.

the class UserProfileAdmin method removeAssociateID.

/**
 * Remove the association with the given federated identifier for the logged in user.
 *
 * @param idpID        Identity Provider ID
 * @param associatedID Federated Identity ID
 * @throws UserProfileException
 */
public void removeAssociateID(String idpID, String associatedID) throws UserProfileException {
    String tenantAwareUsername = CarbonContext.getThreadLocalCarbonContext().getUsername();
    User user = getUser(tenantAwareUsername);
    try {
        getFederatedAssociationManager().deleteFederatedAssociation(user, idpID, associatedID);
    } catch (FederatedAssociationManagerException e) {
        String msg = "Error while removing association with federated IdP: " + idpID + " 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)

Aggregations

FederatedAssociationManagerException (org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException)10 User (org.wso2.carbon.identity.application.common.model.User)7 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)5 FederatedAssociationManager (org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager)5 ArrayList (java.util.ArrayList)4 RealmService (org.wso2.carbon.user.core.service.RealmService)4 UserRealm (org.wso2.carbon.user.core.UserRealm)3 PostAuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException)2 FederatedAssociation (org.wso2.carbon.identity.user.profile.mgt.association.federation.model.FederatedAssociation)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 UserStoreException (org.wso2.carbon.user.core.UserStoreException)2 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Mockito.anyString (org.mockito.Mockito.anyString)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 CarbonException (org.wso2.carbon.CarbonException)1 AbstractFrameworkTest (org.wso2.carbon.identity.application.authentication.framework.AbstractFrameworkTest)1 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)1