Search in sources :

Example 1 with TimeServiceImpl

use of org.cloudfoundry.identity.uaa.util.TimeServiceImpl in project uaa by cloudfoundry.

the class UaaMetricsFilterTests method intolerable_request.

@Test
void intolerable_request() throws Exception {
    TimeService slowRequestTimeService = new TimeService() {

        long now = System.currentTimeMillis();

        @Override
        public long getCurrentTimeMillis() {
            now += 5000;
            return now;
        }
    };
    for (TimeService timeService : Arrays.asList(slowRequestTimeService, new TimeServiceImpl())) {
        reset(publisher);
        filter = new UaaMetricsFilter(true, true, timeService);
        filter.setNotificationPublisher(publisher);
        String path = "/authenticate/test";
        setRequestData(path);
        filter.getUriGroup(request).setLimit(1000);
        filter.doFilterInternal(request, response, chain);
        MetricsQueue metricsQueue = filter.getMetricsQueue(filter.getUriGroup(request).getGroup());
        RequestMetricSummary totals = metricsQueue.getTotals();
        assertEquals(1, totals.getCount());
        assertEquals(timeService == slowRequestTimeService ? 1 : 0, totals.getIntolerableCount());
        ArgumentCaptor<Notification> argumentCaptor = ArgumentCaptor.forClass(Notification.class);
        verify(publisher).sendNotification(argumentCaptor.capture());
        Notification capturedArg = argumentCaptor.getValue();
        assertEquals("/api", capturedArg.getType());
    }
}
Also used : TimeServiceImpl(org.cloudfoundry.identity.uaa.util.TimeServiceImpl) TimeService(org.cloudfoundry.identity.uaa.util.TimeService) Mockito.anyString(org.mockito.Mockito.anyString) Notification(javax.management.Notification) Test(org.junit.jupiter.api.Test)

Example 2 with TimeServiceImpl

use of org.cloudfoundry.identity.uaa.util.TimeServiceImpl in project uaa by cloudfoundry.

the class UaaMetricsFilterTests method idle_counter.

@Test
void idle_counter() throws Exception {
    IdleTimer mockIdleTimer = mock(IdleTimer.class);
    setRequestData("/oauth/token");
    final FilterChain chain = mock(FilterChain.class);
    final UaaMetricsFilter filter = new UaaMetricsFilter(true, false, new TimeServiceImpl());
    ReflectionTestUtils.setField(filter, "inflight", mockIdleTimer);
    filter.doFilterInternal(request, response, chain);
    verify(chain, times(1)).doFilter(same(request), same(response));
    verify(mockIdleTimer, times(1)).startRequest();
    verify(mockIdleTimer, times(1)).endRequest();
}
Also used : TimeServiceImpl(org.cloudfoundry.identity.uaa.util.TimeServiceImpl) FilterChain(javax.servlet.FilterChain) Test(org.junit.jupiter.api.Test)

Example 3 with TimeServiceImpl

use of org.cloudfoundry.identity.uaa.util.TimeServiceImpl in project uaa by cloudfoundry.

the class UaaMetricsFilterTests method happy_path.

@Test
void happy_path() throws Exception {
    filter = spy(new UaaMetricsFilter(true, true, new TimeServiceImpl()));
    filter.setNotificationPublisher(publisher);
    String path = performTwoSimpleRequests();
    Map<String, String> summary = filter.getSummary();
    assertNotNull(summary);
    assertFalse(summary.isEmpty());
    assertEquals(2, summary.size());
    for (String uri : Arrays.asList(path, MetricsUtil.GLOBAL_GROUP)) {
        MetricsQueue totals = readValue(summary.get(filter.getUriGroup(request).getGroup()), MetricsQueue.class);
        assertNotNull(totals, "URI:" + uri);
        for (StatusCodeGroup status : Arrays.asList(StatusCodeGroup.SUCCESS, StatusCodeGroup.SERVER_ERROR)) {
            RequestMetricSummary total = totals.getDetailed().get(status);
            assertEquals(1, total.getCount(), "URI:" + uri);
        }
    }
    assertNull(MetricsAccessor.getCurrent());
    ArgumentCaptor<Notification> argumentCaptor = ArgumentCaptor.forClass(Notification.class);
    verify(publisher, times(2)).sendNotification(argumentCaptor.capture());
    List<Notification> capturedArg = argumentCaptor.getAllValues();
    assertEquals(2, capturedArg.size());
    assertEquals("/api", capturedArg.get(0).getType());
}
Also used : TimeServiceImpl(org.cloudfoundry.identity.uaa.util.TimeServiceImpl) Mockito.anyString(org.mockito.Mockito.anyString) Notification(javax.management.Notification) Test(org.junit.jupiter.api.Test)

Example 4 with TimeServiceImpl

use of org.cloudfoundry.identity.uaa.util.TimeServiceImpl in project uaa by cloudfoundry.

the class JdbcScimGroupMembershipManagerTests method setUp.

