Search in sources :

Example 1 with UnityFailureException

use of io.imunity.furms.spi.exceptions.UnityFailureException in project furms by unity-idm.

the class UnityUsersDAO method getUserStatus.

@Override
public UserStatus getUserStatus(FenixUserId fenixUserId) {
    String uri = UriComponentsBuilder.newInstance().path(ENTITY_BASE).path(fenixUserId.id).toUriString();
    try {
        ObjectNode response = unityClient.get(uri, ObjectNode.class, Map.of("identityType", "identifier"));
        String statusStr = response.get("entityInformation").get("state").asText();
        EntityState unityState = EntityState.valueOf(statusStr);
        return unityState == EntityState.valid ? UserStatus.ENABLED : UserStatus.DISABLED;
    } catch (WebClientResponseException e) {
        throw new UnityFailureException(e.getMessage(), e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WebClientResponseException(org.springframework.web.reactive.function.client.WebClientResponseException) UnityFailureException(io.imunity.furms.spi.exceptions.UnityFailureException) EntityState(pl.edu.icm.unity.types.basic.EntityState)

Example 2 with UnityFailureException

use of io.imunity.furms.spi.exceptions.UnityFailureException in project furms by unity-idm.

the class UnitySiteGroupDAO method update.

@Override
public void update(Site site) {
    assertTrue(site != null && !isEmpty(site.getId()), () -> new IllegalArgumentException("Could not update Site in Unity. Missing Site or Site ID."));
    Map<String, Object> uriVariables = uriVariables(site);
    String metaSitePath = UriComponentsBuilder.newInstance().path(GROUP_BASE).pathSegment(SITE_PATTERN).path(META).uriVariables(uriVariables).buildAndExpand().encode().toUriString();
    try {
        Group group = unityClient.get(metaSitePath, Group.class);
        group.setDisplayedName(new I18nString(site.getName()));
        unityClient.put(GROUP_BASE, group);
    } catch (WebClientResponseException e) {
        throw new UnityFailureException(e.getMessage(), e);
    }
}
Also used : Group(pl.edu.icm.unity.types.basic.Group) WebClientResponseException(org.springframework.web.reactive.function.client.WebClientResponseException) UnityFailureException(io.imunity.furms.spi.exceptions.UnityFailureException) I18nString(pl.edu.icm.unity.types.I18nString) I18nString(pl.edu.icm.unity.types.I18nString)

Example 3 with UnityFailureException

use of io.imunity.furms.spi.exceptions.UnityFailureException in project furms by unity-idm.

the class UnitySiteGroupDAO method create.

@Override
public void create(Site site) {
    assertTrue(site != null && !isEmpty(site.getId()), () -> new IllegalArgumentException("Could not create Site in Unity. Missing Site or Site ID"));
    Map<String, Object> uriVariables = uriVariables(site);
    String groupPath = UriComponentsBuilder.newInstance().path(SITE_PATTERN).uriVariables(uriVariables).toUriString();
    Group group = new Group(groupPath);
    group.setDisplayedName(new I18nString(site.getName()));
    try {
        unityClient.post(GROUP_BASE, group);
    } catch (WebClientResponseException e) {
        throw new UnityFailureException(e.getMessage(), e);
    }
    try {
        String createSiteUsersPath = UriComponentsBuilder.newInstance().path(GROUP_BASE).pathSegment(groupPath + USERS_PATTERN).toUriString();
        unityClient.post(createSiteUsersPath);
    } catch (WebClientResponseException e) {
        throw new UnityFailureException(e.getMessage(), e);
    }
}
Also used : Group(pl.edu.icm.unity.types.basic.Group) WebClientResponseException(org.springframework.web.reactive.function.client.WebClientResponseException) UnityFailureException(io.imunity.furms.spi.exceptions.UnityFailureException) I18nString(pl.edu.icm.unity.types.I18nString) I18nString(pl.edu.icm.unity.types.I18nString)

Example 4 with UnityFailureException

use of io.imunity.furms.spi.exceptions.UnityFailureException in project furms by unity-idm.

the class UserServiceImpl method setUserStatus.

@Override
@FurmsAuthorize(capability = USERS_MAINTENANCE)
public void setUserStatus(FenixUserId fenixUserId, UserStatus status) {
    checkNotNull(status);
    checkNotNull(fenixUserId);
    LOG.info("Setting {} status to {}", fenixUserId, status);
    try {
        usersDAO.setUserStatus(fenixUserId, status);
        userAllocationsService.findAllByFenixUserId(fenixUserId).forEach(userAddition -> userAccountStatusUpdater.setStatus(new SiteAgentSetUserAccountStatusRequest(userAddition, status, SECURITY_INCIDENT)));
    } catch (UnityFailureException e) {
        LOG.info("Failed to resolve user", e);
        throw new UnknownUserException(fenixUserId);
    }
}
Also used : SiteAgentSetUserAccountStatusRequest(io.imunity.furms.domain.users.SiteAgentSetUserAccountStatusRequest) UnityFailureException(io.imunity.furms.spi.exceptions.UnityFailureException) UnknownUserException(io.imunity.furms.domain.users.UnknownUserException) FurmsAuthorize(io.imunity.furms.core.config.security.method.FurmsAuthorize)

Example 5 with UnityFailureException

use of io.imunity.furms.spi.exceptions.UnityFailureException in project furms by unity-idm.

the class UnityUsersDAO method setUserStatus.

@Override
public void setUserStatus(FenixUserId fenixUserId, UserStatus status) {
    EntityState unityStatus = status == UserStatus.ENABLED ? EntityState.valid : EntityState.disabled;
    String uri = UriComponentsBuilder.newInstance().path(ENTITY_BASE).path(fenixUserId.id).path("/status/").path(unityStatus.name()).toUriString();
    try {
        unityClient.put(uri, null, Map.of("identityType", "identifier"));
    } catch (WebClientResponseException e) {
        throw new UnityFailureException(e.getMessage(), e);
    }
}
Also used : WebClientResponseException(org.springframework.web.reactive.function.client.WebClientResponseException) UnityFailureException(io.imunity.furms.spi.exceptions.UnityFailureException) EntityState(pl.edu.icm.unity.types.basic.EntityState)

Aggregations

UnityFailureException (io.imunity.furms.spi.exceptions.UnityFailureException)7 WebClientResponseException (org.springframework.web.reactive.function.client.WebClientResponseException)6 I18nString (pl.edu.icm.unity.types.I18nString)4 Group (pl.edu.icm.unity.types.basic.Group)3 EntityState (pl.edu.icm.unity.types.basic.EntityState)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 FurmsAuthorize (io.imunity.furms.core.config.security.method.FurmsAuthorize)1 SiteAgentSetUserAccountStatusRequest (io.imunity.furms.domain.users.SiteAgentSetUserAccountStatusRequest)1 UnknownUserException (io.imunity.furms.domain.users.UnknownUserException)1