use of io.jans.as.common.model.common.User in project jans by JanssenProject.
the class ScopeServiceTest method getClaims_DifferentDateFields_ClaimsReturnedWithRightFormat.
@Test
public void getClaims_DifferentDateFields_ClaimsReturnedWithRightFormat() throws Exception {
final String userId = UUID.randomUUID().toString();
final Date createdAt = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000);
final Date updatedAt = new Date(System.currentTimeMillis() - 12 * 60 * 60 * 1000);
final Date lastLogon = new Date();
User user = buildRegularUser(userId, createdAt, updatedAt);
Scope scope = new Scope();
scope.setClaims(Lists.newArrayList("uid", "updatedAt", "createdAt", "emailVerified", "lastLogon", "metadata"));
mockRegularGluuAttributesMapping();
when(entryManager.decodeTime(anyString(), anyString())).thenReturn(lastLogon);
Map<String, Object> result = scopeService.getClaims(user, scope);
assertNotNull(result);
assertEquals(result.size(), 6);
assertEquals(result.get("uid"), userId);
assertEquals(result.get("updated_at"), updatedAt);
assertEquals(result.get("created_at"), createdAt);
assertEquals(result.get("email_verified"), true);
assertEquals(result.get("last_logon"), lastLogon);
assertEquals(result.get("metadata"), "{}");
verifyNoMoreInteractions(log);
verifyNoMoreInteractions(attributeService);
}
use of io.jans.as.common.model.common.User in project jans by JanssenProject.
the class ScopeServiceTest method getClaims_GluuAttributeClaimNameBlank_EmptyResult.
@Test
public void getClaims_GluuAttributeClaimNameBlank_EmptyResult() throws Exception {
User user = new User();
Scope scope = new Scope();
scope.setClaims(Lists.newArrayList("claim1", "claim2"));
when(attributeService.getAttributeByDn(anyString())).thenReturn(new GluuAttribute());
Map<String, Object> result = scopeService.getClaims(user, scope);
assertNotNull(result);
assertEquals(result.size(), 0);
verify(log, times(2)).error(startsWith("Failed to get claim because claim name is not set for attribute"), (Object) isNull());
verifyNoMoreInteractions(log);
verifyNoMoreInteractions(attributeService);
}
use of io.jans.as.common.model.common.User in project jans by JanssenProject.
the class ScopeServiceTest method getClaims_RequestFieldThatDoesntExist_ShouldBeIgnored.
@Test
public void getClaims_RequestFieldThatDoesntExist_ShouldBeIgnored() throws Exception {
final String userId = UUID.randomUUID().toString();
final Date createdAndUpdatedAt = new Date();
User user = buildRegularUser(userId, createdAndUpdatedAt, createdAndUpdatedAt);
Scope scope = new Scope();
scope.setClaims(Lists.newArrayList("uid", "updatedAt", "createdAt", "emailVerified", "lastLogon", "metadata", "tmp"));
mockRegularGluuAttributesMapping();
when(entryManager.decodeTime(anyString(), anyString())).thenReturn(createdAndUpdatedAt);
Map<String, Object> result = scopeService.getClaims(user, scope);
assertNotNull(result);
assertEquals(result.size(), 6);
assertEquals(result.get("uid"), userId);
assertEquals(result.get("updated_at"), createdAndUpdatedAt);
assertEquals(result.get("created_at"), createdAndUpdatedAt);
assertEquals(result.get("email_verified"), true);
assertEquals(result.get("last_logon"), createdAndUpdatedAt);
assertEquals(result.get("metadata"), "{}");
verifyNoMoreInteractions(log);
verifyNoMoreInteractions(attributeService);
}
use of io.jans.as.common.model.common.User in project jans by JanssenProject.
the class ScopeServiceTest method getClaims_ScopeClaimsNull_NotProcessed.
@Test
public void getClaims_ScopeClaimsNull_NotProcessed() throws Exception {
User user = new User();
Scope scope = new Scope();
scope.setClaims(null);
Map<String, Object> result = scopeService.getClaims(user, scope);
assertNotNull(result);
assertEquals(result.size(), 0);
verify(log).trace(startsWith("No claims set for scope:"), (Object) isNull());
verifyNoMoreInteractions(log);
verifyNoMoreInteractions(attributeService);
}
use of io.jans.as.common.model.common.User in project jans by JanssenProject.
the class CleanerTimerTest method token_whichIsExpiredAndDeletable_MustBeRemoved.
@Test
public void token_whichIsExpiredAndDeletable_MustBeRemoved() throws StringEncrypter.EncryptionException {
final Client client = createClient();
clientService.persist(client);
// 1. create token
final ClientCredentialsGrant grant = authorizationGrantList.createClientCredentialsGrant(new User(), client);
final AccessToken accessToken = grant.createAccessToken(new ExecutionContext(null, null));
// 2. token exists
assertNotNull(grantService.getGrantByCode(accessToken.getCode()));
// 3. clean up
cleanerTimer.processImpl();
cacheService.clear();
// 4. token exists
final TokenEntity grantLdap = grantService.getGrantByCode(accessToken.getCode());
assertNotNull(grantLdap);
final Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, -10);
grantLdap.setExpirationDate(calendar.getTime());
grantService.merge(grantLdap);
// 5. clean up
cleanerTimer.processImpl();
cacheService.clear();
// 6. no token in persistence
assertNull(grantService.getGrantByCode(accessToken.getCode()));
}
Aggregations