@Override protected void verifyModel(User model, int index) { assertEquals(NAMES[index] + "@" + DOMAIN, model.getUserName()); }
@Override public Response add(User user) { validateParameters(user, "userName"); List<String> authzProvidersNames = getBackendCollection( String.class, QueryType.GetDomainList, new QueryParametersBase()); if (AuthzUtils.getAuthzNameFromEntityName(user.getUserName(), authzProvidersNames) == null) {// user-name may contain the domain (e.g: oliel@xxx.yyy) validateParameters(user, "domain.id|name"); } String domain = getAuthzProviderName(user, authzProvidersNames); DirectoryUser directoryUser = findDirectoryUser(domain, user); if (directoryUser == null) { return Response.status(Status.BAD_REQUEST) .entity("No such user: " + user.getUserName() + " in domain " + domain) .build(); } AddUserParameters parameters = new AddUserParameters(new DbUser(directoryUser)); QueryIdResolver<Guid> resolver = new QueryIdResolver<>(QueryType.GetDbUserByUserId, IdQueryParameters.class); return performCreate(ActionType.AddUser, parameters, resolver, BaseResource.class); }
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); }
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."); } }
@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); }
@Test public void testMapSessions() { org.ovirt.engine.core.common.businessentities.VM vm = new org.ovirt.engine.core.common.businessentities.VM(); VmDynamic vmDynamic = new VmDynamic(); vmDynamic.setConsoleCurrentUserName("admin"); vmDynamic.setClientIp("1.1.1.1"); vmDynamic.setGuestCurrentUserName("Ori"); vm.setDynamicData(vmDynamic); Sessions sessions = VmMapper.map(vm, new Sessions()); assertNotNull(sessions); assertEquals(2, sessions.getSessions().size()); Session consoleSession = sessions.getSessions().get(0).getUser().getUserName().equals("admin") ? sessions.getSessions().get(0) : sessions.getSessions().get(1); Session guestSession = sessions.getSessions().get(0).getUser().getUserName().equals("Ori") ? sessions.getSessions().get(0) : sessions.getSessions().get(1); assertEquals("admin", consoleSession.getUser().getUserName()); assertEquals("1.1.1.1", consoleSession.getIp().getAddress()); assertTrue(consoleSession.isConsoleUser()); assertEquals("Ori", guestSession.getUser().getUserName()); } }
@Mapping(from = Ssh.class, to = VdsStatic.class) public static VdsStatic map(Ssh model, VdsStatic template) { VdsStatic entity = template != null ? template : new VdsStatic(); if (model.isSetUser() && model.getUser().isSetUserName()) { entity.setSshUsername(model.getUser().getUserName()); } if (model.isSetPort() && model.getPort() > 0) { entity.setSshPort(model.getPort()); } if (model.isSetFingerprint()) { entity.setSshKeyFingerprint(model.getFingerprint()); } return entity; }
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."); }
/** * 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; }
String userName = user.getUserName(); if (StringUtils.equals(userName, "root")) { entity.setUserName(userName);
QueryType.GetDbUserByUserNameAndDomain, new GetDbUserByUserNameAndDomainQueryParameters( session.getUser().getUserName(), session.getUser().getDomain().getName() ),
to.setUserName(from.getUserName());
@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; }
params.getvds().setSshUsername(action.getSsh().getUser().getUserName());
if (vm.getDomain().isSetUser()) { if (vm.getDomain().getUser().isSetUserName()) { params.setSysPrepUserName(vm.getDomain().getUser().getUserName());