@Test public void testAuthorizeForPrivateGroupWithAccess() { final Long groupId = 828L; final HashSet<Long> accessiblePrivateGroupIds = new HashSet<Long>(); accessiblePrivateGroupIds.add(groupId); context.checking(new Expectations() { { oneOf(group).isPublic(); will(returnValue(false)); oneOf(group).getId(); will(returnValue(groupId)); oneOf(actionContext).getParams(); will(returnValue(new StreamPopularHashTagsRequest(ScopeType.GROUP, "shortname"))); oneOf(groupsMapper).fetchUniqueResult("shortname"); will(returnValue(group)); oneOf(actionContext).getPrincipal(); will(returnValue(principal)); oneOf(principal).getId(); will(returnValue(userId)); oneOf(groupAccessMapper).execute(userId); will(returnValue(accessiblePrivateGroupIds)); } }); sut.authorize(actionContext); context.assertIsSatisfied(); }
@Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { StreamPopularHashTagsRequest request = (StreamPopularHashTagsRequest) inActionContext.getParams(); if (request.getStreamEntityScopeType() == ScopeType.GROUP) { DomainGroupModelView group = groupsMapper.fetchUniqueResult(request.getStreamEntityUniqueKey()); if (!group.isPublic()) { Set<Long> groupsUserCanAccess = groupAccessMapper.execute(inActionContext.getPrincipal().getId()); if (!groupsUserCanAccess.contains(group.getId())) { throw new AuthorizationException(inActionContext.getPrincipal().getAccountId() + " cannot access popular hashtags for group with short name " + group.getShortName()); } } } }
StreamPopularHashTagsAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { StreamPopularHashTagsRequest request = (StreamPopularHashTagsRequest) inActionContext.getParams(); if (request.getStreamEntityScopeType() == ScopeType.GROUP) { DomainGroupModelView group = groupsMapper.fetchUniqueResult(request.getStreamEntityUniqueKey()); if (!group.isPublic()) { Set<Long> groupsUserCanAccess = groupAccessMapper.execute(inActionContext.getPrincipal().getId()); if (!groupsUserCanAccess.contains(group.getId())) { throw new AuthorizationException(inActionContext.getPrincipal().getAccountId() + " cannot access popular hashtags for group with short name " + group.getShortName()); } } } } }
StreamPopularHashTagsAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { StreamPopularHashTagsRequest request = (StreamPopularHashTagsRequest) inActionContext.getParams(); if (request.getStreamEntityScopeType() == ScopeType.GROUP) { DomainGroupModelView group = groupsMapper.fetchUniqueResult(request.getStreamEntityUniqueKey()); if (!group.isPublic()) { Set<Long> groupsUserCanAccess = groupAccessMapper.execute(inActionContext.getPrincipal().getId()); if (!groupsUserCanAccess.contains(group.getId())) { throw new AuthorizationException(inActionContext.getPrincipal().getAccountId() + " cannot access popular hashtags for group with short name " + group.getShortName()); } } } } StreamPopularHashTagsAuthorization(final GetDomainGroupsByShortNames inGroupsMapper,
            final GetPrivateCoordinatedAndFollowedGroupIdsForUser inGroupAccessMapper); }
StreamPopularHashTagsAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { StreamPopularHashTagsRequest request = (StreamPopularHashTagsRequest) inActionContext.getParams(); if (request.getStreamEntityScopeType() == ScopeType.GROUP) { DomainGroupModelView group = groupsMapper.fetchUniqueResult(request.getStreamEntityUniqueKey()); if (!group.isPublic()) { Set<Long> groupsUserCanAccess = groupAccessMapper.execute(inActionContext.getPrincipal().getId()); if (!groupsUserCanAccess.contains(group.getId())) { throw new AuthorizationException(inActionContext.getPrincipal().getAccountId() + " cannot access popular hashtags for group with short name " + group.getShortName()); } } } } StreamPopularHashTagsAuthorization(final GetDomainGroupsByShortNames inGroupsMapper,
            final GetPrivateCoordinatedAndFollowedGroupIdsForUser inGroupAccessMapper); @Override void authorize(final PrincipalActionContext inActionContext); }
StreamPopularHashTagsAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { StreamPopularHashTagsRequest request = (StreamPopularHashTagsRequest) inActionContext.getParams(); if (request.getStreamEntityScopeType() == ScopeType.GROUP) { DomainGroupModelView group = groupsMapper.fetchUniqueResult(request.getStreamEntityUniqueKey()); if (!group.isPublic()) { Set<Long> groupsUserCanAccess = groupAccessMapper.execute(inActionContext.getPrincipal().getId()); if (!groupsUserCanAccess.contains(group.getId())) { throw new AuthorizationException(inActionContext.getPrincipal().getAccountId() + " cannot access popular hashtags for group with short name " + group.getShortName()); } } } } StreamPopularHashTagsAuthorization(final GetDomainGroupsByShortNames inGroupsMapper,
            final GetPrivateCoordinatedAndFollowedGroupIdsForUser inGroupAccessMapper); @Override void authorize(final PrincipalActionContext inActionContext);  }