Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xnat-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dhcp
xnat-web
Commits
25963acd
Commit
25963acd
authored
8 years ago
by
Mike McKay
Browse files
Options
Downloads
Patches
Plain Diff
XNAT-4154 Got auth REST call to support alias tokens again.
parent
9f7d0d64
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/nrg/xnat/security/alias/AliasTokenAuthenticationProvider.java
+24
-8
24 additions, 8 deletions
...xnat/security/alias/AliasTokenAuthenticationProvider.java
with
24 additions
and
8 deletions
src/main/java/org/nrg/xnat/security/alias/AliasTokenAuthenticationProvider.java
+
24
−
8
View file @
25963acd
...
@@ -11,13 +11,16 @@
...
@@ -11,13 +11,16 @@
package
org.nrg.xnat.security.alias
;
package
org.nrg.xnat.security.alias
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.nrg.framework.services.ContextService
;
import
org.nrg.xdat.entities.AliasToken
;
import
org.nrg.xdat.entities.AliasToken
;
import
org.nrg.xdat.security.helpers.Users
;
import
org.nrg.xdat.security.helpers.Users
;
import
org.nrg.xdat.services.AliasTokenService
;
import
org.nrg.xdat.services.AliasTokenService
;
import
org.nrg.xdat.services.XdatUserAuthService
;
import
org.nrg.xdat.services.XdatUserAuthService
;
import
org.nrg.xdat.services.impl.hibernate.HibernateAliasTokenService
;
import
org.nrg.xft.security.UserI
;
import
org.nrg.xft.security.UserI
;
import
org.nrg.xnat.security.provider.XnatAuthenticationProvider
;
import
org.nrg.xnat.security.provider.XnatAuthenticationProvider
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.security.authentication.AuthenticationServiceException
;
import
org.springframework.security.authentication.AuthenticationServiceException
;
import
org.springframework.security.authentication.BadCredentialsException
;
import
org.springframework.security.authentication.BadCredentialsException
;
...
@@ -28,8 +31,6 @@ import org.springframework.security.core.AuthenticationException;
...
@@ -28,8 +31,6 @@ import org.springframework.security.core.AuthenticationException;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
javax.inject.Inject
;
public
class
AliasTokenAuthenticationProvider
extends
AbstractUserDetailsAuthenticationProvider
implements
XnatAuthenticationProvider
{
public
class
AliasTokenAuthenticationProvider
extends
AbstractUserDetailsAuthenticationProvider
implements
XnatAuthenticationProvider
{
/**
/**
...
@@ -47,7 +48,7 @@ public class AliasTokenAuthenticationProvider extends AbstractUserDetailsAuthent
...
@@ -47,7 +48,7 @@ public class AliasTokenAuthenticationProvider extends AbstractUserDetailsAuthent
@Override
@Override
public
Authentication
authenticate
(
final
Authentication
authentication
)
throws
AuthenticationException
{
public
Authentication
authenticate
(
final
Authentication
authentication
)
throws
AuthenticationException
{
final
String
alias
=
(
String
)
authentication
.
getPrincipal
();
final
String
alias
=
(
String
)
authentication
.
getPrincipal
();
final
AliasToken
token
=
_a
liasTokenService
.
locateToken
(
alias
);
final
AliasToken
token
=
getA
liasTokenService
()
.
locateToken
(
alias
);
if
(
token
==
null
)
{
if
(
token
==
null
)
{
throw
new
BadCredentialsException
(
"No valid alias token found for alias: "
+
alias
);
throw
new
BadCredentialsException
(
"No valid alias token found for alias: "
+
alias
);
}
}
...
@@ -131,7 +132,7 @@ public class AliasTokenAuthenticationProvider extends AbstractUserDetailsAuthent
...
@@ -131,7 +132,7 @@ public class AliasTokenAuthenticationProvider extends AbstractUserDetailsAuthent
String
alias
=
((
AliasTokenAuthenticationToken
)
authentication
).
getAlias
();
String
alias
=
((
AliasTokenAuthenticationToken
)
authentication
).
getAlias
();
long
secret
=
((
AliasTokenAuthenticationToken
)
authentication
).
getSecret
();
long
secret
=
((
AliasTokenAuthenticationToken
)
authentication
).
getSecret
();
String
userId
=
_a
liasTokenService
.
validateToken
(
alias
,
secret
);
String
userId
=
getA
liasTokenService
()
.
validateToken
(
alias
,
secret
);
if
(
StringUtils
.
isBlank
(
userId
)
||
!
userId
.
equals
(
userDetails
.
getUsername
()))
{
if
(
StringUtils
.
isBlank
(
userId
)
||
!
userId
.
equals
(
userDetails
.
getUsername
()))
{
throw
new
BadCredentialsException
(
"The submitted alias token was invalid: "
+
alias
);
throw
new
BadCredentialsException
(
"The submitted alias token was invalid: "
+
alias
);
}
}
...
@@ -166,7 +167,7 @@ public class AliasTokenAuthenticationProvider extends AbstractUserDetailsAuthent
...
@@ -166,7 +167,7 @@ public class AliasTokenAuthenticationProvider extends AbstractUserDetailsAuthent
*/
*/
@Override
@Override
protected
UserDetails
retrieveUser
(
final
String
username
,
final
UsernamePasswordAuthenticationToken
authentication
)
throws
AuthenticationException
{
protected
UserDetails
retrieveUser
(
final
String
username
,
final
UsernamePasswordAuthenticationToken
authentication
)
throws
AuthenticationException
{
AliasToken
token
=
_a
liasTokenService
.
locateToken
(
username
);
AliasToken
token
=
getA
liasTokenService
()
.
locateToken
(
username
);
if
(
token
==
null
)
{
if
(
token
==
null
)
{
throw
new
UsernameNotFoundException
(
"Unable to locate token with alias: "
+
username
);
throw
new
UsernameNotFoundException
(
"Unable to locate token with alias: "
+
username
);
}
}
...
@@ -175,15 +176,30 @@ public class AliasTokenAuthenticationProvider extends AbstractUserDetailsAuthent
...
@@ -175,15 +176,30 @@ public class AliasTokenAuthenticationProvider extends AbstractUserDetailsAuthent
* The hack is to return the user details for the most recent successful login of the user, as that is likely the provider that was used.
* The hack is to return the user details for the most recent successful login of the user, as that is likely the provider that was used.
* Not perfect, but better than just hard-coding to localdb provider (cause then it won't work for a token created by an LDAP-authenticated user).
* Not perfect, but better than just hard-coding to localdb provider (cause then it won't work for a token created by an LDAP-authenticated user).
*/
*/
return
_userAuthService
.
getUserDetailsByUsernameAndMostRecentSuccessfulLogin
(
token
.
getXdatUserId
());
return
getUserAuthService
().
getUserDetailsByUsernameAndMostRecentSuccessfulLogin
(
token
.
getXdatUserId
());
}
private
XdatUserAuthService
getUserAuthService
()
{
if
(
_userAuthService
==
null
)
{
_userAuthService
=
_contextService
.
getBean
(
XdatUserAuthService
.
class
);
}
return
_userAuthService
;
}
private
AliasTokenService
getAliasTokenService
()
{
if
(
_aliasTokenService
==
null
)
{
_aliasTokenService
=
_contextService
.
getBean
(
HibernateAliasTokenService
.
class
);
}
return
_aliasTokenService
;
}
}
@Autowired
@Autowired
@Qualifier
(
"rootContextService"
)
@Lazy
@Lazy
private
ContextService
_contextService
;
private
AliasTokenService
_aliasTokenService
;
private
AliasTokenService
_aliasTokenService
;
@Autowired
@Lazy
private
XdatUserAuthService
_userAuthService
;
private
XdatUserAuthService
_userAuthService
;
private
String
_name
;
private
String
_name
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment