@Test(expected = AuthorizationException.class) public void testPublicGroupDestinationActivityPostFailureAuthorization() { PostActivityRequest currentRequest = new PostActivityRequest(testActivity); Principal currentPrincipal = new DefaultPrincipal(ACCOUNT_ID, OPENSOCIAL_ID, BAD_ID); ServiceActionContext currentActionContext = new ServiceActionContext(currentRequest, currentPrincipal); final Set<Long> groupCoords = new HashSet<Long>(); groupCoords.add(ID); context.checking(new Expectations() { { allowing(testActivity).getDestinationStream(); will(returnValue(testDestination)); oneOf(testDestination).getType(); will(returnValue(EntityType.GROUP)); allowing(testDestination).getUniqueIdentifier(); oneOf(getDomainGroupsMapperMock).fetchUniqueResult(with(any(String.class))); will(returnValue(testGroup)); oneOf(testGroup).getEntityId(); will(returnValue(DESTINATION_ID)); oneOf(getGroupCoordMapperMock).execute(DESTINATION_ID); will(returnValue(groupCoords)); oneOf(testGroup).isPublic(); will(returnValue(true)); oneOf(testGroup).isStreamPostable(); will(returnValue(false)); } }); sut.authorize(currentActionContext); context.assertIsSatisfied(); }
public void authorize(final ServiceActionContext inActionContext) { Principal currentPrincipal = inActionContext.getPrincipal(); PostActivityRequest currentRequest = (PostActivityRequest) inActionContext.getParams(); switch (currentRequest.getActivityDTO().getDestinationStream().getType()) { case PERSON: if (logger.isTraceEnabled()) { logger.trace("Performing authorization to post to a Person based stream: " + currentRequest.getActivityDTO().getDestinationStream().getUniqueIdentifier()); } performPersonAuthorization(currentPrincipal, currentRequest.getActivityDTO()); break; case GROUP: if (logger.isTraceEnabled()) { logger.trace("Performing authorization to post to a Group based stream: " + currentRequest.getActivityDTO().getDestinationStream().getUniqueIdentifier()); } performGroupAuthorization(currentPrincipal, currentRequest.getActivityDTO()); break; case RESOURCE: break; default: logger.error("Error occurred Performing authorization to post an Activity to stream, unsupported" + "destination stream type."); throw new AuthorizationException("Unsupported Destination Stream Type."); } }
PostActivityAuthorizationStrategy implements AuthorizationStrategy<ServiceActionContext> { public void authorize(final ServiceActionContext inActionContext) { Principal currentPrincipal = inActionContext.getPrincipal(); PostActivityRequest currentRequest = (PostActivityRequest) inActionContext.getParams(); switch (currentRequest.getActivityDTO().getDestinationStream().getType()) { case PERSON: if (logger.isTraceEnabled()) { logger.trace("Performing authorization to post to a Person based stream: " + currentRequest.getActivityDTO().getDestinationStream().getUniqueIdentifier()); } performPersonAuthorization(currentPrincipal, currentRequest.getActivityDTO()); break; case GROUP: if (logger.isTraceEnabled()) { logger.trace("Performing authorization to post to a Group based stream: " + currentRequest.getActivityDTO().getDestinationStream().getUniqueIdentifier()); } performGroupAuthorization(currentPrincipal, currentRequest.getActivityDTO()); break; case RESOURCE: break; default: logger.error("Error occurred Performing authorization to post an Activity to stream, unsupported" + "destination stream type."); throw new AuthorizationException("Unsupported Destination Stream Type."); } } }
PostActivityAuthorizationStrategy implements AuthorizationStrategy<ServiceActionContext> { public void authorize(final ServiceActionContext inActionContext) { Principal currentPrincipal = inActionContext.getPrincipal(); PostActivityRequest currentRequest = (PostActivityRequest) inActionContext.getParams(); switch (currentRequest.getActivityDTO().getDestinationStream().getType()) { case PERSON: if (logger.isTraceEnabled()) { logger.trace("Performing authorization to post to a Person based stream: " + currentRequest.getActivityDTO().getDestinationStream().getUniqueIdentifier()); } performPersonAuthorization(currentPrincipal, currentRequest.getActivityDTO()); break; case GROUP: if (logger.isTraceEnabled()) { logger.trace("Performing authorization to post to a Group based stream: " + currentRequest.getActivityDTO().getDestinationStream().getUniqueIdentifier()); } performGroupAuthorization(currentPrincipal, currentRequest.getActivityDTO()); break; case RESOURCE: break; default: logger.error("Error occurred Performing authorization to post an Activity to stream, unsupported" + "destination stream type."); throw new AuthorizationException("Unsupported Destination Stream Type."); } } PostActivityAuthorizationStrategy(final GetDomainGroupsByShortNames inDomainGroupsByShortNameMapper,
            final GetAllPersonIdsWhoHaveGroupCoordinatorAccess inGroupCoordMapper,
            final DomainMapper<Long, List<Long>> inGroupFollowersDAO,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper); }
