Search in sources :

Example 1 with UnauthorizedException

use of org.jboss.errai.security.shared.exception.UnauthorizedException in project kie-wb-common by kiegroup.

the class LibraryServiceImpl method createDefaultOrganizationalUnit.

private OrganizationalUnit createDefaultOrganizationalUnit() {
    if (!authorizationManager.authorize(OrganizationalUnit.RESOURCE_TYPE, OrganizationalUnitAction.CREATE, sessionInfo.getIdentity())) {
        throw new UnauthorizedException("User :user has no permissions to :type -> :action".replace(":user", sessionInfo.getIdentity().getIdentifier()).replace(":type", OrganizationalUnit.RESOURCE_TYPE.getName()).replace(":action", OrganizationalUnitAction.CREATE.getName()));
    }
    final LibraryPreferences preferences = getPreferences();
    final List<Contributor> contributors = new ArrayList<>();
    contributors.add(new Contributor(preferences.getOrganizationalUnitPreferences().getOwner(), ContributorType.OWNER));
    return ouService.createOrganizationalUnit(preferences.getOrganizationalUnitPreferences().getName(), preferences.getOrganizationalUnitPreferences().getGroupId(), Collections.emptyList(), contributors);
}
Also used : UnauthorizedException(org.jboss.errai.security.shared.exception.UnauthorizedException) LibraryPreferences(org.kie.workbench.common.screens.library.api.preferences.LibraryPreferences) ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor)

Example 2 with UnauthorizedException

use of org.jboss.errai.security.shared.exception.UnauthorizedException in project kie-wb-common by kiegroup.

the class LibraryPlacesTest method goToLibraryWhenUserIsNotAuthorizedToCreateProjectsTest.

@Test
public void goToLibraryWhenUserIsNotAuthorizedToCreateProjectsTest() {
    doReturn(Optional.ofNullable(null)).when(projectContext).getActiveOrganizationalUnit();
    when(libraryService.getDefaultOrganizationalUnit()).thenThrow(new UnauthorizedException());
    libraryPlaces.goToLibrary();
    verify(libraryPlaces).goToOrganizationalUnits();
}
Also used : UnauthorizedException(org.jboss.errai.security.shared.exception.UnauthorizedException) Test(org.junit.Test)

Aggregations

UnauthorizedException (org.jboss.errai.security.shared.exception.UnauthorizedException)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 LibraryPreferences (org.kie.workbench.common.screens.library.api.preferences.LibraryPreferences)1 Contributor (org.uberfire.security.Contributor)1