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
d7a139e1
Commit
d7a139e1
authored
May 03, 2017
by
nixonrodrigues
Committed by
Madhan Neethiraj
May 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1767: Support KNOX SSO Token based authentication on Atlas REST API calls
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
a0bb4638
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
7 deletions
+18
-7
AtlasKnoxSSOAuthenticationFilter.java
...e/atlas/web/filters/AtlasKnoxSSOAuthenticationFilter.java
+18
-7
No files found.
webapp/src/main/java/org/apache/atlas/web/filters/AtlasKnoxSSOAuthenticationFilter.java
View file @
d7a139e1
...
@@ -28,6 +28,7 @@ import com.nimbusds.jose.crypto.RSASSAVerifier;
...
@@ -28,6 +28,7 @@ import com.nimbusds.jose.crypto.RSASSAVerifier;
import
com.nimbusds.jwt.SignedJWT
;
import
com.nimbusds.jwt.SignedJWT
;
import
org.apache.atlas.ApplicationProperties
;
import
org.apache.atlas.ApplicationProperties
;
import
org.apache.atlas.web.security.AtlasAuthenticationProvider
;
import
org.apache.atlas.web.security.AtlasAuthenticationProvider
;
import
org.apache.atlas.web.util.Servlets
;
import
org.apache.commons.configuration.Configuration
;
import
org.apache.commons.configuration.Configuration
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.json.simple.JSONObject
;
import
org.json.simple.JSONObject
;
...
@@ -57,6 +58,7 @@ import java.security.interfaces.RSAPublicKey;
...
@@ -57,6 +58,7 @@ import java.security.interfaces.RSAPublicKey;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
org.apache.commons.lang.StringUtils
;
public
class
AtlasKnoxSSOAuthenticationFilter
implements
Filter
{
public
class
AtlasKnoxSSOAuthenticationFilter
implements
Filter
{
...
@@ -69,6 +71,7 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
...
@@ -69,6 +71,7 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
public
static
final
String
JWT_ORIGINAL_URL_QUERY_PARAM
=
"atlas.sso.knox.query.param.originalurl"
;
public
static
final
String
JWT_ORIGINAL_URL_QUERY_PARAM
=
"atlas.sso.knox.query.param.originalurl"
;
public
static
final
String
JWT_COOKIE_NAME_DEFAULT
=
"hadoop-jwt"
;
public
static
final
String
JWT_COOKIE_NAME_DEFAULT
=
"hadoop-jwt"
;
public
static
final
String
JWT_ORIGINAL_URL_QUERY_PARAM_DEFAULT
=
"originalUrl"
;
public
static
final
String
JWT_ORIGINAL_URL_QUERY_PARAM_DEFAULT
=
"originalUrl"
;
public
static
final
String
DEFAULT_BROWSER_USERAGENT
=
"Mozilla,Opera,Chrome"
;
private
SSOAuthenticationProperties
jwtProperties
;
private
SSOAuthenticationProperties
jwtProperties
;
...
@@ -134,7 +137,7 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
...
@@ -134,7 +137,7 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
return
;
return
;
}
}
if
(
!
isWebUserAgent
(
httpRequest
.
getHeader
(
"User-Agent"
))
||
jwtProperties
==
null
||
isAuthenticated
())
{
if
(
jwtProperties
==
null
||
isAuthenticated
())
{
filterChain
.
doFilter
(
servletRequest
,
servletResponse
);
filterChain
.
doFilter
(
servletRequest
,
servletResponse
);
return
;
return
;
}
}
...
@@ -171,18 +174,24 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
...
@@ -171,18 +174,24 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
filterChain
.
doFilter
(
servletRequest
,
httpServletResponse
);
filterChain
.
doFilter
(
servletRequest
,
httpServletResponse
);
}
else
{
// if the token is not valid then redirect to knox sso
}
else
{
// if the token is not valid then redirect to knox sso
redirectToKnox
(
httpRequest
,
httpServletResponse
);
redirectToKnox
(
httpRequest
,
httpServletResponse
,
filterChain
);
}
}
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
LOG
.
warn
(
"Unable to parse the JWT token"
,
e
);
LOG
.
warn
(
"Unable to parse the JWT token"
,
e
);
redirectToKnox
(
httpRequest
,
httpServletResponse
,
filterChain
);
}
}
}
else
{
}
else
{
redirectToKnox
(
httpRequest
,
httpServletResponse
);
redirectToKnox
(
httpRequest
,
httpServletResponse
,
filterChain
);
}
}
}
}
private
void
redirectToKnox
(
HttpServletRequest
httpRequest
,
HttpServletResponse
httpServletResponse
)
throws
IOException
{
private
void
redirectToKnox
(
HttpServletRequest
httpRequest
,
HttpServletResponse
httpServletResponse
,
FilterChain
filterChain
)
throws
IOException
,
ServletException
{
if
(!
isWebUserAgent
(
httpRequest
.
getHeader
(
"User-Agent"
)))
{
filterChain
.
doFilter
(
httpRequest
,
httpServletResponse
);
return
;
}
String
ajaxRequestHeader
=
httpRequest
.
getHeader
(
"X-Requested-With"
);
String
ajaxRequestHeader
=
httpRequest
.
getHeader
(
"X-Requested-With"
);
...
@@ -403,9 +412,11 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
...
@@ -403,9 +412,11 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
jwtProperties
.
setAuthenticationProviderUrl
(
providerUrl
);
jwtProperties
.
setAuthenticationProviderUrl
(
providerUrl
);
jwtProperties
.
setCookieName
(
configuration
.
getString
(
JWT_COOKIE_NAME
,
JWT_COOKIE_NAME_DEFAULT
));
jwtProperties
.
setCookieName
(
configuration
.
getString
(
JWT_COOKIE_NAME
,
JWT_COOKIE_NAME_DEFAULT
));
jwtProperties
.
setOriginalUrlQueryParam
(
configuration
.
getString
(
JWT_ORIGINAL_URL_QUERY_PARAM
,
JWT_ORIGINAL_URL_QUERY_PARAM_DEFAULT
));
jwtProperties
.
setOriginalUrlQueryParam
(
configuration
.
getString
(
JWT_ORIGINAL_URL_QUERY_PARAM
,
JWT_ORIGINAL_URL_QUERY_PARAM_DEFAULT
));
String
userAgent
=
configuration
.
getString
(
BROWSER_USERAGENT
);
String
[]
userAgent
=
configuration
.
getStringArray
(
BROWSER_USERAGENT
);
if
(
userAgent
!=
null
&&
!
userAgent
.
isEmpty
())
{
if
(
userAgent
!=
null
&&
userAgent
.
length
>
0
)
{
jwtProperties
.
setUserAgentList
(
userAgent
.
split
(
","
));
jwtProperties
.
setUserAgentList
(
userAgent
);
}
else
{
jwtProperties
.
setUserAgentList
(
DEFAULT_BROWSER_USERAGENT
.
split
(
","
));
}
}
try
{
try
{
RSAPublicKey
publicKey
=
parseRSAPublicKey
(
publicKeyPathStr
);
RSAPublicKey
publicKey
=
parseRSAPublicKey
(
publicKeyPathStr
);
...
...
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