Search in sources :

Example 1 with TimeService

use of org.cloudfoundry.identity.uaa.util.TimeService 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 TimeService

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

the class IdTokenCreatorTest method setup.

@BeforeEach
void setup() throws Exception {
    issuerUrl = "http://localhost:8080/uaa/oauth/token";
    uaaUrl = "http://localhost:8080/uaa";
    clientId = "clientId";
    clientsecret = "clientsecret";
    tokensalt = "tokensalt";
    userId = "userId";
    zoneId = "zoneId";
    jti = "accessTokenId";
    expDate = new Date(100_000);
    authTime = new Date(500);
    amr = new HashSet<String>() {

        {
            add("mfa");
            add("ext");
        }
    };
    acr = new HashSet<String>() {

        {
            add("urn:oasis:names:tc:SAML:2.0:ac:classes:Password");
        }
    };
    givenName = "bruce";
    familyName = "denis";
    email = "u@p.i";
    previousLogonTime = 12345;
    phoneNumber = "(123) 456-7890";
    roles = new HashSet<>();
    roles.add("cook");
    roles.add("plumber");
    userAttributes = new LinkedMultiValueMap<>();
    userAttributes.add("k1", "v11");
    userAttributes.add("k1", "v12");
    userAttributes.add("k2", "v21");
    nonce = "becreative";
    grantType = "password";
    scopes = new HashSet<String>() {

        {
            add("openid");
            add("roles");
            add("profile");
            add("user_attributes");
        }
    };
    origin = "user-origin";
    userName = "username";
    user = new UaaUser(new UaaUserPrototype().withEmail(email).withGivenName(givenName).withFamilyName(familyName).withPhoneNumber(phoneNumber).withId("id1234").withEmail("spongebob@krustykrab.com").withUsername(userName).withPreviousLogonSuccess(previousLogonTime).withVerified(true).withOrigin(origin));
    iatDate = new Date(1L);
    TokenValidityResolver mockTokenValidityResolver = mock(TokenValidityResolver.class);
    when(mockTokenValidityResolver.resolve(clientId)).thenReturn(expDate);
    mockIdentityZoneManager = mock(IdentityZoneManager.class);
    when(mockIdentityZoneManager.getCurrentIdentityZone()).thenReturn(IdentityZone.getUaa());
    when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(zoneId);
    mockUaaUserDatabase = mock(UaaUserDatabase.class);
    when(mockUaaUserDatabase.retrieveUserById(userId)).thenReturn(user);
    userAuthenticationData = new UserAuthenticationData(authTime, amr, acr, scopes, roles, userAttributes, nonce, grantType, jti);
    excludedClaims = new HashSet<>();
    MultitenantClientServices mockMultitenantClientServices = mock(MultitenantClientServices.class);
    clientDetails = new BaseClientDetails();
    clientDetails.setClientId(clientId);
    clientDetails.setClientSecret(clientsecret);
    HashMap<String, String> additionalInfo = new HashMap<String, String>() {

        {
            put(TOKEN_SALT, tokensalt);
        }
    };
    clientDetails.setAdditionalInformation(additionalInfo);
    when(mockMultitenantClientServices.loadClientByClientId(clientId, zoneId)).thenReturn(clientDetails);
    TimeService mockTimeService = mock(TimeService.class);
    when(mockTimeService.getCurrentDate()).thenCallRealMethod();
    when(mockTimeService.getCurrentTimeMillis()).thenReturn(1L);
    tokenCreator = new IdTokenCreator(new TokenEndpointBuilder(uaaUrl), mockTimeService, mockTokenValidityResolver, mockUaaUserDatabase, mockMultitenantClientServices, excludedClaims, mockIdentityZoneManager);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) HashMap(java.util.HashMap) TimeService(org.cloudfoundry.identity.uaa.util.TimeService) UaaUserDatabase(org.cloudfoundry.identity.uaa.user.UaaUserDatabase) Date(java.util.Date) MultitenantClientServices(org.cloudfoundry.identity.uaa.zone.MultitenantClientServices) TokenValidityResolver(org.cloudfoundry.identity.uaa.oauth.TokenValidityResolver) UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) UaaUserPrototype(org.cloudfoundry.identity.uaa.user.UaaUserPrototype) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) TokenEndpointBuilder(org.cloudfoundry.identity.uaa.oauth.TokenEndpointBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with TimeService

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

the class JdbcUaaUserDatabaseTests method setUp.

@BeforeEach
void setUp() {
    defaultAuthorities = UserConfig.DEFAULT_ZONE_GROUPS.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toSet());
    timeService = mock(TimeService.class);
    mockIdentityZoneManager = mock(IdentityZoneManager.class);
    setUpIdentityZone(mockIdentityZoneManager);
    jdbcUaaUserDatabase = new JdbcUaaUserDatabase(jdbcTemplate, timeService, false, mockIdentityZoneManager);
    // TODO: Don't need these checks
    TestUtils.assertNoSuchUser(jdbcTemplate, "id", JOE_ID);
    TestUtils.assertNoSuchUser(jdbcTemplate, "id", MABEL_ID);
    TestUtils.assertNoSuchUser(jdbcTemplate, "id", ALICE_ID);
    TestUtils.assertNoSuchUser(jdbcTemplate, "id", BOB_ID);
    TestUtils.assertNoSuchUser(jdbcTemplate, "userName", "jo@foo.com");
    addUser(JOE_ID, "Joe", "joespassword", true, jdbcTemplate, "zone-the-first");
    addUser(MABEL_ID, "mabel", "mabelspassword", false, jdbcTemplate, "zone-the-first");
    addUser(ALICE_ID, "alice", "alicespassword", false, jdbcTemplate, "zone-the-second");
    addUser(BOB_ID, "bob", "bobspassword", false, jdbcTemplate, "zone-the-bob");
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) JdbcUaaUserDatabase(org.cloudfoundry.identity.uaa.user.JdbcUaaUserDatabase) TimeService(org.cloudfoundry.identity.uaa.util.TimeService) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with TimeService

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

