Search in sources :

Example 41 with User

use of io.jans.as.common.model.common.User in project jans by JanssenProject.

the class AuthenticationService method localAuthenticate.

private Pair<Boolean, User> localAuthenticate(String nameValue, String password, String... nameAttributes) {
    String lowerNameValue = StringHelper.toString(nameValue);
    User user = userService.getUserByAttributes(lowerNameValue, nameAttributes, "uid", "jansStatus");
    if (user != null) {
        if (!checkUserStatus(user)) {
            return new Pair<Boolean, User>(false, user);
        }
        // Use local LDAP server for user authentication
        boolean authenticated = ldapEntryManager.authenticate(user.getDn(), password);
        if (authenticated) {
            configureAuthenticatedUser(user);
            updateLastLogonUserTime(user);
            log.trace("Authenticate: credentials: '{}', credentials.userName: '{}', authenticatedUser.userId: '{}'", System.identityHashCode(credentials), credentials.getUsername(), getAuthenticatedUserId());
        }
        return new Pair<Boolean, User>(authenticated, user);
    }
    return new Pair<Boolean, User>(false, null);
}
Also used : SimpleUser(io.jans.as.common.model.common.SimpleUser) User(io.jans.as.common.model.common.User) Pair(io.jans.util.Pair)

Example 42 with User

use of io.jans.as.common.model.common.User in project jans by JanssenProject.

the class AuthenticationService method onSuccessfulLogin.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void onSuccessfulLogin(SessionId sessionUser) {
    log.info("Attempting to redirect user: SessionUser: {}", sessionUser != null ? sessionUser.getId() : null);
    if ((sessionUser == null) || StringUtils.isBlank(sessionUser.getUserDn())) {
        return;
    }
    User user = sessionIdService.getUser(sessionUser);
    log.info("Attempting to redirect user: User: {}", user);
    if (user == null) {
        log.error("Failed to identify logged in user for session: {}", sessionUser);
        return;
    }
    final Map<String, String> result = sessionUser.getSessionAttributes();
    // parameters must be filled before filtering
    result.put(AuthorizeResponseParam.SESSION_ID, sessionUser.getId());
    // parameters must be filled before filtering
    result.put(AuthorizeResponseParam.SID, sessionUser.getOutsideSid());
    Map<String, String> allowedParameters = requestParameterService.getAllowedParameters(result);
    log.trace("Logged in successfully! User: {}, page: /authorize.xhtml, map: {}", user, allowedParameters);
    facesService.redirect("/authorize.xhtml", (Map) allowedParameters);
}
Also used : SimpleUser(io.jans.as.common.model.common.SimpleUser) User(io.jans.as.common.model.common.User)

Example 43 with User

use of io.jans.as.common.model.common.User in project jans by JanssenProject.

the class ScopeServiceTest method getClaims_ScopeClaimsEmpty_NotProcessed.

@Test
public void getClaims_ScopeClaimsEmpty_NotProcessed() throws Exception {
    User user = new User();
    Scope scope = new Scope();
    scope.setClaims(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(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 44 with User

use of io.jans.as.common.model.common.User in project jans by JanssenProject.

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.setClaims(Lists.newArrayList("uid", "updatedAt", "createdAt", "emailVerified", "lastLogon", "metadata"));
    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 45 with User

use of io.jans.as.common.model.common.User in project jans by JanssenProject.

the class ScopeServiceTest method getClaims_ScopeParamNull_NotProcessed.

@Test
public void getClaims_ScopeParamNull_NotProcessed() throws Exception {
    User user = new User();
    Map<String, Object> result = scopeService.getClaims(user, null);
    assertNotNull(result);
    assertEquals(result.size(), 0);
    verify(log).trace("Scope is null.");
    verifyNoMoreInteractions(log);
    verifyNoMoreInteractions(attributeService);
}
Also used : User(io.jans.as.common.model.common.User) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

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