Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vitamui-pr-pastis
Manage
Activity
Members
Labels
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dad
vitamui-pr-pastis
Commits
2562e44a
Commit
2562e44a
authored
4 years ago
by
Jérôme LELEU
Committed by
Makhtar DIAGNE
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
don't lost surrogation when bad password
parent
1eb14668
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Feature/design/1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cas/cas-server/src/main/java/org/apereo/cas/web/flow/action/SurrogateInitialAuthenticationAction.java
+74
-0
74 additions, 0 deletions
...web/flow/action/SurrogateInitialAuthenticationAction.java
with
74 additions
and
0 deletions
cas/cas-server/src/main/java/org/apereo/cas/web/flow/action/SurrogateInitialAuthenticationAction.java
0 → 100644
+
74
−
0
View file @
2562e44a
package
org.apereo.cas.web.flow.action
;
import
org.apereo.cas.authentication.RememberMeCredential
;
import
org.apereo.cas.authentication.SurrogateUsernamePasswordCredential
;
import
org.apereo.cas.authentication.adaptive.AdaptiveAuthenticationPolicy
;
import
org.apereo.cas.authentication.credential.UsernamePasswordCredential
;
import
org.apereo.cas.web.flow.actions.InitialAuthenticationAction
;
import
org.apereo.cas.web.flow.resolver.CasDelegatingWebflowEventResolver
;
import
org.apereo.cas.web.flow.resolver.CasWebflowEventResolver
;
import
org.apereo.cas.web.support.WebUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.val
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.webflow.execution.Event
;
import
org.springframework.webflow.execution.RequestContext
;
/**
* Copy of the original class without the downgrade to UsernamePasswordCredential when there is no surrogation separator.
*/
@Slf4j
public
class
SurrogateInitialAuthenticationAction
extends
InitialAuthenticationAction
{
private
final
String
separator
;
public
SurrogateInitialAuthenticationAction
(
final
CasDelegatingWebflowEventResolver
delegatingWebflowEventResolver
,
final
CasWebflowEventResolver
webflowEventResolver
,
final
AdaptiveAuthenticationPolicy
adaptiveAuthenticationPolicy
,
final
String
separator
)
{
super
(
delegatingWebflowEventResolver
,
webflowEventResolver
,
adaptiveAuthenticationPolicy
);
this
.
separator
=
separator
;
}
@Override
protected
Event
doPreExecute
(
final
RequestContext
context
)
throws
Exception
{
val
up
=
WebUtils
.
getCredential
(
context
,
UsernamePasswordCredential
.
class
);
if
(
up
==
null
)
{
LOGGER
.
debug
(
"Provided credentials cannot be found, or are already of type [{}]"
,
SurrogateUsernamePasswordCredential
.
class
.
getName
());
return
super
.
doPreExecute
(
context
);
}
if
(
up
.
getUsername
().
contains
(
this
.
separator
))
{
LOGGER
.
debug
(
"Credential username includes the separator [{}]. Converting to surrogate..."
,
this
.
separator
);
convertToSurrogateCredential
(
context
,
up
);
}
return
super
.
doPreExecute
(
context
);
}
private
void
convertToSurrogateCredential
(
final
RequestContext
context
,
final
UsernamePasswordCredential
up
)
{
val
sc
=
new
SurrogateUsernamePasswordCredential
();
val
tUsername
=
up
.
getUsername
();
val
surrogateUsername
=
tUsername
.
substring
(
0
,
tUsername
.
indexOf
(
this
.
separator
));
val
realUsername
=
tUsername
.
substring
(
tUsername
.
indexOf
(
this
.
separator
)
+
this
.
separator
.
length
());
LOGGER
.
debug
(
"Converting to surrogate credential for username [{}], surrogate username [{}]"
,
realUsername
,
surrogateUsername
);
if
(
StringUtils
.
isBlank
(
surrogateUsername
))
{
up
.
setUsername
(
realUsername
);
WebUtils
.
putRequestSurrogateAuthentication
(
context
,
Boolean
.
TRUE
);
WebUtils
.
putCredential
(
context
,
up
);
LOGGER
.
debug
(
"No surrogate username is defined; Signal webflow to request for surrogate credentials"
);
return
;
}
sc
.
setUsername
(
realUsername
);
sc
.
setSurrogateUsername
(
surrogateUsername
);
sc
.
setPassword
(
up
.
getPassword
());
if
(
up
instanceof
RememberMeCredential
)
{
sc
.
setRememberMe
(((
RememberMeCredential
)
up
).
isRememberMe
());
}
WebUtils
.
putRequestSurrogateAuthentication
(
context
,
Boolean
.
FALSE
);
LOGGER
.
debug
(
"Converted credential to surrogate for username [{}] and assigned it to webflow"
,
realUsername
);
WebUtils
.
putCredential
(
context
,
sc
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
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