Search in sources :

Example 6 with UserExportException

use of org.wso2.carbon.identity.user.export.core.UserExportException in project identity-governance by wso2-extensions.

the class ConsentInformationProvider method getRetainedUserInformation.

@Override
public UserInformationDTO getRetainedUserInformation(String username, String userStoreDomain, int tenantId) throws UserExportException {
    try {
        List<ConsentReceiptDTO> receipts = new ArrayList<>();
        int limit = 100;
        int offset = 0;
        String tenantDomain = realmService.getTenantManager().getDomain(tenantId);
        List<ReceiptListResponse> receiptListResponses;
        do {
            receiptListResponses = consentManager.searchReceipts(limit, offset, UserCoreUtil.addDomainToName(username, userStoreDomain), tenantDomain, null, ConsentConstants.ACTIVE_STATE);
            for (ReceiptListResponse receiptListResponse : receiptListResponses) {
                String receiptId = receiptListResponse.getConsentReceiptId();
                Receipt receipt = consentManager.getReceipt(receiptId);
                receipts.add(Utils.getConsentReceiptDTO(receipt));
            }
            offset += limit;
        } while (receiptListResponses != null && receiptListResponses.size() != 0);
        if (receipts.size() > 0) {
            return new UserInformationDTO(receipts);
        }
    } catch (UserStoreException e) {
        throw new UserExportException("Error while retrieving tenant domain from tenant id: " + tenantId, e);
    } catch (ConsentManagementException e) {
        throw new UserExportException("Error while retrieving consent receipts for user: " + UserCoreUtil.addDomainToName(username, userStoreDomain) + " in tenant id: " + tenantId, e);
    }
    return new UserInformationDTO();
}
Also used : ConsentReceiptDTO(org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO) Receipt(org.wso2.carbon.consent.mgt.core.model.Receipt) ReceiptListResponse(org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserExportException(org.wso2.carbon.identity.user.export.core.UserExportException) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)

Example 7 with UserExportException

use of org.wso2.carbon.identity.user.export.core.UserExportException in project identity-governance by wso2-extensions.

the class PiInfoApiServiceImpl method getUserById.

@Override
public Response getUserById(String userId) {
    String usernameFromRequest = new String(Base64.getUrlDecoder().decode(userId.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
    String userStoreDomain = UserCoreUtil.extractDomainFromName(usernameFromRequest);
    String username = UserCoreUtil.removeDomainFromName(usernameFromRequest);
    String tenantDomain = MultitenantUtils.getTenantDomain(username);
    username = MultitenantUtils.getTenantAwareUsername(usernameFromRequest);
    int tenantId;
    try {
        tenantId = Utils.getRealmService().getTenantManager().getTenantId(tenantDomain);
    } catch (UserStoreException e) {
        ErrorDTO errorDTO = new ErrorDTO();
        errorDTO.setRef(Utils.getCorrelation());
        errorDTO.setMessage("Invalid tenant domain provided in username.");
        return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
    } catch (UserExportException e) {
        ErrorDTO errorDTO = new ErrorDTO();
        errorDTO.setRef(Utils.getCorrelation());
        errorDTO.setMessage(e.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
    }
    Map userAttributes = null;
    try {
        userAttributes = Utils.getUserInformationService().getRetainedUserInformation(username, userStoreDomain, tenantId);
    } catch (UserExportException e) {
        Utils.handleNotFound(e.getMessage(), String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
    }
    return Response.ok().status(Response.Status.OK).entity(userAttributes).build();
}
Also used : ErrorDTO(org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserExportException(org.wso2.carbon.identity.user.export.core.UserExportException) Map(java.util.Map)

Example 8 with UserExportException

use of org.wso2.carbon.identity.user.export.core.UserExportException in project identity-governance by wso2-extensions.

the class MockUserInformationService method getRetainedUserInformation.

@Override
public Map<String, Object> getRetainedUserInformation(String username, String userStoreDomain, int tenantId) throws UserExportException {
    Map<String, String> attributes = new HashMap<>();
    attributes.put("http://wso2.org/claims/username", "username1");
    attributes.put("http://wso2.org/claims/givenname", "lastname1");
    attributes.put("http://wso2.org/claims/lastname", "lastname1");
    UserInformationDTO basicUserInformationDTO = new UserInformationDTO(attributes);
    Map<String, Object> info = new HashMap<>();
    info.put("basic", basicUserInformationDTO.getData());
    return info;
}
Also used : HashMap(java.util.HashMap) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)

Aggregations

UserExportException (org.wso2.carbon.identity.user.export.core.UserExportException)6 UserInformationDTO (org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)5 UserStoreException (org.wso2.carbon.user.api.UserStoreException)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ErrorDTO (org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO)2 Claim (org.wso2.carbon.user.api.Claim)2 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)2 ArrayList (java.util.ArrayList)1 ConsentManagementException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException)1 Receipt (org.wso2.carbon.consent.mgt.core.model.Receipt)1 ReceiptListResponse (org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse)1 ConsentReceiptDTO (org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO)1 SecurityInformationDTO (org.wso2.carbon.identity.user.export.core.dto.SecurityInformationDTO)1 UserInformationProvider (org.wso2.carbon.identity.user.export.core.service.UserInformationProvider)1