protected boolean isLocalAccount(String username) { ILocalAccountPerson person = accountDao.getPerson(username); if (person != null) { return true; } else { return false; } }
/** * Determine the name to use in the password reset email that identifies the users whose * password has been reset. * * @param person the account that has had its password reset * @return the account holders name */ protected String findDisplayNameFromLocalAccountPerson(ILocalAccountPerson person) { Object name = person.getAttributeValue(ILocalAccountPerson.ATTR_DISPLAY_NAME); if ((name instanceof String) && !StringUtils.isEmpty((String) name)) { return (String) name; } // if display name is not set, just return username. return person.getName(); } }
public PortalRootPersonAttributeDaoTest() { portalRootPersonAttributeDao.setUsernameAttributeProvider(usernameAttributeProvider); }
@Override @Transactional public void updatePassword(String user, String spass, boolean create) throws IOException { // Make sure user is specified correctly if (StringUtils.isBlank(user)) { throw new IllegalArgumentException( "You did not specify a valid user name. Please try again."); } // attempt to get the account form the database ILocalAccountPerson account = this.localAccountDao.getPerson(user); if (account == null) { if (!create) { throw new IllegalArgumentException("No such user: " + user); } account = this.localAccountDao.createPerson(user); } // update the user's password final String encryptedPassword = this.portalPasswordService.encryptPassword(spass); account.setPassword(encryptedPassword); this.localAccountDao.updateAccount(account); logger.info("Password Updated for: {}", user); } }
public PersonForm getForm(String username) { ILocalAccountPerson person = accountDao.getPerson(username); PersonForm form = new PersonForm(accountEditAttributes); form.setUsername(person.getName()); form.setId(person.getId()); Set<String> attributeNames = accountDao.getCurrentAttributeNames(); for (String name : attributeNames) { List<String> values = new ArrayList<String>(); List<Object> attrValues = person.getAttributeValues(name); if (attrValues != null) { for (Object value : person.getAttributeValues(name)) { values.add((String) value); } } form.getAttributes().put(name, new StringListAttribute(values)); } return form; }
public void deleteAccount(IPerson currentUser, String target) { if (!canDeleteUser(currentUser, target)) { throw new RuntimeException( "Current user " + currentUser.getName() + " does not have permissions to update person " + target); } ILocalAccountPerson person = accountDao.getPerson(target); accountDao.deleteAccount(person); log.info("Account " + person.getName() + " successfully deleted"); }
public boolean validateLoginToken(String username, String token) { ILocalAccountPerson person = accountDao.getPerson(username); if (person != null) { Object recordedToken = person.getAttributeValue("loginToken"); if (recordedToken != null && recordedToken.equals(token)) { if (log.isInfoEnabled()) { log.info("Successfully validated security token for user: " + username); } return true; } else { if (log.isInfoEnabled()) { log.info( "Unable to validate security token; recordedToken=" + recordedToken + ", submitted token=" + token); } } } else { if (log.isInfoEnabled()) { log.info("Unable to validate security token; person not found: " + username); } } return false; }
@Override public final Set<IPersonAttributes> getPeopleWithMultivaluedAttributes( Map<String, List<Object>> query) { Validate.notNull(query, "query may not be null."); // Generate the query to pass to the subclass final LocalAccountQuery queryBuilder = this.generateQuery(query); if (queryBuilder == null) { this.logger.debug( "No queryBuilder was generated for query " + query + ", null will be returned"); return null; } // Get the username from the query, if specified final IUsernameAttributeProvider usernameAttributeProvider = this.getUsernameAttributeProvider(); // Execute the query in the subclass final List<ILocalAccountPerson> unmappedPeople = localAccountDao.getPeople(queryBuilder); if (unmappedPeople == null) { return null; } // Map the attributes of the found people according to resultAttributeMapping if it is set final Set<IPersonAttributes> mappedPeople = new LinkedHashSet<IPersonAttributes>(); for (final ILocalAccountPerson unmappedPerson : unmappedPeople) { final IPersonAttributes mappedPerson = this.mapPersonAttributes(unmappedPerson); mappedPeople.add(mappedPerson); } return Collections.unmodifiableSet(mappedPeople); }
/** * Return the list of all possible attribute names. This implementation queries the database to * provide a list of all mapped attribute names, plus all attribute keys currently in-use in the * database. * * @return Set */ @Override public Set<String> getPossibleUserAttributeNames() { final Set<String> names = new HashSet<String>(); names.addAll(this.possibleUserAttributes); names.addAll(localAccountDao.getCurrentAttributeNames()); names.add(displayNameAttribute); return names; }
/** * This method is for "filling" a specific individual. * * @param uid The username (identity) of a known individual * @return A completely "filled" person, including overrides, or <code>null</code> if the person * is unknown */ @Override public IPersonAttributes getPerson(String uid) { final IPersonAttributes rslt = delegatePersonAttributeDao.getPerson(uid); if (rslt == null) { // Nothing we can do with that return null; } return postProcessPerson(rslt, uid); }
/** * @return The appropriate attribute to user for the user name. Since {@link * #getDefaultAttributeName()} should never return null this method should never return null * either. */ protected String getConfiguredUserNameAttribute() { // If configured explicitly use it if (this.unmappedUsernameAttribute != null) { return this.unmappedUsernameAttribute; } final IUsernameAttributeProvider usernameAttributeProvider = this.getUsernameAttributeProvider(); return usernameAttributeProvider.getUsernameAttribute(); } }
@Override public IPersonAttributes getOriginalUserAttributes(String uid) { final IPersonAttributeDao delegatePersonAttributeDao = this.portalRootPersonAttributeDao.getDelegatePersonAttributeDao(); return delegatePersonAttributeDao.getPerson(uid); }
@Test public void testGetAvailableQueryAttributes() { Set<String> attributes = impersonationStatusPersonAttributeDao.getAvailableQueryAttributes(); assertNotNull(attributes); String attribute = attributes.iterator().next(); assertEquals(attribute, "attrs"); }
String first_name, last_name; ILocalAccountDao accountStore = LocalAccountDaoLocator.getLocalAccountDao(); ILocalAccountPerson account = accountStore.getPerson(this.myPrincipal.UID); if (account != null) { first_name = (String) account.getAttributeValue("given"); last_name = (String) account.getAttributeValue("sn"); this.myPrincipal.FullName = first_name + " " + last_name; if (log.isInfoEnabled())
@Override public final Set<IPersonAttributes> getPeopleWithMultivaluedAttributes( Map<String, List<Object>> query) { Validate.notNull(query, "query may not be null."); // Generate the query to pass to the subclass final LocalAccountQuery queryBuilder = this.generateQuery(query); if (queryBuilder == null) { this.logger.debug( "No queryBuilder was generated for query " + query + ", null will be returned"); return null; } // Get the username from the query, if specified final IUsernameAttributeProvider usernameAttributeProvider = this.getUsernameAttributeProvider(); // Execute the query in the subclass final List<ILocalAccountPerson> unmappedPeople = localAccountDao.getPeople(queryBuilder); if (unmappedPeople == null) { return null; } // Map the attributes of the found people according to resultAttributeMapping if it is set final Set<IPersonAttributes> mappedPeople = new LinkedHashSet<IPersonAttributes>(); for (final ILocalAccountPerson unmappedPerson : unmappedPeople) { final IPersonAttributes mappedPerson = this.mapPersonAttributes(unmappedPerson); mappedPeople.add(mappedPerson); } return Collections.unmodifiableSet(mappedPeople); }
/** * Return the list of all possible attribute names. This implementation queries the database to * provide a list of all mapped attribute names, plus all attribute keys currently in-use in the * database. * * @return Set */ @Override public Set<String> getPossibleUserAttributeNames() { final Set<String> names = new HashSet<String>(); names.addAll(this.possibleUserAttributes); names.addAll(localAccountDao.getCurrentAttributeNames()); names.add(displayNameAttribute); return names; }
/** * This method is for "filling" a specific individual. * * @param uid The username (identity) of a known individual * @return A completely "filled" person, including overrides, or <code>null</code> if the person * is unknown */ @Override public IPersonAttributes getPerson(String uid) { final IPersonAttributes rslt = delegatePersonAttributeDao.getPerson(uid); if (rslt == null) { // Nothing we can do with that return null; } return postProcessPerson(rslt, uid); }
/** * @return The appropriate attribute to user for the user name. Since {@link * #getDefaultAttributeName()} should never return null this method should never return null * either. */ protected String getConfiguredUserNameAttribute() { // If configured explicitly use it if (this.unmappedUsernameAttribute != null) { return this.unmappedUsernameAttribute; } final IUsernameAttributeProvider usernameAttributeProvider = this.getUsernameAttributeProvider(); return usernameAttributeProvider.getUsernameAttribute(); } }
public PersonForm getNewAccountForm() { PersonForm form = new PersonForm(accountEditAttributes); Set<String> attributeNames = accountDao.getCurrentAttributeNames(); for (String name : attributeNames) { form.getAttributes() .put(name, new StringListAttribute(Collections.<String>emptyList())); } return form; }
/** * This method is for matching a search query. Each matching item will subsequently be passed to * <code>getPerson(uid)</code> for "filling." */ @Override public Set<IPersonAttributes> getPeopleWithMultivaluedAttributes( Map<String, List<Object>> query) { final Set<IPersonAttributes> people = delegatePersonAttributeDao.getPeopleWithMultivaluedAttributes(query); if (people == null) { return null; } final Set<IPersonAttributes> modifiedPeople = new LinkedHashSet<>(); for (final IPersonAttributes person : people) { /* * WARNING: Not safe to pass uidInQuery in this scenario; results will be "filled" by * getPerson(uid) subsequently. */ final IPersonAttributes mergedPerson = postProcessPerson(person, null); modifiedPeople.add(mergedPerson); } return modifiedPeople; }