PostActivityAuthorizationStrategy implements AuthorizationStrategy<ServiceActionContext> { public void authorize(final ServiceActionContext inActionContext) { Principal currentPrincipal = inActionContext.getPrincipal(); PostActivityRequest currentRequest = (PostActivityRequest) inActionContext.getParams(); switch (currentRequest.getActivityDTO().getDestinationStream().getType()) { case PERSON: if (logger.isTraceEnabled()) { logger.trace("Performing authorization to post to a Person based stream: " + currentRequest.getActivityDTO().getDestinationStream().getUniqueIdentifier()); } performPersonAuthorization(currentPrincipal, currentRequest.getActivityDTO()); break; case GROUP: if (logger.isTraceEnabled()) { logger.trace("Performing authorization to post to a Group based stream: " + currentRequest.getActivityDTO().getDestinationStream().getUniqueIdentifier()); } performGroupAuthorization(currentPrincipal, currentRequest.getActivityDTO()); break; case RESOURCE: break; default: logger.error("Error occurred Performing authorization to post an Activity to stream, unsupported" + "destination stream type."); throw new AuthorizationException("Unsupported Destination Stream Type."); } } PostActivityAuthorizationStrategy(final GetDomainGroupsByShortNames inDomainGroupsByShortNameMapper,
            final GetAllPersonIdsWhoHaveGroupCoordinatorAccess inGroupCoordMapper,
            final DomainMapper<Long, List<Long>> inGroupFollowersDAO,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper); void authorize(final ServiceActionContext inActionContext); }
PostActivityAuthorizationStrategy implements AuthorizationStrategy<ServiceActionContext> { public void authorize(final ServiceActionContext inActionContext) { Principal currentPrincipal = inActionContext.getPrincipal(); PostActivityRequest currentRequest = (PostActivityRequest) inActionContext.getParams(); switch (currentRequest.getActivityDTO().getDestinationStream().getType()) { case PERSON: if (logger.isTraceEnabled()) { logger.trace("Performing authorization to post to a Person based stream: " + currentRequest.getActivityDTO().getDestinationStream().getUniqueIdentifier()); } performPersonAuthorization(currentPrincipal, currentRequest.getActivityDTO()); break; case GROUP: if (logger.isTraceEnabled()) { logger.trace("Performing authorization to post to a Group based stream: " + currentRequest.getActivityDTO().getDestinationStream().getUniqueIdentifier()); } performGroupAuthorization(currentPrincipal, currentRequest.getActivityDTO()); break; case RESOURCE: break; default: logger.error("Error occurred Performing authorization to post an Activity to stream, unsupported" + "destination stream type."); throw new AuthorizationException("Unsupported Destination Stream Type."); } } PostActivityAuthorizationStrategy(final GetDomainGroupsByShortNames inDomainGroupsByShortNameMapper,
            final GetAllPersonIdsWhoHaveGroupCoordinatorAccess inGroupCoordMapper,
            final DomainMapper<Long, List<Long>> inGroupFollowersDAO,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper); void authorize(final ServiceActionContext inActionContext);  }