protected PrincipalUser validateAndGetOwner ( HttpServletRequest req , String ownerName ) { PrincipalUser remoteUser = getRemoteUser ( req ) ; if ( ownerName == null || ownerName . isEmpty ( ) || ownerName . equalsIgnoreCase ( remoteUser . getUserName ( ) ) ) { //If ownerName is not present or if it is present and equal to remote username, then return remoteUser. return remoteUser ; } else if ( remoteUser . isPrivileged ( ) ) { PrincipalUser owner ; owner = userService . findUserByUsername ( ownerName ) ; if ( owner == null ) { throw new WebApplicationException ( ownerName + ": User does not exist." , Status . NOT_FOUND ) ; } else { return owner ; } } throw new WebApplicationException ( Status . FORBIDDEN . getReasonPhrase ( ) , Status . FORBIDDEN ) ; }
Validates the owner name and returns the owner object .