자바 코드 구현 kerbeos 인증 hive 연결

1491 단어 자바
자바 코드 구현 kerbeos 인증 hive 연결
hive 데이터 베 이 스 는 my sql 과 달리 인증 파일 두 개가 있어 야 로그 인 할 수 있 습 니 다.Hive.keytab 및 krb 5.conf
1.페이지 에서 두 개의 파일 을 전달 합 니 다.여기 서 base 64 로 전달 합 니 다.(두 개의 파일 이 크 지 않 은 것 을 고려 하여 이러한 방식 으로 base 64 가 파일 을 인 코딩 할 때 접두사 가 나타 나 므 로 디 코딩 할 때 절단 에 주의해 야 합 니 다)
2.프론트 엔 드 에서 두 개의 파일 을 전달 하여 사용자 정의 주 소 를 디 코딩 하고 읽 습 니 다.
3.자바 코드 로 연결 가 져 오기
Connection con = null; //          
System.setProperty("java.security.krb5.conf", "krb5.conf         ");

            Configuration configuration = new Configuration();
            configuration.set("hadoop.security.authentication" , "Kerberos" );
            UserGroupInformation.setConfiguration(configuration);
            try {
                UserGroupInformation userGroupInformation = UserGroupInformation.loginUserFromKeytabAndReturnUGI("   ", "hive.keytab      ");
                try {
                    con = userGroupInformation.doAs((PrivilegedExceptionAction) () -> {
                        Connection connection = null;
                        connection = DriverManager.getConnection(dsConfig.getDsUrl());
                        return connection;
                    });
                    return con;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
 
            } catch (IOException e) {
                e.printStackTrace();
            }

좋은 웹페이지 즐겨찾기