the class CodeStoreEndpointsTests method setUp.

@BeforeEach
void setUp(@Autowired JdbcTemplate jdbcTemplate) {
    currentTime = new AtomicLong(System.currentTimeMillis());
    spiedExpiringCodeStore = spy(new JdbcExpiringCodeStore(jdbcTemplate.getDataSource(), new TimeService() {

        @Override
        public long getCurrentTimeMillis() {
            return currentTime.get();
        }
    }));
    currentIdentityZoneId = createDummyIdentityZone(jdbcTemplate);
    final IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
    when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(currentIdentityZoneId);
    codeStoreEndpoints = new CodeStoreEndpoints(spiedExpiringCodeStore, null, mockIdentityZoneManager);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TimeService(org.cloudfoundry.identity.uaa.util.TimeService) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with TimeService

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

the class LimitedModeUaaFilterTests method setUp.

@BeforeEach
void setUp() throws Exception {
    timeService = new TimeService() {

        @Override
        public long getCurrentTimeMillis() {
            return time.get();
        }
    };
    mockHttpServletRequest = new MockHttpServletRequest();
    mockHttpServletRequest.addHeader(ACCEPT, "*/*");
    mockHttpServletResponse = new MockHttpServletResponse();
    mockFilterChain = mock(FilterChain.class);
    filter = new LimitedModeUaaFilter();
    statusFile = File.createTempFile("uaa-limited-mode.", ".status");
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FilterChain(javax.servlet.FilterChain) TimeService(org.cloudfoundry.identity.uaa.util.TimeService) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TimeService (org.cloudfoundry.identity.uaa.util.TimeService)13 UaaUser (org.cloudfoundry.identity.uaa.user.UaaUser)5 Before (org.junit.Before)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 UaaUserDatabase (org.cloudfoundry.identity.uaa.user.UaaUserDatabase)4 IdentityZoneManager (org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager)4 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)4 ApprovalService (org.cloudfoundry.identity.uaa.approval.ApprovalService)3 UaaUserPrototype (org.cloudfoundry.identity.uaa.user.UaaUserPrototype)3 TimeServiceImpl (org.cloudfoundry.identity.uaa.util.TimeServiceImpl)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 FilterChain (javax.servlet.FilterChain)2 IdTokenGranter (org.cloudfoundry.identity.uaa.oauth.openid.IdTokenGranter)2 IdentityProvider (org.cloudfoundry.identity.uaa.provider.IdentityProvider)2 LockoutPolicy (org.cloudfoundry.identity.uaa.provider.LockoutPolicy)2 JdbcUaaUserDatabase (org.cloudfoundry.identity.uaa.user.JdbcUaaUserDatabase)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2