Package org.rest.sec.model

Examples of org.rest.sec.model.Role


    }

    @Test
    public final void whenResourceIsCreatedWithExistingAssociation_thenAssociationIsLinkedToTheResource() {
        final Privilege existingAssociation = getAssociationAPI().create(getAssociationEntityOps().createNewEntity());
        final Role resourceToCreate = getEntityOps().createNewEntity();

        // When
        resourceToCreate.getPrivileges().add(existingAssociation);
        final Role existingResource = getApi().create(resourceToCreate);

        // Then
        assertThat(existingResource.getPrivileges(), hasItem(existingAssociation));
    }
View Full Code Here


    // update

    @Test
    public final void givenResourceExists_whenResourceIsUpdatedWithExistingAssociation_thenAssociationIsCorrectlyUpdated() {
        // Given
        final Role existingResource = getApi().create(getEntityOps().createNewEntity());
        final Privilege existingAssociation = getAssociationAPI().create(getAssociationEntityOps().createNewEntity());
        existingResource.setPrivileges(Sets.newHashSet(existingAssociation));

        // When
        getApi().update(existingResource);

        // Given
        final Role updatedResource = getApi().findOne(existingResource.getId());
        assertThat(updatedResource.getPrivileges(), hasItem(existingAssociation));
    }
View Full Code Here

        assertThat(updatedResource.getPrivileges(), hasItem(existingAssociation));
    }

    @Test
    public final void givenExistingResourceAndExistingAssociation_whenUpdatingResourceWithTheAssociation_thanAssociationCorrectlyDone() {
        final Role existingResource = getApi().create(getEntityOps().createNewEntity());
        final Privilege existingAssociation = getAssociationAPI().create(getAssociationEntityOps().createNewEntity());
        existingResource.setPrivileges(Sets.newHashSet(existingAssociation));

        getApi().update(existingResource);
        final Role updatedResource = getApi().findOne(existingResource.getId());
        assertThat(updatedResource.getPrivileges(), hasItem(existingAssociation));
    }
View Full Code Here

    @Test
    @Ignore("TODO: fix")
    public final void givenResourceWithAssociationsExists_thenResourceCanBeDeleted() {
        // Given
        final Privilege existingAssociation = getAssociationAPI().create(getAssociationEntityOps().createNewEntity());
        final Role newResource = getEntityOps().createNewEntity();
        newResource.getPrivileges().add(existingAssociation);
        final Role existingResource = getApi().create(newResource);

        // When
        getApi().delete(existingResource.getId());

        // Then
        assertNull(getApi().findOne(existingAssociation.getId()));
    }
View Full Code Here

    // complex scenarios

    @Test
    public final void whenScenarioOfWorkingWithAssociations_thenTheChangesAreCorrectlyPersisted() {
        final Privilege existingAssociation = getAssociationAPI().create(getAssociationEntityOps().createNewEntity());
        final Role resource1 = new Role(randomAlphabetic(6), Sets.newHashSet(existingAssociation));

        final Role resource1ViewOfServerBefore = getApi().create(resource1);
        assertThat(resource1ViewOfServerBefore.getPrivileges(), hasItem(existingAssociation));

        final Role resource2 = new Role(randomAlphabetic(6), Sets.newHashSet(existingAssociation));
        getApi().create(resource2);

        final Role resource1ViewOfServerAfter = getApi().findOne(resource1ViewOfServerBefore.getId());
        assertThat(resource1ViewOfServerAfter.getPrivileges(), hasItem(existingAssociation));
    }
View Full Code Here

        createRoleIfNotExisting(Roles.ROLE_ADMIN, Sets.<Privilege> newHashSet(canUserRead, canUserWrite, canRoleRead, canRoleWrite, canPrivilegeRead, canPrivilegeWrite));
    }

    final void createRoleIfNotExisting(final String name, final Set<Privilege> privileges) {
        final Role entityByName = roleService.findByName(name);
        if (entityByName == null) {
            final Role entity = new Role(name);
            entity.setPrivileges(privileges);
            roleService.create(entity);
        }
    }
View Full Code Here

    }

    // Principal/User

    final void createPrincipals() {
        final Role roleAdmin = roleService.findByName(Roles.ROLE_ADMIN);

        // createPrincipalIfNotExisting(SecurityConstants.ADMIN_USERNAME, SecurityConstants.ADMIN_PASS, Sets.<Role> newHashSet(roleAdmin));
        createPrincipalIfNotExisting(SecurityConstants.ADMIN_EMAIL, SecurityConstants.ADMIN_PASS, Sets.<Role> newHashSet(roleAdmin));
    }
View Full Code Here

            public final Privilege apply(final GrantedAuthority springAuthority) {
                return new Privilege(springAuthority.getAuthority());
            }
        };
        final Collection<Privilege> privileges = Collections2.transform(authenticationInSpring.getAuthorities(), springAuthorityToPrivilegeFunction);
        final Role defaultRole = new Role("defaultRole", Sets.<Privilege> newHashSet(privileges));

        final User authenticationResource = new User(authenticationInSpring.getName(), (String) authenticationInSpring.getCredentials(), Sets.<Role> newHashSet(defaultRole));
        return authenticationResource;
    }
View Full Code Here

    }

    @Test
    @Ignore("intermitent failures - temporarily ignored")
    public final void whenResourceIsCreatedWithInvalidAssociation_then409IsReceived() {
        final Role invalidAssociation = getAssociationEntityOps().createNewEntity();
        invalidAssociation.setId(1001l);
        final User newResource = getEntityOps().createNewEntity();
        newResource.getRoles().add(invalidAssociation);

        // When
        final Response response = getApi().createAsResponse(newResource);
View Full Code Here

        assertThat(response.getStatusCode(), is(409));
    }

    @Test
    public final void whenUserIsCreatedWithExistingRole_then201IsReceived() {
        final Role existingAssociation = getAssociationAPI().create(getAssociationEntityOps().createNewEntity());
        final User newResource = getEntityOps().createNewEntity();
        newResource.getRoles().add(existingAssociation);

        // When
        final Response response = getApi().createAsResponse(newResource);
View Full Code Here

TOP

Related Classes of org.rest.sec.model.Role

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.