YARN-6989 Ensure timeline service v2 codebase gets UGI from HttpServletRequest in a consistent way. Contributed by Abhishek Modi
This commit is contained in:
parent
cc1bf7f894
commit
7a5d27dde4
@ -269,25 +269,8 @@ static String parseStr(String str) {
|
|||||||
* @return UGI.
|
* @return UGI.
|
||||||
*/
|
*/
|
||||||
public static UserGroupInformation getUser(HttpServletRequest req) {
|
public static UserGroupInformation getUser(HttpServletRequest req) {
|
||||||
return getCallerUserGroupInformation(req, false);
|
Principal princ = req.getUserPrincipal();
|
||||||
}
|
String remoteUser = princ == null ? null : princ.getName();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get UGI from the HTTP request.
|
|
||||||
*
|
|
||||||
* @param hsr HTTP request.
|
|
||||||
* @param usePrincipal if true, use principal name else use remote user name
|
|
||||||
* @return UGI.
|
|
||||||
*/
|
|
||||||
public static UserGroupInformation getCallerUserGroupInformation(
|
|
||||||
HttpServletRequest hsr, boolean usePrincipal) {
|
|
||||||
|
|
||||||
String remoteUser = hsr.getRemoteUser();
|
|
||||||
if (usePrincipal) {
|
|
||||||
Principal princ = hsr.getUserPrincipal();
|
|
||||||
remoteUser = princ == null ? null : princ.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserGroupInformation callerUGI = null;
|
UserGroupInformation callerUGI = null;
|
||||||
if (remoteUser != null) {
|
if (remoteUser != null) {
|
||||||
callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
|
callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
|
||||||
|
@ -67,7 +67,7 @@ public void doFilter(ServletRequest request, ServletResponse response,
|
|||||||
|
|
||||||
if (isWhitelistReadAuthEnabled) {
|
if (isWhitelistReadAuthEnabled) {
|
||||||
UserGroupInformation callerUGI = TimelineReaderWebServicesUtils
|
UserGroupInformation callerUGI = TimelineReaderWebServicesUtils
|
||||||
.getCallerUserGroupInformation(httpRequest, true);
|
.getUser(httpRequest);
|
||||||
if (callerUGI == null) {
|
if (callerUGI == null) {
|
||||||
String msg = "Unable to obtain user name, user not authenticated";
|
String msg = "Unable to obtain user name, user not authenticated";
|
||||||
throw new AuthorizationException(msg);
|
throw new AuthorizationException(msg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user