Converts a user entity to DTO.

@param   user  The entity to convert.

@return  The DTO.

@throws  WebApplicationException  If an error occurs.
545152
public static PrincipalUserDto transformToDto(PrincipalUser user) {
        if (user == null) {
            throw new WebApplicationException("Null entity object cannot be converted to Dto object.", Status.INTERNAL_SERVER_ERROR);
        }

        PrincipalUserDto result = createDtoObject(PrincipalUserDto.class, user);

        for (Dashboard dashboard : user.getOwnedDashboards()) {
            result.addOwnedDashboardId(dashboard.getId());
        }
        return result;
    }
288516
@Override
    public IUserInstance getUserInstance(HttpServletRequest request) throws PortalException {
        try {
            request = this.portalRequestUtils.getOriginalPortalRequest(request);
        } catch (IllegalArgumentException iae) {
            // ignore, just means that this isn't a wrapped request
        }

        // Use request attributes first for the fastest possible retrieval
        IUserInstance userInstance = (IUserInstance) request.getAttribute(KEY);
        if (userInstance != null) {
            return userInstance;
        }

        final IPerson person;
        try {
            // Retrieve the person object that is associated with the request
            person = this.personManager.getPerson(request);
        } catch (Exception e) {
            logger.error("Exception while retrieving IPerson!", e);
            throw new PortalSecurityException("Could not retrieve IPerson", e);
        }

        if (person == null) {
            throw new PortalSecurityException(
                    "PersonManager returned null person for this request.  With no user, there's no UserInstance.  Is PersonManager misconfigured?  RDBMS access misconfigured?");
        }

        final HttpSession session = request.getSession();
        if (session == null) {
            throw new IllegalStateException(
                    "HttpServletRequest.getSession() returned a null session for request: "
                            + request);
        }

        // Return the UserInstance object if it's in the session
        UserInstanceHolder userInstanceHolder = getUserInstanceHolder(session);
        if (userInstanceHolder != null) {
            userInstance = userInstanceHolder.getUserInstance();

            if (userInstance != null) {
                return userInstance;
            }
        }

        // Create either a UserInstance or a GuestUserInstance
        final LocaleManager localeManager = this.getLocaleManager(request, person);
        final String userAgent = this.getUserAgent(request);
        final IUserProfile userProfile =
                this.getUserProfile(request, person, localeManager, userAgent);

        // Create the user layout manager and user instance object
        IUserLayoutManager userLayoutManager =
                userLayoutManagerFactory.getUserLayoutManager(person, userProfile);

        final UserPreferencesManager userPreferencesManager =
                new UserPreferencesManager(person, userProfile, userLayoutManager);
        userInstance = new UserInstance(person, userPreferencesManager, localeManager);

        // Ensure the newly created UserInstance is cached in the session
        if (userInstanceHolder == null) {
            userInstanceHolder = new UserInstanceHolder();
        }
        userInstanceHolder.setUserInstance(userInstance);
        session.setAttribute(KEY, userInstanceHolder);
        request.setAttribute(KEY, userInstance);

        // Return the new UserInstance
        return userInstance;
    }
429075
public LdapUser updateLdapUser(final LdapUser transientUser) {
        final LdapUser user = getObjectById(LdapUser.class, transientUser.getId());
        pm.currentTransaction().begin();
        user.setDN(transientUser.getDN());
        pm.currentTransaction().commit();
        return pm.getObjectById(LdapUser.class, user.getId());
    }
71060
public static AVIMClient getInstance(AVUser user) {
    if (null == user) {
      return null;
    }
    String clientId = user.getObjectId();
    String sessionToken = user.getSessionToken();
    if (StringUtil.isEmpty(clientId) || StringUtil.isEmpty(sessionToken)) {
      return null;
    }
    AVIMClient client = getInstance(clientId);
    client.userSessionToken = sessionToken;
    return client;
  }
866053
protected UserAction getUserAction(User user, String path, Object content, Map<String,String> headers) {
        Action action = getAction(path, content, headers);
        Entity entity = getEntity(path, content, headers);
        Long entityId = getEntityId(path, content, headers);
        String descrip = getEntityDescription(path, content, headers);
        if (descrip.length() > 1000)
            descrip = descrip.substring(0, 999);
        UserAction userAction = new UserAction(user.getCuid(), action, entity, entityId, descrip);
        userAction.setSource(getSource());
        return userAction;
    }
694866
@POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Description("Creates a new namepsace.")
    public NamespaceDto createNamespace(@Context HttpServletRequest req, NamespaceDto namespaceDto) {
        if (namespaceDto == null) {
            throw new WebApplicationException("Null namespace object cannot be created.", Status.BAD_REQUEST);
        }

        PrincipalUser remoteUser = validateAndGetOwner(req, null);
        Set<PrincipalUser> users = _getPrincipalUserByUserName(namespaceDto.getUsernames());
        Namespace namespace = new Namespace(remoteUser, namespaceDto.getQualifier(), remoteUser, users);

        return NamespaceDto.transformToDto(_namespaceService.createNamespace(namespace));
    }
