我使用kerberos rest模板访问kerberized hadoop上的作业历史服务器,但是这段代码给我一个例外:
KerberosRestTemplate kerberosRestTemplate = new KerberosRestTemplate(properties.getProperty("userKeytabPath"),properties.getProperty("userprincipal")); System.out.println(kerberosRestTemplate.getForObject(jobhistoryurl, String.class));
例外:
Exception in thread "main" org.springframework.web.client.RestClientException: Error running rest call; nested exception is org.springframework.web.client.HttpClientErrorException: 401 Authentication required
at org.springframework.security.kerberos.client.KerberosRestTemplate.doExecute(KerberosRestTemplate.java:196)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:530)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:237)
at com.datametica.hiveconnection.hiveconnectioncheck.HivePortCheck.main(HivePortCheck.java:57)
Caused by: org.springframework.web.client.HttpClientErrorException: 401 Authentication required
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:614)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:570)
at org.springframework.security.kerberos.client.KerberosRestTemplate.doExecuteSubject(KerberosRestTemplate.java:202)
at org.springframework.security.kerberos.client.KerberosRestTemplate.access$100(KerberosRestTemplate.java:67)
at org.springframework.security.kerberos.client.KerberosRestTemplate$1.run(KerberosRestTemplate.java:191)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at org.springframework.security.kerberos.client.KerberosRestTemplate.doExecute(KerberosRestTemplate.java:187)
... 3 more
那么我是否需要在请求标头中传递任何额外的参数来访问kerberos secure apis? 在访问此API之前,我已经通过kerberosRestTemplate中提供的相同用户主体和keytab使用hadoop安全性的UserGroupInformation类登录用户。
UserGroupInformation.loginUserFromKeytab(properties.getProperty("userprincipal"),properties.getProperty("userKeytabPath"));
我在访问作业历史记录之前检查了当前用户登录(通过ugi当前用户),并且它正在告诉我该用户已登录并使用kerberos身份验证,但我仍然从作业历史记录服务器获得401状态。