@Override public String getName() { return user != null ? user.getName() : null; }
private SecurityRule getRuleForGroup(List<SecurityRule> securityList, UserGroup group){ for(SecurityRule sr : securityList){ if(sr.getGroup() != null && sr.getGroup().getGroupName() != null && sr.getGroup().getGroupName().equals(group.getGroupName())){ return sr; } } return null; }
public RESTSecurityRule(SecurityRule rule) { if(rule.getUser() != null) { User ruleUser = rule.getUser(); user = new RESTUser(); user.setId(ruleUser.getId()); user.setName(ruleUser.getName()); } if(rule.getGroup() != null) { UserGroup ruleGroup = rule.getGroup(); group = new RESTUserGroup(); group.setId(ruleGroup.getId()); group.setGroupName(ruleGroup.getGroupName()); } canRead = rule.isCanRead(); canWrite = rule.isCanWrite(); }
SecurityRule securityRule = new SecurityRule(); Resource resource = new Resource(); resource.setId(resourceId); securityRule.setResource(resource); User user = new User(); user.setId(rule.getUser().getId()); securityRule.setUser(user); UserGroup group = new UserGroup(); group.setId(rule.getGroup().getId()); securityRule.setGroup(group); securityRule.setCanRead(rule.isCanRead()); securityRule.setCanWrite(rule.isCanWrite());
private RESTResource createRESTResource(Resource resource) { RESTResource ret = new RESTResource(); ret.setCategory(new RESTCategory(resource.getCategory().getName())); ret.setName(resource.getName()); ret.setDescription(resource.getDescription()); ret.setMetadata(resource.getMetadata()); if (resource.getData() != null) ret.setData(resource.getData().getData()); if (CollectionUtils.isNotEmpty(resource.getAttribute())) ret.setAttribute(Convert.convertToShortAttributeList(resource.getAttribute())); return ret; }
@Override public RESTUserGroup get(SecurityContext sc, String name) throws NotFoundWebEx { UserGroup ug = userGroupService.get(name); if(ug != null){ return new RESTUserGroup(ug.getId(),ug.getGroupName(),ug.getUsers(), ug.getDescription()); } return null; } }
public boolean insertSpecialUsersGroups(){ if (LOGGER.isDebugEnabled()) { LOGGER.debug("Persisting Reserved UsersGroup... "); } UserGroup ug = new UserGroup(); ug.setGroupName(GroupReservedNames.EVERYONE.groupName()); userGroupDAO.persist(ug); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Special UserGroup '" + ug.getGroupName() + "' persisted!"); } return true; }
@Override public List<StoredData> getAllFull() { List<StoredData> found = storedDataDAO.findAll(); for (StoredData data : found) { Resource resource = data.getResource(); if (resource != null) { List<SecurityRule> security = resourceDAO.findSecurityRules(resource.getId()); resource.setSecurity(security); List<Attribute> attribute = resourceDAO.findAttributes(resource.getId()); resource.setAttribute(attribute); } } return found; }
@Override public User find(Long id) { User user = super.find(id); if (user != null) { // // To load the LAZY list of the user attributes // if (Hibernate.isInitialized(user)) { List<UserAttribute> attributes = user.getAttribute(); Hibernate.initialize(attributes); Set<UserGroup> groups = user.getGroups(); Hibernate.initialize(groups); } } return user; }
@Override public User merge(User entity) { String newpw = entity.getNewPassword(); if (newpw != null && !newpw.isEmpty()) { String enc = PwEncoder.encode(newpw); entity.setPassword(enc); } return super.merge(entity); }
@Override public void updateAttributes(long id, List<UserAttribute> attributes) throws NotFoundServiceEx { User user = userDAO.find(id); if (user == null) { throw new NotFoundServiceEx("User not found " + id); } // // Removing old attributes // List<UserAttribute> oldList = user.getAttribute(); // Iterator<UserAttribute> iterator; if (oldList != null) { for (UserAttribute a : oldList) { userAttributeDAO.removeById(a.getId()); } } // // Saving old attributes // for (UserAttribute a : attributes) { a.setUser(user); userAttributeDAO.persist(a); } }
public static List<String> extratcGroupNames(Set<UserGroup> groups) { List<String> groupNames = new ArrayList<String>(); if (groups == null) { return groupNames; } for (UserGroup ug : groups) { groupNames.add(ug.getGroupName()); } return groupNames; }
private Resource rbr2res(RESTBackupResource rbr, long catId) { Resource ret = Convert.convertResource(rbr.getResource()); ret.getCategory().setId(catId); // remap category return ret; }
@Override public Resource merge(Resource entity) { entity.setLastUpdate(new Date()); return super.merge(entity); }
@Override public void persist(Resource... entities) { if (LOGGER.isDebugEnabled()) { LOGGER.info("Inserting new entities for Resource ... "); } int size = entities.length; Date creation = new Date(); for (int i = 0; i < size; i++) { entities[i].setCreation(creation); } super.persist(entities); }
private RESTBackupResource createResource(Resource resource) { LOGGER.info("Packing resource " + resource.getName()); RESTResource rr = createRESTResource(resource); RESTBackupResource rbr = new RESTBackupResource(); rbr.setResource(rr); return rbr; }
@Override public int hashCode() { return user != null ? user.getName().hashCode() : 42; } }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final GeoStorePrincipal other = (GeoStorePrincipal) obj; if (this.user != other.user && (this.user == null || !this.user.getName().equals(other.user.getName()))) { return false; } return true; }
/** * Gets the username associated to the given sessionId (if it exists). * * @param sessionId * @return */ public String getUserName(String sessionId, boolean refresh) { User userData = userSessionService.getUserData(sessionId); if (userData != null) { if (refresh && autorefresh) { userSessionService.refreshSession(sessionId, userSessionService.getRefreshToken(sessionId)); } return userData.getName(); } return null; }