555234
@Programmatic
    public List<PublishedEvent> findRecentByUser(final String user) {
        return repositoryService.allMatches(
                new QueryDefault<>(PublishedEvent.class, "findRecentByUser", "user", user));

    }
337377
public static AnnotationDto transformToDto(Annotation annotation) {
        if (annotation == null) {
            throw new WebApplicationException("Null entity object cannot be converted to Dto object.", Status.INTERNAL_SERVER_ERROR);
        }

        AnnotationDto result = createDtoObject(AnnotationDto.class, annotation);

        return result;
    }
974478
public static SignedJWT generateJWToken(User user, App app) {
		if (app != null) {
			try {
				Date now = new Date();
				JWTClaimsSet.Builder claimsSet = new JWTClaimsSet.Builder();
				String userSecret = "";
				claimsSet.issueTime(now);
				claimsSet.expirationTime(new Date(now.getTime() + (app.getTokenValiditySec() * 1000)));
				claimsSet.notBeforeTime(now);
				claimsSet.claim("refresh", getNextRefresh(app.getTokenValiditySec()));
				claimsSet.claim(Config._APPID, app.getId());
				if (user != null) {
					claimsSet.subject(user.getId());
					userSecret = user.getTokenSecret();
				}
				JWSSigner signer = new MACSigner(app.getSecret() + userSecret);
				SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), claimsSet.build());
				signedJWT.sign(signer);
				return signedJWT;
			} catch (JOSEException e) {
				logger.warn("Unable to sign JWT: {}.", e.getMessage());
			}
		}
		return null;
	}
392516
protected String userTenancyPathForCached(final ApplicationUser applicationUser) {
        return queryResultsCache.execute(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return userTenancyPathFor(applicationUser);
            }
        }, TenantedAuthorizationFacetDefault.class, "userTenancyPathFor", applicationUser);
    }
1134975
private UserInterface fromUser(User user) {
        return new UserInterface(user.getId(), user.getUsername(), user.getIpAddress(),
            user.getEmail(), user.getData());
    }
381356
@GetMapping("/user")
  public ResponseEntity<User> getUser(
      @VersionApi int version, //<1>
      @RequestParam("id") String id) {
    throw new UnsupportedOperationException();
  }
305106
@Transactional
	public OAuthSessionContextEntity create(final UserEntity user, final OAuthServiceEntity service, final String scope)
	{
		// Create a new context
		OAuthSessionContextEntity entity = get(user.getId(), service.getId(), scope);

		// No active context exists, we must create one
		if (entity == null)
		{
			entity = new OAuthSessionContextEntity();

			entity.setUser(user);
			entity.setScope(StringUtils.trimToEmpty(scope));
			entity.setService(service);
			entity.setActive(true);

			entity.setId(save(entity));
		}

		return entity;
	}
313407
private void authorize(HttpSession session, Action action, Entity entity, String location)
            throws AuthorizationException, DataAccessException {
        AuthenticatedUser user  = (AuthenticatedUser)session.getAttribute("authenticatedUser");
        if (user == null && ApplicationContext.getServiceUser() != null) {
            String cuid = ApplicationContext.getServiceUser();
            user = new AuthenticatedUser(UserGroupCache.getUser(cuid));
        }

        if (user == null)
            throw new AuthorizationException(AuthorizationException.NOT_AUTHORIZED, "Authentication failure");
        if (action == Action.Create || action == Action.Delete) {
            if (!user.hasRole(Role.PROCESS_EXECUTION)) {
                throw new AuthorizationException(AuthorizationException.FORBIDDEN, "User "
                        + user.getCuid() + " not authorized for " + action + " on " + location);
            }
            logger.info("Asset mod request received from user: " + user.getCuid() + " for: " + location);
            UserAction userAction = new UserAction(user.getCuid(), action, entity, 0L, location);
            userAction.setSource(getClass().getSimpleName());
            ServiceLocator.getUserServices().auditLog(userAction);
        }
    }
1360097
public static List<NamespaceDto> transformToDto(List<Namespace> namespaces) {
        if (namespaces == null) {
            throw new WebApplicationException("Null entity object cannot be converted to Dto object.", Status.INTERNAL_SERVER_ERROR);
        }

        List<NamespaceDto> result = new ArrayList<>();

        for (Namespace namespace : namespaces) {
            result.add(transformToDto(namespace));
        }
        return result;
    }
1231691
public void setUser(User user) {
		this.user = user;
		if (httpSender != null) {
			httpSender.setUser(user);
		}
	}
149047
public Response createUser(UserEntity userEntity) {
		return restClient.post("users", userEntity, new HashMap<String, String>());
	}