mgaido91 commented on a change in pull request #141: [LIVY-551] Add "doAs" impersonation support URL: https://github.com/apache/incubator-livy/pull/141#discussion_r252153677
########## File path: server/src/main/scala/org/apache/livy/server/SessionServlet.scala ########## @@ -156,9 +156,29 @@ abstract class SessionServlet[S <: Session, R <: RecoveryMetadata]( } /** - * Returns the remote user for the given request. Separate method so that tests can override it. - */ - protected def remoteUser(req: HttpServletRequest): String = req.getRemoteUser() + * Returns the remote user for the given request. Separate method so that tests can override it. + */ + protected def remoteUser(req: HttpServletRequest): String = req.getRemoteUser + + protected def impersonatedUser(request: HttpServletRequest): Option[String] = { + val impersonatedUser = Option(request.getParameter("doAs")) + impersonatedUser.filter(accessManager.checkImpersonation(remoteUser(request), _)) + } + + /** + * Returns the proxy user as determined by the json request body or owner if available. + * This is necessary to preserve backwards compatibility prior to "doAs" impersonation. + */ + protected def legacyProxyUser(owner: String, bodyProxyUser: Option[String]): Option[String] = { + bodyProxyUser.filter(accessManager.checkImpersonation(owner, _)).orElse(Option(owner)) + } + + /** + * Gets the request user or impersonated user to determine the effective user Review comment: ditto ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services