CDH 6.2.1实现HUE界面自动登录

6 篇文章 0 订阅

目录

1.通过修改hue界面的前端代码实现hue界面的自动登录

1.需求背景

2.hue登陆界面的前端源代码位置

3.将login.mako修改为如下代码即可

4在url中添加账号密码信息到项目连接里面就可以实现自动登录


1.通过修改hue界面的前端代码实现hue界面的自动登录

1.需求背景

项目需要用到hue界面做impala查询,需要每次点击按钮后跳转到hue登录界面,但是每个访问项目的人都需要登录hue界面很不实际。

2.hue登陆界面的前端源代码位置

/opt/cloudera/parcels/CDH-6.2.1-1.cdh6.2.1.p0.1425774/lib/hue/desktop/core/src/desktop/templates/login.mako

3.将login.mako修改为如下代码即可

需要知道那些地方更改的,可以将自己的login.mako和这个login.mako做代码对比

## Licensed to Cloudera, Inc. under one
## or more contributor license agreements.    See the NOTICE file
## distributed with this work for additional information
## regarding copyright ownership.  Cloudera, Inc. licenses this file
## to you under the Apache License, Version 2.0 (the
## "License"); you may not use this file except in compliance
## with the License.  You may obtain a copy of the License at
##
##       http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

<%!
  from desktop import conf
  from django.utils.translation import ugettext as _
  from desktop.views import commonheader, commonfooter
  from useradmin.hue_password_policy import is_password_policy_enabled, get_password_hint
  from desktop.conf import is_hue4
%>

<%namespace name="hueIcons" file="/hue_icons.mako" />

${ commonheader(_("Welcome to Hue"), "login", user, request, "50px", True, True) | n,unicode }

<link rel="stylesheet" href="${ static('desktop/css/login.css') }">
%if is_hue4():
<link rel="stylesheet" href="${ static('desktop/css/login4.css') }">
%endif

<style type="text/css">
  body {
    background-color: #F8F8F8;
    padding-top: 150px;
  }

  .footer {
    position: fixed;
    bottom: 0;
    background-color: #0B7FAD;
    height: 6px;
    width: 100%;
  }

  select {
    width: 100%;
  }
</style>

%if not is_hue4():
<div class="navigator">
  <div class="pull-right">

  <ul class="nav nav-pills">
    <li><a href="http://gethue.com" target="_blank" title="${_('Go to gethue.com')}" data-rel="navigator-tooltip" data-placement="left"><i class="fa fa-globe"></i></a></li>
  </ul>

  </div>
  <a class="brand pull-left" href="/">
    <svg style="margin-top: 2px; margin-left:8px;width: 60px;height: 16px;display: inline-block;">
      <use xlink:href="#hi-logo"></use>
    </svg>
  </a>
</div>
%endif

<div class="login-container">

  <form method="POST" action="${action}" autocomplete="off">
    ${ csrf_token(request) | n,unicode }

    <div class="logo">
      %if is_hue4():
      <svg style="height: 80px; width: 200px;"><use xlink:href="#hi-logo"></use></svg>
      %else:
      <img src="${ static('desktop/art/hue-login-logo-ellie@2x.png') }" width="70" height="70" alt="${ _('Hue logo') }">
      %endif
    </div>
    <h3>Query. Explore. Repeat.</h3>

    %if 'OIDCBackend' in backend_names:
      <button title="${ _('Single Sign-on') }" class="btn btn-primary" onclick="location.href='/oidc/authenticate/'">${ _('Single Sign-on') }</button>

      <hr class="separator-line"/>
    %endif

    %if first_login_ever:
      <div class="alert alert-info center">
        ${_('Since this is your first time logging in, pick any username and password. Be sure to remember these, as')}
        <strong>${_('they will become your Hue superuser credentials.')}</strong>
        %if is_password_policy_enabled():
        <p>${get_password_hint()}</p>
        %endif
      </div>
    %endif

    <div class="text-input
      %if backend_names == ['OAuthBackend']:
        hide
      %endif
      %if form['username'].errors or (not form['username'].errors and not form['password'].errors and login_errors):
        error
      %endif
    ">
      ${ form['username'] | n,unicode }
    </div>

    ${ form['username'].errors | n,unicode }

    <div class="text-input
      %if 'AllowAllBackend' in backend_names or backend_names == ['OAuthBackend']:
        hide
      %endif
      %if form['password'].errors or (not form['username'].errors and not form['password'].errors and login_errors):
        error
      %endif
    ">
      ${ form['password'] | n,unicode }
    </div>

    ${ form['password'].errors | n,unicode }

    %if active_directory:
    <div
      %if 'server' in form.fields and len(form.fields['server'].choices) == 1:
        class="hide"
      %endif
      >
      %if 'server' in form.fields:
        ${ form['server'] | n,unicode }
      %endif
    </div>
    %endif

    %if 'ImpersonationBackend' in backend_names:
    <div class="text-input">
      ${ form['login_as'] | n,unicode }
    </div>
    %endif

    %if login_errors and not form['username'].errors and not form['password'].errors:
      %if form.errors:
        % for error in form.errors:
         ${ form.errors[error]|unicode,n }
        % endfor
      %endif
    %endif

    %if first_login_ever:
      <input type="submit" class="btn btn-primary" value="${_('Create Account')}"/>
    %else:
      <input type="submit" class="btn btn-primary" value="${_('Sign In')}"/>
    %endif
    <input type="hidden" name="next" value="${next}"/>

  </form>

  %if conf.CUSTOM.LOGIN_SPLASH_HTML.get():
  <div class="alert alert-info" id="login-splash">
    ${ conf.CUSTOM.LOGIN_SPLASH_HTML.get() | n,unicode }
  </div>
  %endif
