Пример #1
0
  @Before
  public void initJdbcApprovalStoreTests() {

    dao =
        new JdbcApprovalStore(
            jdbcTemplate,
            new JdbcPagingListFactory(jdbcTemplate, limitSqlAdapter),
            new SimpleSearchQueryConverter());

    eventPublisher = TestApplicationEventPublisher.forEventClass(ApprovalModifiedEvent.class);
    dao.setApplicationEventPublisher(eventPublisher);

    addApproval("u1", "c1", "uaa.user", 6000, APPROVED);
    addApproval("u1", "c2", "uaa.admin", 12000, DENIED);
    addApproval("u2", "c1", "openid", 6000, APPROVED);
  }
Пример #2
0
  @Test
  public void testAddingAndUpdatingAnApprovalPublishesEvents() throws Exception {
    UaaTestAccounts testAccounts = UaaTestAccounts.standard(null);

    Approval approval =
        new Approval()
            .setUserId(testAccounts.getUserName())
            .setClientId("app")
            .setScope("cloud_controller.read")
            .setExpiresAt(Approval.timeFromNow(1000))
            .setStatus(ApprovalStatus.APPROVED);

    eventPublisher.clearEvents();

    MockAuthentication authentication = new MockAuthentication();
    SecurityContextHolder.getContext().setAuthentication(authentication);

    dao.addApproval(approval);

    Assert.assertEquals(1, eventPublisher.getEventCount());

    ApprovalModifiedEvent addEvent = eventPublisher.getLatestEvent();
    Assert.assertEquals(approval, addEvent.getSource());
    Assert.assertEquals(authentication, addEvent.getAuthentication());
    Assert.assertEquals(
        "{\"scope\":\"cloud_controller.read\",\"status\":\"APPROVED\"}",
        addEvent.getAuditEvent().getData());

    approval.setStatus(DENIED);

    eventPublisher.clearEvents();
    dao.addApproval(approval);

    Assert.assertEquals(1, eventPublisher.getEventCount());

    ApprovalModifiedEvent modifyEvent = eventPublisher.getLatestEvent();
    Assert.assertEquals(approval, modifyEvent.getSource());
    Assert.assertEquals(authentication, modifyEvent.getAuthentication());
    Assert.assertEquals(
        "{\"scope\":\"cloud_controller.read\",\"status\":\"DENIED\"}",
        addEvent.getAuditEvent().getData());
  }