Search in sources :

Example 91 with User

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);
}
Also used : User(io.jans.as.common.model.common.User) Scope(io.jans.as.persistence.model.Scope) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 92 with User

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);
}
Also used : User(io.jans.as.common.model.common.User) Scope(io.jans.as.persistence.model.Scope) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GluuAttribute(io.jans.model.GluuAttribute) Test(org.testng.annotations.Test)

Example 93 with User

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);
}
Also used : User(io.jans.as.common.model.common.User) Scope(io.jans.as.persistence.model.Scope) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 94 with User

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);
}
Also used : User(io.jans.as.common.model.common.User) Scope(io.jans.as.persistence.model.Scope) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 95 with User

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()));
}
Also used : User(io.jans.as.common.model.common.User) ExecutionContext(io.jans.as.server.model.common.ExecutionContext) AccessToken(io.jans.as.server.model.common.AccessToken) ClientCredentialsGrant(io.jans.as.server.model.common.ClientCredentialsGrant) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) TokenEntity(io.jans.as.server.model.ldap.TokenEntity) Client(io.jans.as.common.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(io.jans.as.server.BaseComponentTest)

Aggregations

User (io.jans.as.common.model.common.User)95 Test (org.testng.annotations.Test)54 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)35 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)12 Client (io.jans.as.common.model.registration.Client)11 Date (java.util.Date)11 SessionId (io.jans.as.server.model.common.SessionId)9 Scope (io.jans.as.persistence.model.Scope)8 ArrayList (java.util.ArrayList)8 SimpleUser (io.jans.as.common.model.common.SimpleUser)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 OAuth2AuditLog (io.jans.as.server.model.audit.OAuth2AuditLog)5 Response (javax.ws.rs.core.Response)5 JsonWebResponse (io.jans.as.model.token.JsonWebResponse)4 AuthorizationGrant (io.jans.as.server.model.common.AuthorizationGrant)4 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 InvalidJwtException (io.jans.as.model.exception.InvalidJwtException)3 CibaRequestCacheControl (io.jans.as.server.model.common.CibaRequestCacheControl)3 CustomAttribute (io.jans.orm.model.base.CustomAttribute)3