Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
da7a6a88
Commit
da7a6a88
authored
Mar 30, 2015
by
Jon Maron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BUG-32834 login processor
parent
403c04b3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
37 deletions
+38
-37
GuiceServletConfig.java
...che/hadoop/metadata/web/listeners/GuiceServletConfig.java
+4
-0
LoginProcessor.java
.../apache/hadoop/metadata/web/listeners/LoginProcessor.java
+26
-26
web.xml
webapp/src/main/webapp/WEB-INF/web.xml
+0
-3
LoginProcessorIT.java
...pache/hadoop/metadata/web/listeners/LoginProcessorIT.java
+8
-8
No files found.
webapp/src/main/java/org/apache/hadoop/metadata/web/listeners/GuiceServletConfig.java
View file @
da7a6a88
...
...
@@ -78,6 +78,10 @@ public class GuiceServletConfig extends GuiceServletContextListener {
public
void
contextInitialized
(
ServletContextEvent
servletContextEvent
)
{
super
.
contextInitialized
(
servletContextEvent
);
// perform login operations
LoginProcessor
loginProcessor
=
new
LoginProcessor
();
loginProcessor
.
login
();
restoreTypeSystem
();
}
...
...
webapp/src/main/java/org/apache/hadoop/metadata/web/listeners/Login
Listene
r.java
→
webapp/src/main/java/org/apache/hadoop/metadata/web/listeners/Login
Processo
r.java
View file @
da7a6a88
...
...
@@ -25,34 +25,26 @@ import org.apache.hadoop.util.Shell;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.servlet.ServletContextEvent
;
import
javax.servlet.ServletContextListener
;
import
java.io.IOException
;
import
java.net.InetAddress
;
/**
* A
listener
capable of performing a simple or kerberos login.
* A
class
capable of performing a simple or kerberos login.
*/
public
class
Login
Listener
implements
ServletContextListener
{
public
class
Login
Processor
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
LoginListener
.
class
);
public
static
final
String
AUTHENTICATION_METHOD
=
"authentication.method"
;
public
static
final
String
AUTHENTICATION_PRINCIPAL
=
"authentication.principal"
;
public
static
final
String
AUTHENTICATION_KEYTAB
=
"authentication.keytab"
;
@Override
public
void
contextDestroyed
(
ServletContextEvent
servletContextEvent
)
{
}
.
getLogger
(
LoginProcessor
.
class
);
public
static
final
String
METADATA_AUTHENTICATION_PREFIX
=
"metadata.authentication."
;
public
static
final
String
AUTHENTICATION_METHOD
=
METADATA_AUTHENTICATION_PREFIX
+
"method"
;
public
static
final
String
AUTHENTICATION_PRINCIPAL
=
METADATA_AUTHENTICATION_PREFIX
+
"principal"
;
public
static
final
String
AUTHENTICATION_KEYTAB
=
METADATA_AUTHENTICATION_PREFIX
+
"keytab"
;
/**
* Perform a SIMPLE login based on established OS identity or a kerberos based login using the configured
* principal and keytab (via application.properties).
* @param servletContextEvent
*/
@Override
public
void
contextInitialized
(
ServletContextEvent
servletContextEvent
)
{
public
void
login
()
{
// first, let's see if we're running in a hadoop cluster and have the env configured
boolean
isHadoopCluster
=
isHadoopCluster
();
Configuration
hadoopConfig
=
isHadoopCluster
?
getHadoopConfiguration
()
:
new
Configuration
(
false
);
...
...
@@ -64,17 +56,12 @@ public class LoginListener implements ServletContextListener {
}
if
(!
isHadoopCluster
)
{
// need to read the configured authentication choice and create the UGI configuration
String
authMethod
;
authMethod
=
configuration
!=
null
?
configuration
.
getString
(
AUTHENTICATION_METHOD
)
:
null
;
// getString may return null, and would like to log the nature of the default setting
if
(
authMethod
==
null
)
{
LOG
.
info
(
"No authentication method configured. Defaulting to simple authentication"
);
authMethod
=
"simple"
;
}
SecurityUtil
.
setAuthenticationMethod
(
UserGroupInformation
.
AuthenticationMethod
.
valueOf
(
authMethod
.
toUpperCase
()),
hadoopConfig
);
setupHadoopConfiguration
(
hadoopConfig
,
configuration
);
}
doServiceLogin
(
hadoopConfig
,
configuration
);
}
protected
void
doServiceLogin
(
Configuration
hadoopConfig
,
PropertiesConfiguration
configuration
)
{
UserGroupInformation
.
setConfiguration
(
hadoopConfig
);
UserGroupInformation
ugi
=
null
;
...
...
@@ -95,6 +82,19 @@ public class LoginListener implements ServletContextListener {
}
}
protected
void
setupHadoopConfiguration
(
Configuration
hadoopConfig
,
PropertiesConfiguration
configuration
)
{
String
authMethod
;
authMethod
=
configuration
!=
null
?
configuration
.
getString
(
AUTHENTICATION_METHOD
)
:
null
;
// getString may return null, and would like to log the nature of the default setting
if
(
authMethod
==
null
)
{
LOG
.
info
(
"No authentication method configured. Defaulting to simple authentication"
);
authMethod
=
"simple"
;
}
SecurityUtil
.
setAuthenticationMethod
(
UserGroupInformation
.
AuthenticationMethod
.
valueOf
(
authMethod
.
toUpperCase
()),
hadoopConfig
);
}
/**
* Return a server (service) principal. The token "_HOST" in the principal will be replaced with the local host
* name (e.g. dgi/_HOST will be changed to dgi/localHostName)
...
...
webapp/src/main/webapp/WEB-INF/web.xml
View file @
da7a6a88
...
...
@@ -48,9 +48,6 @@
</filter-mapping>
<listener>
<listener-class>
org.apache.hadoop.metadata.web.listeners.LoginListener
</listener-class>
</listener>
<listener>
<listener-class>
org.apache.hadoop.metadata.web.listeners.GuiceServletConfig
</listener-class>
</listener>
</web-app>
webapp/src/test/java/org/apache/hadoop/metadata/web/listeners/Login
Listene
rIT.java
→
webapp/src/test/java/org/apache/hadoop/metadata/web/listeners/Login
Processo
rIT.java
View file @
da7a6a88
...
...
@@ -35,7 +35,7 @@ import java.util.Properties;
/**
*
*/
public
class
Login
Listene
rIT
{
public
class
Login
Processo
rIT
{
private
static
final
String
JAAS_ENTRY
=
"%s { \n"
...
...
@@ -56,13 +56,13 @@ public class LoginListenerIT {
@Test
public
void
testDefaultSimpleLogin
()
throws
Exception
{
Login
Listener
listener
=
new
LoginListene
r
()
{
Login
Processor
processor
=
new
LoginProcesso
r
()
{
@Override
protected
PropertiesConfiguration
getPropertiesConfiguration
()
throws
ConfigurationException
{
return
new
PropertiesConfiguration
();
}
};
listener
.
contextInitialized
(
null
);
processor
.
login
(
);
assert
UserGroupInformation
.
getCurrentUser
()
!=
null
;
assert
!
UserGroupInformation
.
isLoginKeytabBased
();
...
...
@@ -73,13 +73,13 @@ public class LoginListenerIT {
public
void
testKerberosLogin
()
throws
Exception
{
final
File
keytab
=
setupKDCAndPrincipals
();
Login
Listener
listener
=
new
LoginListene
r
()
{
Login
Processor
processor
=
new
LoginProcesso
r
()
{
@Override
protected
PropertiesConfiguration
getPropertiesConfiguration
()
throws
ConfigurationException
{
PropertiesConfiguration
config
=
new
PropertiesConfiguration
();
config
.
setProperty
(
"authentication.method"
,
"kerberos"
);
config
.
setProperty
(
"authentication.principal"
,
"dgi@EXAMPLE.COM"
);
config
.
setProperty
(
"authentication.keytab"
,
keytab
.
getAbsolutePath
());
config
.
setProperty
(
"
metadata.
authentication.method"
,
"kerberos"
);
config
.
setProperty
(
"
metadata.
authentication.principal"
,
"dgi@EXAMPLE.COM"
);
config
.
setProperty
(
"
metadata.
authentication.keytab"
,
keytab
.
getAbsolutePath
());
return
config
;
}
...
...
@@ -98,7 +98,7 @@ public class LoginListenerIT {
return
true
;
}
};
listener
.
contextInitialized
(
null
);
processor
.
login
(
);
assert
UserGroupInformation
.
getLoginUser
().
getShortUserName
().
endsWith
(
"dgi"
);
assert
UserGroupInformation
.
getCurrentUser
()
!=
null
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment