/** * Create LDAP attributes that represents user in LDAP context. * * @param user User * @return LDAP Attributes */ public final Attributes userToAttributes(User user) { BasicAttributes attrs = new BasicAttributes(); if (USER_LDAP_CLASSES == null) USER_LDAP_CLASSES = userLDAPClasses.split(","); attrs.put(new ObjectClassAttribute(USER_LDAP_CLASSES)); attrs.put(userDNKey, user.getUserName()); attrs.put(userDisplayNameAttr, user.getDisplayName()); attrs.put(userUsernameAttr, user.getUserName()); attrs.put(userPassword, user.getPassword()); attrs.put(userLastNameAttr, user.getLastName()); attrs.put(userFirstNameAttr, user.getFirstName()); attrs.put(userMailAttr, user.getEmail()); attrs.put(ldapDescriptionAttr, "Account for " + user.getDisplayName()); return attrs; }
attrs = am.getAttributes(new SimpleUser(user.getUserName())); } catch (Exception e) { handleException("Cannot obtain attributes for user: " + user.getUserName() + "; ", e); try { long date = Long.parseLong(attrs.get(USER_CREATED_DATE).getValue().toString()); user.setCreatedDate(new Date(date)); } catch (NumberFormatException e) { user.setCreatedDate(dateFormat.parse(attrs.get(USER_CREATED_DATE).getValue().toString())); } catch (ParseException e2) { log.error("Cannot parse the creation date for: " + user.getUserName()); user.setEmail(attrs.get(USER_EMAIL).getValue().toString()); user.setFirstName(attrs.get(USER_FIRST_NAME).getValue().toString()); user.setLastLoginTime(new Date(lastLoginMillis)); user.setLastLoginTime(dateFormat.parse(attrs.get(USER_LAST_LOGIN_TIME).getValue().toString())); } catch (ParseException e2) { log.error("Cannot parse the last login date for: " + user.getUserName()); user.setLastName(attrs.get(USER_LAST_NAME).getValue().toString()); user.setFullName(attrs.get(USER_DISPLAY_NAME).getValue().toString()); user.setOrganizationId(attrs.get(USER_ORGANIZATION_ID).getValue().toString());
private String getDNKeyValue(User user) { String dnKeyValue = user.getUserName(); if (!ldapAttrMapping.userDNKey.equals(ldapAttrMapping.userUsernameAttr)) { if (ldapAttrMapping.userDNKey.equals(ldapAttrMapping.userLastNameAttr)) { dnKeyValue = user.getLastName(); } else if (ldapAttrMapping.userDNKey.equals(ldapAttrMapping.userFirstNameAttr)) { dnKeyValue = user.getFirstName(); } else if (ldapAttrMapping.userDNKey.equals(ldapAttrMapping.userMailAttr)) { dnKeyValue = user.getEmail(); } else if (ldapAttrMapping.userDNKey.equals(ldapAttrMapping.userDisplayNameAttr)) { dnKeyValue = user.getFullName(); } } return dnKeyValue; }
/** * Find user by DN. * * @param ctx {@link LdapContext} * @param userDN user DN * @return {@link User} * @throws Exception if any errors occurs */ protected User findUserByDN(LdapContext ctx, String userDN) throws Exception { if (userDN == null) return null; try { Attributes attrs = ctx.getAttributes(userDN); User user = ldapAttrMapping.attributesToUser(attrs); user.setFullName(user.getFirstName() + " " + user.getLastName()); return user; } catch (NameNotFoundException e) { return null; } }
@Override public void preSave(User user, boolean isNew) throws Exception { if (passwordEncrypter != null && user.getPassword() != null) { User persistedUser = organizationService.getUserHandler().findUserByName(user.getUserName()); if (persistedUser == null || persistedUser.getPassword() == null) { if (LOG.isDebugEnabled()) { LOG.debug("Encrypting password for a new user " + user.getUserName()); } String encodedPassword = new String(passwordEncrypter.encrypt(user.getPassword().getBytes())); user.setPassword(encodedPassword); } else if (!user.getPassword().equals(persistedUser.getPassword())) { if (LOG.isDebugEnabled()) { LOG.debug("Encrypting changed password for user " + user.getUserName()); } String encodedPassword = new String(passwordEncrypter.encrypt(user.getPassword().getBytes())); user.setPassword(encodedPassword); } else { if (LOG.isDebugEnabled()) { LOG.debug("Nothing to encrypt for user " + user.getUserName() + ": password no changed."); } } } } }
private void removeDisplayNameIfNeeded(AttributesManager am, User user) { try { Attribute attr = am.getAttribute(user.getUserName(), USER_DISPLAY_NAME); if (attr != null) { am.removeAttributes(user.getUserName(), new String[] { USER_DISPLAY_NAME }); } } catch (Exception e) { handleException("Cannot remove displayName attribute of user: " + user.getUserName() + "; ", e); } }
if (user.getCreatedDate() != null) { attributes.add(new SimpleAttribute(USER_CREATED_DATE, "" + user.getCreatedDate().getTime())); if (user.getLastLoginTime() != null) { attributes.add(new SimpleAttribute(USER_LAST_LOGIN_TIME, "" + user.getLastLoginTime().getTime())); if (user.getEmail() != null) { attributes.add(new SimpleAttribute(USER_EMAIL, user.getEmail())); if (user.getFirstName() != null) { attributes.add(new SimpleAttribute(USER_FIRST_NAME, user.getFirstName())); if (user.getLastName() != null) { attributes.add(new SimpleAttribute(USER_LAST_NAME, user.getLastName())); if (user.getOrganizationId() != null) { attributes.add(new SimpleAttribute(USER_ORGANIZATION_ID, user.getOrganizationId())); if (user.getPassword() != null) { if (orgService.getConfiguration().isPasswordAsAttribute()) { attributes.add(new SimpleAttribute(USER_PASSWORD, user.getPassword())); } else { try { am.updatePassword(session.getPersistenceManager().findUser(user.getUserName()), user.getPassword()); } catch (Exception e) { handleException("Cannot update password: " + user.getUserName() + "; ", e); throw e; am.updateAttributes(user.getUserName(), attrs);
String email = req.getParameter("email"); portalUser.setUserName(username); portalUser.setPassword(password); portalUser.setFirstName(firstName); portalUser.setLastName(lastName); portalUser.setDisplayName(displayName); portalUser.setEmail(email); orgService.getUserHandler().createUser(portalUser, true); UserProfileHandler profileHandler = orgService.getUserProfileHandler(); UserProfile newUserProfile = profileHandler.findUserProfileByName(portalUser.getUserName()); if (newUserProfile == null) { newUserProfile = orgService.getUserProfileHandler().createUserProfileInstance(portalUser.getUserName()); orgService.getUserHandler().removeUser(portalUser.getUserName(), true);
OrganizationConfig.User data = (OrganizationConfig.User) users.get(i); User user = organizationService.getUserHandler().createUserInstance(data.getUserName()); user.setPassword(data.getPassword()); user.setFirstName(data.getFirstName()); user.setLastName(data.getLastName()); user.setEmail(data.getEmail());
private String readPasswordFromPicketLink(User user) throws Exception { PicketLinkIDMOrganizationServiceImpl orgService = (PicketLinkIDMOrganizationServiceImpl) organizationService; if (orgService.getConfiguration().isPasswordAsAttribute()) { return user.getPassword(); } else { IdentitySession identitySession = picketLinkIDMService.getIdentitySession(); IdentityStoreInvocationContext identitySessionContext = ((IdentitySessionImpl) identitySession).getSessionContext() .resolveStoreInvocationContext(); Session session = ((Session) ((RepositoryIdentityStoreSessionImpl) identitySessionContext.getIdentityStoreSession()) .getIdentityStoreSession("HibernateStore").getSessionContext()); HibernateIdentityObjectType hibernateIdentityObjectType = (HibernateIdentityObjectType) session .createCriteria(HibernateIdentityObjectType.class).add(Restrictions.eq("name", "USER")).uniqueResult(); HibernateIdentityObject hibernateUserObject = (HibernateIdentityObject) session .createCriteria(HibernateIdentityObject.class).add(Restrictions.eq("name", user.getUserName())) .add(Restrictions.eq("identityType", hibernateIdentityObjectType)).uniqueResult(); HibernateIdentityObjectCredential hibernateCredential = (HibernateIdentityObjectCredential) session .createCriteria(HibernateIdentityObjectCredential.class).createAlias("type", "t") .add(Restrictions.eq("t.name", PasswordCredential.TYPE.getName())) .add(Restrictions.eq("identityObject", hibernateUserObject)).setCacheable(true).uniqueResult(); if (hibernateCredential != null) { return hibernateCredential.getTextValue(); } else { return ""; } } }
@Override public void processRender(WebuiRequestContext context) throws Exception { HttpServletRequest request = Util.getPortalRequestContext().getRequest(); User pUser = (User) authRegistry.getAttributeOfClient(request, OAuthConstants.ATTRIBUTE_AUTHENTICATED_PORTAL_USER); if (portalUser == null || (pUser != null && pUser != portalUser)) { if (pUser == null) { log.warn("portalUser from OAuth login is not available!"); pUser = new UserImpl(); pUser.setDisplayName(""); } this.portalUser = pUser; setupUserToRegisterForm(); User detectedUser = (User) authRegistry.getAttributeOfClient(request, OAuthConst.ATTRIBUTE_AUTHENTICATED_PORTAL_USER_DETECTED); if (detectedUser != null) { getChild(UIRegisterForm.class).setRendered(false); UIOAuthInvitationForm invitationForm = getChild(UIOAuthInvitationForm.class); invitationForm.setRendered(true); String detected = detectedUser.getUserName(); if (!detected.equals(pUser.getUserName()) && detectedUser.getEmail().equals(pUser.getEmail())) { detected = detectedUser.getEmail(); } invitationForm.setDetectedUserName(detected); } else { getChild(UIRegisterForm.class).setRendered(true); getChild(UIOAuthInvitationForm.class).setRendered(false); } } super.processRender(context); }
if (!user.isEnabled()) { throw new DisabledUserException(username); authenticated = user.getPassword().equals(password); } else { try { org.picketlink.idm.api.User idmUser = session.getPersistenceManager().findUser(user.getUserName());
OAuthProviderType providerType = principal.getOauthProviderType(); User user = providerType.getOauthPrincipalProcessor().convertToGateInUser(principal); user.setPassword(randomPassword(16)); UserProfile newUserProfile = profileHandler.findUserProfileByName(user.getUserName()); if (newUserProfile == null) { newUserProfile = orgService.getUserProfileHandler().createUserProfileInstance(user.getUserName()); Identity identity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, user.getUserName(), true); Profile p = identity.getProfile(); log.error("Exception when trying to create user: " + user.getUserName() + " on-fly", ex);
User gtnUser = providerType.getOauthPrincipalProcessor().convertToGateInUser(principal); String email = gtnUser.getEmail(); String username = gtnUser.getUserName();
public void saveUser(User user, boolean broadcast) throws Exception { if (log.isTraceEnabled()) { Tools.logMethodIn(log, LogLevel.TRACE, "saveUser", new Object[] { "user", user, "broadcast", broadcast }); } if (user != null && !user.isEnabled()) { throw new DisabledUserException(user.getUserName()); } IdentitySession session = service_.getIdentitySession(); if (broadcast) { preSave(user, false); } persistUserInfo(user, session, false); if (broadcast) { postSave(user, false); } }
/** * {@inheritDoc} */ public boolean authenticate(String username, String password, PasswordEncrypter pe) throws Exception { User user = findUserByName(username); if (user == null) { return false; } boolean authenticated; if (pe == null) { authenticated = user.getPassword().equals(password); } else { String encryptedPassword = new String(pe.encrypt(user.getPassword().getBytes())); authenticated = encryptedPassword.equals(password); } if (authenticated) { UserImpl userImpl = (UserImpl)user; userImpl.setLastLoginTime(Calendar.getInstance().getTime()); saveUser(userImpl, false); } return authenticated; }
private void setSelectedItem() throws Exception { for (Object o : this.uiIterator_.getCurrentPageData()) { User u = (User) o; UIFormCheckBoxInput input = this.getUIFormCheckBoxInput(u.getUserName()); if (input != null) { this.uiIterator_.setSelectedItem(u.getUserName(), input.isChecked()); } } }
if (!user.getFullName().equals(existingUser.getFullName())) user.getFullName())); modifications.add(mod); mod = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(ldapAttrMapping.ldapDescriptionAttr, user.getFullName())); modifications.add(mod); if (!user.getUserName().equals(existingUser.getUserName())) user.getUserName())); modifications.add(mod); if (!user.getLastName().equals(existingUser.getLastName())) user.getLastName())); modifications.add(mod); if (!user.getFirstName().equals(existingUser.getFirstName())) user.getFirstName())); modifications.add(mod); if (!user.getEmail().equals(existingUser.getEmail())) .getEmail())); modifications.add(mod);
user.setPassword(userPasswordAccount); user.setFirstName(firstNameAccount); user.setLastName(lastNameAccount); user.setEmail(emailAccount); adminUser.setPassword(adminPassword); organizationService.getUserHandler().saveUser(adminUser, false); } catch (Exception e) {
userDN = getDNFromUsername(ctx, user.getUserName()); if (userDN == null) return; existingUser = getUserFromUsername(ctx, user.getUserName()); ModificationItem[] mods = createUserModification(user, existingUser); if (broadcast) postSave(user, false); cacheHandler.put(user.getUserName(), user, CacheType.USER); break; if (existingUser != null && (!user.getPassword().equals(existingUser.getPassword())))