@Test public void testAuthorizeSuccess() throws Exception { final HashMap<String, Serializable> state = new HashMap<String, Serializable>(); final Person person = context.mock(Person.class); final List<Stream> streams = new ArrayList<Stream>(); final Stream stream1 = new Stream(); stream1.setId(1L); streams.add(stream1); context.checking(new Expectations() { { allowing(actionContext).getPrincipal(); will(returnValue(principal)); allowing(principal).getId(); allowing(actionContext).getState(); will(returnValue(state)); oneOf(personMapper).execute(with(any(FindByIdRequest.class))); will(returnValue(person)); oneOf(person).getStreams(); will(returnValue(streams)); oneOf(requestTransformer).transform(actionContext); will(returnValue(1L)); } }); sut.authorize(actionContext); context.assertIsSatisfied(); }
public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { Person person = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); inActionContext.getState().put("person", person); boolean found = false; List<Stream> streams = person.getStreams(); Long streamId = (Long) requestTransformer.transform(inActionContext); for (Stream s : streams) { if (s.getId() == streamId) { found = true; break; } } if (!found && streamId != 0) { throw new AuthorizationException(inActionContext.getPrincipal().getAccountId() + " cannot modify stream " + streamId); } }
ModifyStreamForCurrentUserAuthorization implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { Person person = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); inActionContext.getState().put("person", person); boolean found = false; List<Stream> streams = person.getStreams(); Long streamId = (Long) requestTransformer.transform(inActionContext); for (Stream s : streams) { if (s.getId() == streamId) { found = true; break; } } if (!found && streamId != 0) { throw new AuthorizationException(inActionContext.getPrincipal().getAccountId() + " cannot modify stream " + streamId); } } }
ModifyStreamForCurrentUserAuthorization implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { Person person = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); inActionContext.getState().put("person", person); boolean found = false; List<Stream> streams = person.getStreams(); Long streamId = (Long) requestTransformer.transform(inActionContext); for (Stream s : streams) { if (s.getId() == streamId) { found = true; break; } } if (!found && streamId != 0) { throw new AuthorizationException(inActionContext.getPrincipal().getAccountId() + " cannot modify stream " + streamId); } } ModifyStreamForCurrentUserAuthorization(final FindByIdMapper<Person> inPersonMapper,
            final RequestTransformer inRequestTransformer); }
ModifyStreamForCurrentUserAuthorization implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { Person person = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); inActionContext.getState().put("person", person); boolean found = false; List<Stream> streams = person.getStreams(); Long streamId = (Long) requestTransformer.transform(inActionContext); for (Stream s : streams) { if (s.getId() == streamId) { found = true; break; } } if (!found && streamId != 0) { throw new AuthorizationException(inActionContext.getPrincipal().getAccountId() + " cannot modify stream " + streamId); } } ModifyStreamForCurrentUserAuthorization(final FindByIdMapper<Person> inPersonMapper,
            final RequestTransformer inRequestTransformer); void authorize(final PrincipalActionContext inActionContext); }
ModifyStreamForCurrentUserAuthorization implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { Person person = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); inActionContext.getState().put("person", person); boolean found = false; List<Stream> streams = person.getStreams(); Long streamId = (Long) requestTransformer.transform(inActionContext); for (Stream s : streams) { if (s.getId() == streamId) { found = true; break; } } if (!found && streamId != 0) { throw new AuthorizationException(inActionContext.getPrincipal().getAccountId() + " cannot modify stream " + streamId); } } ModifyStreamForCurrentUserAuthorization(final FindByIdMapper<Person> inPersonMapper,
            final RequestTransformer inRequestTransformer); void authorize(final PrincipalActionContext inActionContext);  }