@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; }
@Override public V3User adapt(User from) { V3User to = new V3User(); if (from.isSetLinks()) { to.getLinks().addAll(adaptOut(from.getLinks())); if (from.isSetActions()) { to.setActions(adaptOut(from.getActions())); if (from.isSetComment()) { to.setComment(from.getComment()); if (from.isSetDepartment()) { to.setDepartment(from.getDepartment()); if (from.isSetDescription()) { to.setDescription(from.getDescription()); if (from.isSetDomain()) { to.setDomain(adaptOut(from.getDomain())); if (from.isSetDomainEntryId()) { to.setDomainEntryId(from.getDomainEntryId()); if (from.isSetEmail()) { to.setEmail(from.getEmail()); if (from.isSetGroups()) { to.setGroups(new V3Groups()); to.getGroups().getGroups().addAll(adaptOut(from.getGroups().getGroups()));
public static void validateAdd(User user) { if (user == null) { throw new ValidationException("Parameter 'user' is mandatory but was not provided."); } if (user.getUserName()==null) { throw new ValidationException("Parameter 'user.user_name' is mandatory but was not provided."); } if ( (user.getDomain()==null || user.getDomain().getId()==null) && (user.getDomain()==null || user.getDomain().getName()==null) ) { throw new ValidationException("Parameters 'user.domain.id' or 'user.domain.name' are mandatory but both were not provided."); } }
/** * Find the directory user that corresponds to the given model. * * @param directoryName the name of the directory where to perform the search * @param user the user model * @return the requested directory group or {@code null} if no such group exists */ private DirectoryUser findDirectoryUser(String directoryName, User user) { DirectoryUser result = null; String namespace = user.getNamespace(); if (user.isSetDomainEntryId()) { result = getUserById(directoryName, namespace, user.getDomainEntryId()); } else if (user.isSetId()) { result = getUserById(directoryName, namespace, user.getId()); } else if (user.isSetPrincipal()) { result = getEntity(DirectoryUser.class, QueryType.GetDirectoryUserByPrincipal, new GetDirectoryUserByPrincipalParameters(directoryName, user.getPrincipal()), user.getPrincipal()); } else if (user.isSetUserName()) { result = getEntity( DirectoryUser.class, SearchType.DirectoryUser, getDirectoryUserSearchPattern( AuthzUtils.getEntityNameWithoutAuthz(user.getUserName(), directoryName), user.getNamespace(), directoryName) ); } return result; }
@Override public User adapt(V3User from) { User to = new User(); if (from.isSetLinks()) { to.getLinks().addAll(adaptIn(from.getLinks())); to.setActions(adaptIn(from.getActions())); to.setComment(from.getComment()); to.setDepartment(from.getDepartment()); to.setDescription(from.getDescription()); to.setDomain(adaptIn(from.getDomain())); to.setDomainEntryId(from.getDomainEntryId()); to.setEmail(from.getEmail()); to.setGroups(new Groups()); to.getGroups().getGroups().addAll(adaptIn(from.getGroups().getGroups())); to.setId(from.getId()); to.setHref(from.getHref()); to.setLastName(from.getLastName()); to.setLoggedIn(from.isLoggedIn());
@Mapping(from = User.class, to = DbUser.class) public static DbUser map(User model, DbUser template) { DbUser entity = template != null? template: new DbUser(); if (model.isSetPrincipal()) { entity.setLoginName(model.getPrincipal()); } else if (model.isSetName()) { entity.setLoginName(model.getName()); } if (model.isSetId()) { String id = model.getId(); entity.setId(GuidUtils.asGuid(id)); } if (model.isSetDomain()) { Domain domain = model.getDomain(); if (domain.isSetName()) { entity.setDomain(domain.getName()); } } if (model.isSetDomainEntryId()) { entity.setExternalId(DirectoryEntryIdUtils.decode(model.getDomainEntryId())); } if (model.isSetNamespace()) { entity.setNamespace(model.getNamespace()); } return entity; }
String userName = parseUserName(consoleUserName); String domainName = parseDomainName(consoleUserName); User consoleUser = new User(); consoleUser.setUserName(userName); consoleUser.setDomain(new Domain()); consoleUser.getDomain().setName(domainName); if (vm.getConsoleUserId()!=null) { consoleUser.setId(vm.getConsoleUserId().toString());
@Mapping(from = Host.class, to = VdsOperationActionParameters.class) public static VdsOperationActionParameters map(Host host, VdsOperationActionParameters params) { params.setPassword(host.getRootPassword()); if (host.isSetSsh()) { if (host.getSsh().isSetUser()) { if (host.getSsh().getUser().isSetPassword()) { // For backward compatibility giving priority to rootPassword field if (params.getPassword() == null) { params.setPassword(host.getSsh().getUser().getPassword()); } } if (host.getSsh().getUser().isSetUserName()) { params.getvds().setSshUsername(host.getSsh().getUser().getUserName()); } } if (host.getSsh().isSetPort()) { params.getvds().setSshPort(host.getSsh().getPort()); } if (host.getSsh().isSetFingerprint()) { params.getvds().setSshKeyFingerprint(host.getSsh().getFingerprint()); } if (host.getSsh().isSetAuthenticationMethod()) { params.setAuthMethod(mapSshAuthenticationMethod(host.getSsh().getAuthenticationMethod())); } } return params; }
/** * 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; }
@Test public void testCompleteListSubFieldAlternatives() { User user = new User(); user.setRoles(new Roles()); user.getRoles().getRoles().add(new Role()); user.getRoles().getRoles().get(0).setId("0"); user.getRoles().getRoles().add(new Role()); user.getRoles().getRoles().get(1).setName("0"); CompletenessAssertor.validateParameters(user, "roles.id|name"); }
@Override protected void verifyModel(User model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertEquals(NAMES[index] + "@" + DOMAIN, model.getUserName()); assertNotNull(model.getDomain()); assertEquals(DirectoryEntryIdUtils.encode(DOMAIN), model.getDomain().getId()); assertTrue(model.isSetGroups()); assertEquals(PARSED_GROUPS.length, model.getGroups().getGroups().size()); Set<String> groupNames = model.getGroups().getGroups().stream().map(Group::getName).collect(Collectors.toSet()); assertEquals(new HashSet<>(Arrays.asList(PARSED_GROUPS)), groupNames); verifyLinks(model); }
QueryType.GetDbUserByUserNameAndDomain, new GetDbUserByUserNameAndDomainQueryParameters( session.getUser().getUserName(), session.getUser().getDomain().getName() ), "", session.getUser().setId(user.getId()); session.getUser().setHref(user.getHref()); session.getUser().getDomain().setId(user.getDomain().getId()); session.getUser().getDomain().setHref(user.getDomain().getHref());
@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); }
protected void verifyModel(User model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertEquals(NAMES[index], model.getName()); assertNotNull(model.getDomain()); assertTrue(model.isSetGroups()); assertEquals(PARSED_GROUPS.length, model.getGroups().getGroups().size()); Set<String> groupNames = model.getGroups().getGroups().stream().map(Group::getName).collect(Collectors.toSet()); assertEquals(new HashSet<>(Arrays.asList(PARSED_GROUPS)), groupNames); verifyLinks(model); } }
protected String getAuthzProviderName(User user, Collection<String> authzProvidersNames) { if (user.isSetDomain() && user.getDomain().isSetName()) { return user.getDomain().getName(); } else if (user.isSetDomain() && user.getDomain().isSetId()) { for (String domain : authzProvidersNames) { Guid domainId = asGuid(domain.getBytes(StandardCharsets.UTF_8)); if (domainId.toString().equals(user.getDomain().getId())) { return domain; } } throw new WebFaultException(null, "Domain: '" + user.getDomain().getId().toString() + "' does not exist.", Response.Status.BAD_REQUEST); } return AuthzUtils.getAuthzNameFromEntityName(user.getUserName(), authzProvidersNames); }
@Override public Permission addParents(Permission permission) { // REVISIT for entity-level permissions we need an isUser // flag on the permissions entity in order to distinguish // between the user and group cases if (isGroupSubCollection() && permission.isSetUser() && permission.getUser().isSetId()) { permission.setGroup(new Group()); permission.getGroup().setId(permission.getUser().getId()); permission.setUser(null); } return permission; }
public static Method getApproveSignature(Action action) throws NoSuchMethodException, SecurityException { if (action == null) { throw new ValidationException("Action is mandatory but was not provided."); } /** * using_root_password */ if (action!=null && action.getHost()!=null && action.getHost().getRootPassword()!=null ) { return HostResource.class.getMethod("approveUsingRootPassword", Action.class); } /** * using_ssh */ if (action!=null && action.getHost()!=null && action.getHost().getSsh()!=null && action.getHost().getSsh().getUser()!=null && action.getHost().getSsh().getUser().getUserName()!=null && action.getHost()!=null && action.getHost().getSsh()!=null && action.getHost().getSsh().getUser()!=null && action.getHost().getSsh().getUser().getPassword()!=null && action.getHost()!=null && action.getHost().getSsh()!=null && action.getHost().getSsh().getAuthenticationMethod()!=null ) { return HostResource.class.getMethod("approveUsingSsh", Action.class); } throw new ValidationException("No matching signature found, make sure that mandatory attributes are provided."); }