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