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());
}
}
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);
}
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");
}
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);
}
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");
}
Aggregations