/** * Creates a profile in the userprofile database without adding bag. * Method used by the ProfileReadXml. * * @param profile a Profile object */ public synchronized void createProfileWithoutBags(Profile profile) { UserProfile userProfile = new UserProfile(); userProfile.setUsername(profile.getUsername()); if (profile.getPassword() != null) { userProfile.setPassword(PasswordHasher.hashPassword(profile.getPassword())); } userProfile.setSuperuser(profile.isSuperUser); try { uosw.store(userProfile); profile.setUserId(userProfile.getId()); } catch (ObjectStoreException e) { throw new RuntimeException(e); } saveProfile(profile); }
/** * Constructor with the actual objects we are trying to link. * @param bag The SavedBag we are trying to share * @param up The UserProfile we are trying to share this with. */ public UserAlreadyShareBagException(SavedBag bag, UserProfile up) { super(String.format("This bag (%s:%d) is already shared with this user (%s:%d)", bag.getName(), bag.getId(), up.getUsername(), up.getId())); } }
/** * Get a user's password * A check should be made prior to this call to ensure a Profile exists * @param username the username * @return password the password */ public String getPassword(String username) { UserProfile userProfile = getUserProfile(username); return userProfile.getPassword(); }
private Iterable<String> getAllSuperNames() throws ObjectStoreException { Set<String> names = new HashSet<String>(); UserProfile example = new UserProfile(); example.setSuperuser(true); for (UserProfile up: uosw.getObjectsByExample(example, singleton("superuser"))) { names.add(up.getUsername()); } return names; }
private UserProfile getUserProfile(String userName) { UserProfile profile = new UserProfile(); profile.setUsername(userName); Set<String> fieldNames = new HashSet<String>(); fieldNames.add("username"); try { profile = osWriter.getObjectByExample(profile, fieldNames); } catch (ObjectStoreException e) { throw new RuntimeException("Unable to load user profile", e); } return profile; }
ConstraintOp.CONTAINS, new ProxyReference(null, userProfile.getId(), UserProfile.class))); try { if (StringUtils.isBlank(bagName)) { LOG.warn("Failed to load bag with blank name on login for user: " + userProfile.getUsername()); } else { try { } catch (UnknownBagTypeException e) { LOG.warn("The bag '" + bagName + "' for user '" + userProfile.getUsername() + "'" + " with type: " + savedBag.getType() + " is not in the model. It will be saved into invalidBags" , e); InvalidBag bag = new InvalidBag(savedBag, userProfile.getId(), os, uosw); savedInvalidBags.put(bagName, bag); for (SavedQuery query : userProfile.getSavedQuerys()) { try { Reader r = new StringReader(query.getQuery()); for (SavedTemplateQuery template : userProfile.getSavedTemplateQuerys()) { try { StringReader sr = new StringReader(template.getTemplateQuery()); Profile profile = new Profile(this, userProfile.getUsername(), userProfile.getId(),
throw new ObjectStoreException("User is not in the data store."); for (org.intermine.api.userprofile.SavedQuery sq: userProfile.getSavedQuerys()) { uosw.delete(sq); for (SavedTemplateQuery st: userProfile.getSavedTemplateQuerys()) { uosw.delete(st); for (SavedBag sb: userProfile.getSavedBags()) { uosw.delete(sb); for (PermanentToken token: userProfile.getPermanentTokens()) { removePermanentToken(token); for (Tag tag : tagManager.getUserTags(userProfile.getUsername())) { tagManager.deleteTag(tag);
for (Iterator i = userProfile.getSavedQuerys().iterator(); i.hasNext();) { uosw.delete((InterMineObject) i.next()); for (Iterator i = userProfile.getSavedTemplateQuerys().iterator(); i.hasNext();) { uosw.delete((InterMineObject) i.next()); userProfile.setApiKey(profile.getApiKey()); profile.setUserId(userProfile.getId()); } catch (ObjectStoreException e) { throw new RuntimeException(e);
/** * Construct a ProfileManager for the webapp * @param os the ObjectStore to which the webapp is providing an interface * @param userProfileOS the object store that holds user profile information */ public ProfileManager(ObjectStore os, ObjectStoreWriter userProfileOS) { this.os = os; this.uosw = userProfileOS; //retrieve the super user String superUserName = PropertiesUtil.getProperties().getProperty("superuser.account"); UserProfile superuserProfile = new UserProfile(); superuserProfile.setUsername(superUserName); Set<String> fieldNames = new HashSet<String>(); fieldNames.add("username"); try { superuserProfile = uosw.getObjectByExample(superuserProfile, fieldNames); if (superuserProfile != null) { superuser = superuserProfile.getUsername(); } } catch (ObjectStoreException e) { throw new RuntimeException("Unable to load super user profile", e); } pathQueryFormat = loadPathQueryFormatVersion(); permanentTokens.putAll(loadPermanentTokens()); }
/** * Return the name of the user with the given internal DB id. * * If no user with that name exists, returns null. * @param profileId the id of the profile. * @return the name of the user, or null. */ public synchronized String getProfileUserName(int profileId) { try { UserProfile profile = (UserProfile) uosw.getObjectById(profileId, UserProfile.class); return profile.getUsername(); } catch (ObjectStoreException e) { return null; // Not in DB. } catch (NullPointerException e) { return null; // profile was null (impossible!) } }
private Profile getProfileByApiKey(String token, Map<String, List<FieldDescriptor>> classKeys) { UserProfile profile = new UserProfile(); profile.setApiKey(token); Set<String> fieldNames = new HashSet<String>(); fieldNames.add("apiKey"); try { profile = uosw.getObjectByExample(profile, fieldNames); } catch (ObjectStoreException e) { return null; // Could not be found. } if (profile == null) { throw new AuthenticationException( "'" + token + "' is not a valid API access key"); } return getProfile(profile.getUsername(), classKeys); }
@Override public boolean equals(Object o) { return (o instanceof UserProfile && id != null) ? id.equals(((UserProfile)o).getId()) : this == o; } @Override public int hashCode() { return (id != null) ? id.hashCode() : super.hashCode(); }
/** * Get a user's Profile using a username and password. * @param username the username * @param password the password * @return the Profile, or null if one doesn't exist */ public synchronized Profile getProfile(String username, String password) { if (hasProfile(username)) { if (getUserProfile(username).getLocalAccount()) { if (validPassword(username, password)) { return getProfile(username); } } else { return getProfile(username); } } return null; }
ConstraintOp.CONTAINS, new ProxyReference(null, userProfile.getId(), UserProfile.class))); try { if (StringUtils.isBlank(bagName)) { LOG.warn("Failed to load bag with blank name on login for user: " + userProfile.getUsername()); } else { try { } catch (UnknownBagTypeException e) { LOG.warn("The bag '" + bagName + "' for user '" + userProfile.getUsername() + "'" + " with type: " + savedBag.getType() + " is not in the model. It will be saved into invalidBags" , e); InvalidBag bag = new InvalidBag(savedBag, userProfile.getId(), os, uosw); savedInvalidBags.put(bagName, bag); for (SavedQuery query : userProfile.getSavedQuerys()) { try { Reader r = new StringReader(query.getQuery()); for (SavedTemplateQuery template : userProfile.getSavedTemplateQuerys()) { try { StringReader sr = new StringReader(template.getTemplateQuery()); Profile profile = new Profile(this, userProfile.getUsername(), userProfile.getId(),
throw new ObjectStoreException("User is not in the data store."); for (org.intermine.api.userprofile.SavedQuery sq: userProfile.getSavedQuerys()) { uosw.delete(sq); for (SavedTemplateQuery st: userProfile.getSavedTemplateQuerys()) { uosw.delete(st); for (SavedBag sb: userProfile.getSavedBags()) { uosw.delete(sb); for (PermanentToken token: userProfile.getPermanentTokens()) { removePermanentToken(token); for (Tag tag : tagManager.getUserTags(userProfile.getUsername())) { tagManager.deleteTag(tag);
for (Iterator i = userProfile.getSavedQuerys().iterator(); i.hasNext();) { uosw.delete((InterMineObject) i.next()); for (Iterator i = userProfile.getSavedTemplateQuerys().iterator(); i.hasNext();) { uosw.delete((InterMineObject) i.next()); userProfile.setApiKey(profile.getApiKey()); profile.setUserId(userProfile.getId()); } catch (ObjectStoreException e) { throw new RuntimeException(e);
private UserProfile getUserProfile(String userName) { UserProfile profile = new UserProfile(); profile.setUsername(userName); Set<String> fieldNames = new HashSet<String>(); fieldNames.add("username"); try { profile = osWriter.getObjectByExample(profile, fieldNames); } catch (ObjectStoreException e) { throw new RuntimeException("Unable to load user profile", e); } return profile; }
/** * Construct a ProfileManager for the webapp * @param os the ObjectStore to which the webapp is providing an interface * @param userProfileOS the object store that holds user profile information */ public ProfileManager(ObjectStore os, ObjectStoreWriter userProfileOS) { this.os = os; this.uosw = userProfileOS; //retrieve the super user String superUserName = PropertiesUtil.getProperties().getProperty("superuser.account"); UserProfile superuserProfile = new UserProfile(); superuserProfile.setUsername(superUserName); Set<String> fieldNames = new HashSet<String>(); fieldNames.add("username"); try { superuserProfile = uosw.getObjectByExample(superuserProfile, fieldNames); if (superuserProfile != null) { superuser = superuserProfile.getUsername(); } } catch (ObjectStoreException e) { throw new RuntimeException("Unable to load super user profile", e); } pathQueryFormat = loadPathQueryFormatVersion(); permanentTokens.putAll(loadPermanentTokens()); }
/** * Return the name of the user with the given internal DB id. * * If no user with that name exists, returns null. * @param profileId the id of the profile. * @return the name of the user, or null. */ public synchronized String getProfileUserName(int profileId) { try { UserProfile profile = (UserProfile) uosw.getObjectById(profileId, UserProfile.class); return profile.getUsername(); } catch (ObjectStoreException e) { return null; // Not in DB. } catch (NullPointerException e) { return null; // profile was null (impossible!) } }
private Iterable<String> getAllSuperNames() throws ObjectStoreException { Set<String> names = new HashSet<String>(); UserProfile example = new UserProfile(); example.setSuperuser(true); for (UserProfile up: uosw.getObjectsByExample(example, singleton("superuser"))) { names.add(up.getUsername()); } return names; }