</div>


<div class="trademark center muted">
  % if conf.CUSTOM.LOGO_SVG.get():
    ${ _('Powered by') } <img src="${ static('desktop/art/hue-login-logo.png') }" width="40" style="vertical-align: middle"  alt="${ _('Hue logo') }"> -
  % endif
  ${ _('Hue and the Hue logo are trademarks of Cloudera, Inc.') }
</div>

%if not is_hue4():
<div class="footer"></div>
%endif

<script>
function GetRequest() {
	var url = location.search; //获取url中"?"符后的字串
	var theRequest = new Object();
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for (var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
};
  $(document).ready(function () {
	  var urlParams = GetRequest();
	  if (urlParams.username) {
	  	$('#id_username').val(urlParams.username)
	  }
	  if (urlParams.password) {
	  	$('#id_password').val(urlParams.password)
	  }
	  if ((urlParams.username || "").length > 0 && (urlParams.password || "").length > 0) {
	  	setTimeout(function() {
	  		$("form").submit()
	  	}, 200)
	  }
    $("form").on("submit", function () {
      window.setTimeout(function () {
        $(".logo").find("img").addClass("waiting");
      }, 1000);
    });

    %if 'AllowAllBackend' in backend_names:
      $('#id_password').val('password');
    %endif

    %if backend_names == ['OAuthBackend']:
      $("input").css({"display": "block", "margin-left": "auto", "margin-right": "auto"});
      $("input").bind('click', function () {
        window.location.replace('/login/oauth/');
        return false;
      });
    %endif

    % if next:
      var $redirect = $('input[name="next"]');
      $redirect.val($redirect.val() + window.location.hash);
    % endif
  });
</script>

${ commonfooter(None, messages) | n,unicode }

4.在url中添加账号密码信息到项目连接里面就可以实现自动登录

http://10.68.9.258:8889/hue/accounts/login?next=/&username=admin&password=admin

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
CDH 6.2.1 是 Cloudera 公司提供的一个大数据处理平台。它包含了各种组件和工具,用于存储、处理和分析大规模的数据。 要安装CDH 6.2.1,首先需要下载安装包。可以从 Cloudera 的官方网站上获得安装包,或者从其他可靠的资源下载。安装包主要包括各个组件的二进制文件、配置文件和文档。 安装CDH 6.2.1之前,需要先安装操作系统和一些依赖软件,如Java等。确保操作系统和依赖软件的版本满足CDH 6.2.1的要求。然后,使用命令行或图形界面工具解压安装包到指定目录。 解压安装包后,需要对各个组件进行配置。可以根据实际需求,修改配置文件来调整组件的行为。配置文件通常保存在安装目录下的conf目录中。在配置文件中,可以设置各组件的参数,如数据存储路径、网络端口等。 配置完成后,可以启动CDH 6.2.1的各个组件。启动命令可以在安装包的文档中找到。启动后,可以通过浏览器访问CDH 6.2.1的管理界面,进行管理和监控。在管理界面中,可以查看集群的状态、添加和删除节点等。 如果需要使用CDH 6.2.1进行数据处理和分析,可以使用提供的工具和API。CDH 6.2.1支持各种数据处理框架,如Hadoop、Spark、Hive等。用户可以根据需要选择合适的工具和API,进行数据处理和分析。 总之,安装CDH 6.2.1需要下载安装包,解压到指定目录,进行配置,启动组件,然后使用工具和API进行数据处理和分析。在安装和使用过程中,可以参考官方文档和社区资源,获得帮助和支持。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值