/** * This method maps the sessions of users who are connected to the VM, but are not the 'logged-in'/'console' user. * Currently the information that engine supplies about these users is only a string, which contains the name of * only one such user, if exists (the user is not necessarily an ovirt user). In the future the engine may pass * multiple 'guest' users, along with their IPs and perhaps also the connection protocols that they are using (SSH, * RDP...) */ private static Sessions mapGuestSessions(org.ovirt.engine.core.common.businessentities.VM vm, Sessions sessions) { String guestUserName = vm.getGuestCurentUserName(); if (guestUserName != null && !guestUserName.isEmpty()) { Session guestSession = new Session(); User user = new User(); user.setUserName(guestUserName); guestSession.setUser(user); // TODO: in the future, map the user-IP and connection protocol as well sessions.getSessions().add(guestSession); } return sessions; }
@Mapping(from = VdsStatic.class, to = Ssh.class) public static Ssh map(VdsStatic entity, Ssh template) { Ssh model = template != null ? template : new Ssh(); model.setPort(entity.getSshPort()); model.setUser(new User()); model.getUser().setUserName(entity.getSshUsername()); model.setFingerprint(entity.getSshKeyFingerprint()); return model; }
String domainName = parseDomainName(consoleUserName); User consoleUser = new User(); consoleUser.setUserName(userName); consoleUser.setDomain(new Domain()); consoleUser.getDomain().setName(domainName);
@Test public void testAddUser3() { setUpEntityQueryExpectations(QueryType.GetDomainList, QueryParametersBase.class, new String[] {}, new Object[] {}, setUpDomains()); setUpAddUserExpectations("ADUSER@" + DOMAIN + ":: username=" + NAMES[0]); User model = new User(); model.setUserName(NAMES[0] + "@" + DOMAIN); Response response = collection.add(model); verifyAddUser(response); }
@Mapping(from = DbUser.class, to = User.class) public static User map(DbUser entity, User template) { User model = template != null ? template : new User(); model.setName(entity.getFirstName()); model.setUserName(entity.getLoginName() + "@" + entity.getDomain()); model.setPrincipal(entity.getLoginName()); model.setId(entity.getId().toString()); model.setLastName(entity.getLastName()); model.setEmail(entity.getEmail()); model.setDepartment(entity.getDepartment()); model.setDomainEntryId(DirectoryEntryIdUtils.encode(entity.getExternalId())); model.setNamespace(entity.getNamespace()); if (entity.getGroupNames() != null && entity.getGroupNames().size() > 0) { model.setGroups(new Groups()); for (String name : entity.getGroupNames()) { Group group = new Group(); group.setName(name); model.getGroups().getGroups().add(group); } } if (!StringUtils.isEmpty(entity.getDomain())) { Domain dom = new Domain(); dom.setName(entity.getDomain()); dom.setId(DirectoryEntryIdUtils.encode(dom.getName())); model.setDomain(dom); } return model; }
@Mapping(from = DirectoryUser.class, to = User.class) public static User map(DirectoryUser entity, User template) { User model = template != null ? template : new User(); model.setName(entity.getFirstName()); model.setUserName(entity.getName() + "@" + entity.getDirectoryName()); model.setId(DirectoryEntryIdUtils.encode(entity.getId())); model.setLastName(entity.getLastName()); model.setEmail(entity.getEmail()); model.setDepartment(entity.getDepartment()); model.setPrincipal(entity.getPrincipal()); model.setNamespace(entity.getNamespace()); if (entity.getGroups() != null) { model.setGroups(new Groups()); for (DirectoryGroup directoryGroup : entity.getGroups()) { Group group = new Group(); group.setName(directoryGroup.getName()); model.getGroups().getGroups().add(group); } } if (!StringUtils.isEmpty(entity.getDirectoryName())) { Domain dom = new Domain(); dom.setName(entity.getDirectoryName()); dom.setId(DirectoryEntryIdUtils.encode(dom.getName())); model.setDomain(dom); } return model; }
@Test public void testAddUser2() { setUpEntityQueryExpectations(QueryType.GetDomainList, QueryParametersBase.class, new String[] {}, new Object[] {}, setUpDomains()); setUpAddUserExpectations("ADUSER@" + DOMAIN + ":: username=" + NAMES[0]); User model = new User(); Domain domain = new Domain(); domain.setName(DOMAIN); domain.setId(DirectoryEntryIdUtils.encode(domain.getName())); model.setDomain(domain); model.setUserName(NAMES[0]); Response response = collection.add(model); verifyAddUser(response); }
@Test public void testAddUser4() { setUpEntityQueryExpectations(QueryType.GetDomainList, QueryParametersBase.class, new String[] { }, new Object[] { }, setUpDomains()); setUpAddUserExpectations("ADUSER@" + DOMAIN + ":: username=" + NAMES[0]); User model = new User(); model.setUserName(NAMES[0]); Domain domain = new Domain(); domain.setName(DOMAIN); domain.setId(DirectoryEntryIdUtils.encode(domain.getName())); model.setDomain(domain); Response response = collection.add(model); verifyAddUser(response); }
@Test public void testUpdateSshHost() { Ssh sshConf = new Ssh(); sshConf.setPort(22); sshConf.setUser(new User()); sshConf.getUser().setUserName("root"); sshConf.setFingerprint("1234"); VdsStatic vdsStatic = new VdsStatic(); vdsStatic.setSshUsername("root"); vdsStatic.setSshPort(22); vdsStatic.setSshKeyFingerprint("1234"); VdsStatic mappedVdsStatic = HostMapper.map(sshConf, vdsStatic); assertEquals(22, mappedVdsStatic.getSshPort()); assertEquals("1234", mappedVdsStatic.getSshKeyFingerprint()); assertEquals("root", mappedVdsStatic.getSshUsername()); }
to.setUserName(from.getUserName());