@BeforeEach
void setUp() {
    generator = new RandomValueStringGenerator();
    otherIdentityZone = MultitenancyFixture.identityZone("otherIdentityZone-" + generator.generate(), "otherIdentityZone-" + generator.generate());
    uaaIdentityZone = IdentityZone.getUaa();
    JdbcPagingListFactory pagingListFactory = new JdbcPagingListFactory(jdbcTemplate, limitSqlAdapter);
    JdbcScimUserProvisioning jdbcScimUserProvisioning = new JdbcScimUserProvisioning(jdbcTemplate, pagingListFactory, passwordEncoder);
    jdbcScimGroupProvisioning = new JdbcScimGroupProvisioning(jdbcTemplate, pagingListFactory);
    jdbcScimGroupMembershipManager = new JdbcScimGroupMembershipManager(jdbcTemplate, new TimeServiceImpl(), jdbcScimUserProvisioning, null);
    jdbcScimGroupMembershipManager.setScimGroupProvisioning(jdbcScimGroupProvisioning);
    IdentityZoneHolder.get().getConfig().getUserConfig().setDefaultGroups(Collections.singletonList("uaa.user"));
    jdbcScimGroupProvisioning.createOrGet(new ScimGroup(null, "uaa.user", IdentityZoneHolder.get().getId()), IdentityZoneHolder.get().getId());
    addUsersAndGroups(jdbcTemplate, otherIdentityZone.getId(), otherIdentityZone.getId() + "-");
    addUsersAndGroups(jdbcTemplate, uaaIdentityZone.getId(), "");
    validateCount(0, jdbcTemplate, IdentityZoneHolder.get().getId());
}
Also used : TimeServiceImpl(org.cloudfoundry.identity.uaa.util.TimeServiceImpl) JdbcPagingListFactory(org.cloudfoundry.identity.uaa.resources.jdbc.JdbcPagingListFactory) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ScimGroup(org.cloudfoundry.identity.uaa.scim.ScimGroup) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with TimeServiceImpl

use of org.cloudfoundry.identity.uaa.util.TimeServiceImpl in project uaa by cloudfoundry.

the class JdbcScimGroupProvisioningTests method initJdbcScimGroupProvisioningTests.

@BeforeEach
void initJdbcScimGroupProvisioningTests() {
    generator = new RandomValueStringGenerator();
    SecureRandom random = new SecureRandom();
    random.setSeed(System.nanoTime());
    generator.setRandom(random);
    zoneId = generator.generate();
    IdentityZone zone = new IdentityZone();
    zone.setId(zoneId);
    IdentityZoneHolder.set(zone);
    IdentityZoneHolder.get().getConfig().getUserConfig().setDefaultGroups(new ArrayList<>());
    validateGroupCountInZone(0, zoneId);
    dao = spy(new JdbcScimGroupProvisioning(jdbcTemplate, new JdbcPagingListFactory(jdbcTemplate, limitSqlAdapter)));
    users = mock(ScimUserProvisioning.class);
    memberships = new JdbcScimGroupMembershipManager(jdbcTemplate, new TimeServiceImpl(), users, null);
    memberships.setScimGroupProvisioning(dao);
    dao.setJdbcScimGroupMembershipManager(memberships);
    JdbcScimGroupExternalMembershipManager jdbcScimGroupExternalMembershipManager = new JdbcScimGroupExternalMembershipManager(jdbcTemplate);
    jdbcScimGroupExternalMembershipManager.setScimGroupProvisioning(dao);
    dao.setJdbcScimGroupExternalMembershipManager(jdbcScimGroupExternalMembershipManager);
    g1Id = "g1";
    g2Id = "g2";
    g3Id = "g3";
    group1Description = "u" + generator.generate();
    g1 = addGroup(g1Id, group1Description, zoneId);
    group2Description = "u" + generator.generate();
    g2 = addGroup(g2Id, group2Description, zoneId);
    group3Description = "op" + generator.generate();
    g3 = addGroup(g3Id, group3Description, zoneId);
    validateGroupCountInZone(3, zoneId);
}
Also used : IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) TimeServiceImpl(org.cloudfoundry.identity.uaa.util.TimeServiceImpl) JdbcPagingListFactory(org.cloudfoundry.identity.uaa.resources.jdbc.JdbcPagingListFactory) SecureRandom(java.security.SecureRandom) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TimeServiceImpl (org.cloudfoundry.identity.uaa.util.TimeServiceImpl)19 BeforeEach (org.junit.jupiter.api.BeforeEach)11 JdbcPagingListFactory (org.cloudfoundry.identity.uaa.resources.jdbc.JdbcPagingListFactory)7 Test (org.junit.jupiter.api.Test)5 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)5 JdbcScimUserProvisioning (org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimUserProvisioning)4 FilterChain (javax.servlet.FilterChain)3 JdbcScimGroupMembershipManager (org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupMembershipManager)3 JdbcScimGroupProvisioning (org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupProvisioning)3 TimeService (org.cloudfoundry.identity.uaa.util.TimeService)3 Mockito.anyString (org.mockito.Mockito.anyString)3 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 Notification (javax.management.Notification)2 KeyInfoService (org.cloudfoundry.identity.uaa.oauth.KeyInfoService)2 TokenEndpointBuilder (org.cloudfoundry.identity.uaa.oauth.TokenEndpointBuilder)2 IdentityProvider (org.cloudfoundry.identity.uaa.provider.IdentityProvider)2 IdentityProviderProvisioning (org.cloudfoundry.identity.uaa.provider.IdentityProviderProvisioning)2 ScimGroup (org.cloudfoundry.identity.uaa.scim.ScimGroup)2 ScimUserProvisioning (org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning)2