@Test(expected = AccessDeniedException.class) public void authorizeWithOutAccess() { final FeedSubscriber feed1 = context.mock(FeedSubscriber.class); final FeedSubscriber feed2 = context.mock(FeedSubscriber.class, "f2"); final List<FeedSubscriber> feeds = new ArrayList<FeedSubscriber>(); feeds.add(feed1); feeds.add(feed2); final Serializable[] paramsForAuthorizor = new Serializable[1]; paramsForAuthorizor[0] = "something"; final HashMap<String, Serializable> values = new HashMap<String, Serializable>(); values.put("EUREKA:USER", "user"); values.put("EUREKA:GROUP", "something"); context.checking(new Expectations() { { oneOf(getEntityId).getEntityId(values); oneOf(getFeedSubsMapper).execute(with(any(GetFeedSubscriberRequest.class))); will(returnValue(feeds)); allowing(feed1).getId(); will(returnValue(1L)); allowing(feed2).getId(); will(returnValue(3L)); allowing(param).getEntityId(); will(returnValue("something")); allowing(param).getFeedSubscriberId(); will(returnValue(2L)); allowing(ac).getPrincipal(); will(returnValue(principal)); allowing(ac).getParams(); will(returnValue(param)); allowing(principal).getAccountId(); will(returnValue("user")); allowing(principal).getId(); will(returnValue(9L)); } }); sut.authorize(ac); context.assertIsSatisfied(); }
public void authorize(final PrincipalActionContext inActionContext) { DeleteFeedSubscriptionRequest request = (DeleteFeedSubscriptionRequest) inActionContext.getParams(); Serializable[] paramsForAuthorizor = new Serializable[1]; paramsForAuthorizor[0] = request.getEntityId(); HashMap<String, Serializable> values = new HashMap<String, Serializable>(); Principal principal = inActionContext.getPrincipal(); values.put("EUREKA:USER", principal.getAccountId()); values.put("EUREKA:GROUP", request.getEntityId()); List<FeedSubscriber> feedSubs = getFeedSubsMapper.execute(new GetFeedSubscriberRequest(0L, getEntityId.getEntityId(values), type, principal.getId())); boolean found = false; for (FeedSubscriber feedSub : feedSubs) { if (feedSub.getId() == request.getFeedSubscriberId()) { found = true; break; } } if (!found) { throw new AccessDeniedException("You can only delete feed subscriptions you own."); } }
DeleteFeedSubscriberAuthorizationStrategy implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) { DeleteFeedSubscriptionRequest request = (DeleteFeedSubscriptionRequest) inActionContext.getParams(); Serializable[] paramsForAuthorizor = new Serializable[1]; paramsForAuthorizor[0] = request.getEntityId(); HashMap<String, Serializable> values = new HashMap<String, Serializable>(); Principal principal = inActionContext.getPrincipal(); values.put("EUREKA:USER", principal.getAccountId()); values.put("EUREKA:GROUP", request.getEntityId()); List<FeedSubscriber> feedSubs = getFeedSubsMapper.execute(new GetFeedSubscriberRequest(0L, getEntityId.getEntityId(values), type, principal.getId())); boolean found = false; for (FeedSubscriber feedSub : feedSubs) { if (feedSub.getId() == request.getFeedSubscriberId()) { found = true; break; } } if (!found) { throw new AccessDeniedException("You can only delete feed subscriptions you own."); } } }
DeleteFeedSubscriberAuthorizationStrategy implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) { DeleteFeedSubscriptionRequest request = (DeleteFeedSubscriptionRequest) inActionContext.getParams(); Serializable[] paramsForAuthorizor = new Serializable[1]; paramsForAuthorizor[0] = request.getEntityId(); HashMap<String, Serializable> values = new HashMap<String, Serializable>(); Principal principal = inActionContext.getPrincipal(); values.put("EUREKA:USER", principal.getAccountId()); values.put("EUREKA:GROUP", request.getEntityId()); List<FeedSubscriber> feedSubs = getFeedSubsMapper.execute(new GetFeedSubscriberRequest(0L, getEntityId.getEntityId(values), type, principal.getId())); boolean found = false; for (FeedSubscriber feedSub : feedSubs) { if (feedSub.getId() == request.getFeedSubscriberId()) { found = true; break; } } if (!found) { throw new AccessDeniedException("You can only delete feed subscriptions you own."); } } DeleteFeedSubscriberAuthorizationStrategy(final GetFeedSubscriptionsByEntity inGetFeedSubsMapper,
            final GetEntityIdForFeedSubscription inGetEntityId, final EntityType inType); }
DeleteFeedSubscriberAuthorizationStrategy implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) { DeleteFeedSubscriptionRequest request = (DeleteFeedSubscriptionRequest) inActionContext.getParams(); Serializable[] paramsForAuthorizor = new Serializable[1]; paramsForAuthorizor[0] = request.getEntityId(); HashMap<String, Serializable> values = new HashMap<String, Serializable>(); Principal principal = inActionContext.getPrincipal(); values.put("EUREKA:USER", principal.getAccountId()); values.put("EUREKA:GROUP", request.getEntityId()); List<FeedSubscriber> feedSubs = getFeedSubsMapper.execute(new GetFeedSubscriberRequest(0L, getEntityId.getEntityId(values), type, principal.getId())); boolean found = false; for (FeedSubscriber feedSub : feedSubs) { if (feedSub.getId() == request.getFeedSubscriberId()) { found = true; break; } } if (!found) { throw new AccessDeniedException("You can only delete feed subscriptions you own."); } } DeleteFeedSubscriberAuthorizationStrategy(final GetFeedSubscriptionsByEntity inGetFeedSubsMapper,
            final GetEntityIdForFeedSubscription inGetEntityId, final EntityType inType); void authorize(final PrincipalActionContext inActionContext); }
DeleteFeedSubscriberAuthorizationStrategy implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) { DeleteFeedSubscriptionRequest request = (DeleteFeedSubscriptionRequest) inActionContext.getParams(); Serializable[] paramsForAuthorizor = new Serializable[1]; paramsForAuthorizor[0] = request.getEntityId(); HashMap<String, Serializable> values = new HashMap<String, Serializable>(); Principal principal = inActionContext.getPrincipal(); values.put("EUREKA:USER", principal.getAccountId()); values.put("EUREKA:GROUP", request.getEntityId()); List<FeedSubscriber> feedSubs = getFeedSubsMapper.execute(new GetFeedSubscriberRequest(0L, getEntityId.getEntityId(values), type, principal.getId())); boolean found = false; for (FeedSubscriber feedSub : feedSubs) { if (feedSub.getId() == request.getFeedSubscriberId()) { found = true; break; } } if (!found) { throw new AccessDeniedException("You can only delete feed subscriptions you own."); } } DeleteFeedSubscriberAuthorizationStrategy(final GetFeedSubscriptionsByEntity inGetFeedSubsMapper,
            final GetEntityIdForFeedSubscription inGetEntityId, final EntityType inType); void authorize(final PrincipalActionContext inActionContext);  }