Search in sources :

Example 1 with Scope

use of org.oxauth.persistence.model.Scope in project oxAuth by GluuFederation.

the class ScopeServiceTest method getClaims_ScopeClaimsEmpty_NotProcessed.

@Test
public void getClaims_ScopeClaimsEmpty_NotProcessed() throws Exception {
    User user = new User();
    Scope scope = new Scope();
    scope.setOxAuthClaims(Lists.newArrayList());
    Map<String, Object> result = scopeService.getClaims(user, scope);
    assertNotNull(result);
    assertEquals(result.size(), 0);
    verify(log, never()).trace(startsWith("No claims set for scope:"));
    verifyNoMoreInteractions(log);
    verifyNoMoreInteractions(attributeService);
}
Also used : User(org.gluu.oxauth.model.common.User) Scope(org.oxauth.persistence.model.Scope) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 2 with Scope

use of org.oxauth.persistence.model.Scope in project oxAuth by GluuFederation.

the class ScopeServiceTest method getClaims_AllFieldsSet_ClaimsReturned.

@Test
public void getClaims_AllFieldsSet_ClaimsReturned() throws Exception {
    final Date createdAndUpdatedAt = new Date();
    final String userId = UUID.randomUUID().toString();
    User user = buildRegularUser(userId, createdAndUpdatedAt, createdAndUpdatedAt);
    Scope scope = new Scope();
    scope.setOxAuthClaims(Lists.newArrayList("uid", "updatedAt", "createdAt", "emailVerified", "lastLogon", "metadata"));
    mockRegularGluuAttributesMapping();
    when(ldapEntryManager.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(org.gluu.oxauth.model.common.User) Scope(org.oxauth.persistence.model.Scope) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 3 with Scope

use of org.oxauth.persistence.model.Scope in project oxAuth by GluuFederation.

the class ScopeServiceTest method getClaims_GluuAttributeClaimNameBlank_EmptyResult.

@Test
public void getClaims_GluuAttributeClaimNameBlank_EmptyResult() throws Exception {
    User user = new User();
    Scope scope = new Scope();
    scope.setOxAuthClaims(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(org.gluu.oxauth.model.common.User) Scope(org.oxauth.persistence.model.Scope) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GluuAttribute(org.gluu.model.GluuAttribute) Test(org.testng.annotations.Test)

Example 4 with Scope

use of org.oxauth.persistence.model.Scope in project oxAuth by GluuFederation.

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.setOxAuthClaims(Lists.newArrayList("uid", "updatedAt", "createdAt", "emailVerified", "lastLogon", "metadata", "tmp"));
    mockRegularGluuAttributesMapping();
    when(ldapEntryManager.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(org.gluu.oxauth.model.common.User) Scope(org.oxauth.persistence.model.Scope) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 5 with Scope

use of org.oxauth.persistence.model.Scope in project oxAuth by GluuFederation.

the class ScopeServiceTest method getClaims_ScopeClaimsNull_NotProcessed.

@Test
public void getClaims_ScopeClaimsNull_NotProcessed() throws Exception {
    User user = new User();
    Scope scope = new Scope();
    scope.setOxAuthClaims(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(org.gluu.oxauth.model.common.User) Scope(org.oxauth.persistence.model.Scope) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Aggregations

Scope (org.oxauth.persistence.model.Scope)63 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)12 Operation (io.swagger.v3.oas.annotations.Operation)10 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)10 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)9 HttpEntity (org.apache.http.HttpEntity)8 HttpResponse (org.apache.http.HttpResponse)8 ParseException (org.apache.http.ParseException)8 GluuAttribute (org.gluu.model.GluuAttribute)8 Test (org.junit.Test)8 User (org.gluu.oxauth.model.common.User)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Test (org.testng.annotations.Test)7 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)5 HttpGet (org.apache.http.client.methods.HttpGet)4 HttpPost (org.apache.http.client.methods.HttpPost)4 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)4 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)4 Filter (org.gluu.search.filter.Filter)4