Spring Security: Custom LdapAuthenticationProviderWhat's the difference between @Component, @Repository & @Service annotations in Spring?How to configure port for a Spring Boot applicationSecurity configuration with Spring-bootSpring Security: AuthenticationProvider and UserDetailsService not working as expectedSpring Security Thymleaf static resources don't loadSpring boot security consider case insensitive username check for loginCustomize Spring Security for trusted spaceHow to pass custom creds to spring boot ldapSpring-Security 5 always 302Spring boot security cannot log in after invalid credentials
Are actors contractually obligated to certain things like going nude/ Sensual Scenes/ Gory Scenes?
Can the U.S. president make military decisions without consulting anyone?
Algorithm that spans orthogonal vectors: Python
What can a pilot do if an air traffic controller is incapacitated?
How do I extract code from an arduino?
Cheap antenna for new HF HAM
How could artificial intelligence harm us?
What is the need of methods like GET and POST in the HTTP protocol?
Can Northern Ireland's border issue be solved by repartition?
Debussy as term for bathroom?
What is the most damaging one handed melee weapon?
Is there any actual security benefit to restricting foreign IPs?
Name of cleat-style tripod mounting head
I reverse the source code, you negate the input!
When does removing Goblin Warchief affect its cost reduction ability?
What did the controller say during my approach to land (audio clip)?
How do I clean sealant/silicon from a glass mirror?
What are these pixel-level discolored specks? How can I fix it?
Can multiple wall timers turn lights on or off when required?
Repeat elements in list, but the number of times each element is repeated is provided by a separate list
How does IBM's 53-bit quantum computer compares to classical ones for cryptanalytic tasks?
How use custom order in folder on Windows 7 and 10
Writing a letter of recommendation for a mediocre student
Nanomachines exist that enable Axolotl-levels of regeneration - So how can crippling injuries exist as well?
Spring Security: Custom LdapAuthenticationProvider
What's the difference between @Component, @Repository & @Service annotations in Spring?How to configure port for a Spring Boot applicationSecurity configuration with Spring-bootSpring Security: AuthenticationProvider and UserDetailsService not working as expectedSpring Security Thymleaf static resources don't loadSpring boot security consider case insensitive username check for loginCustomize Spring Security for trusted spaceHow to pass custom creds to spring boot ldapSpring-Security 5 always 302Spring boot security cannot log in after invalid credentials
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to use a custom LdapAuthenticationProvider, with only one minor change, in order to execute the authentication, a certain precondition needs to be met.
What I want basically:
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException
if (!precondition)
throw new DisabledException("");
return super.authenticate(authentication);
My WebSecurityConfigurerAdapter:
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
auth
.userDetailsService(userDetailsService)
.passwordEncoder(encoder);
if (ldapSecurityConfig.isLdapEnabled())
auth
.ldapAuthentication()
.contextSource(ldapContextSource)
.userSearchFilter(ldapSecurityConfig.getUserSearchFilter())
.ldapAuthoritiesPopulator(ldapAuthoritiesPopulator)
.userDetailsContextMapper(userDetailsContextMapper);
The problem is, that the line
auth.ldapAuthentication()
creates an LdapAuthenticationProviderConfigurer object, and its build method instantiates an LdapAuthenticationProvider object:
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(ldapAuthenticator, authoritiesPopulator);
It looks like I don't have control over which LdapAuthenticationProvider will be used at the end.
As a workaround, I could check the precondition in my UserDetailsContextMapper object and throw an exception if it is not met, but it is not optimal, since in this case the LDAP server will be queried even if it's not needed.
My question is, how can I force that my custom provider will be used, or is there any other "simple" way to achieve the behaviour I want?
java spring spring-boot spring-security
add a comment
|
I need to use a custom LdapAuthenticationProvider, with only one minor change, in order to execute the authentication, a certain precondition needs to be met.
What I want basically:
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException
if (!precondition)
throw new DisabledException("");
return super.authenticate(authentication);
My WebSecurityConfigurerAdapter:
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
auth
.userDetailsService(userDetailsService)
.passwordEncoder(encoder);
if (ldapSecurityConfig.isLdapEnabled())
auth
.ldapAuthentication()
.contextSource(ldapContextSource)
.userSearchFilter(ldapSecurityConfig.getUserSearchFilter())
.ldapAuthoritiesPopulator(ldapAuthoritiesPopulator)
.userDetailsContextMapper(userDetailsContextMapper);
The problem is, that the line
auth.ldapAuthentication()
creates an LdapAuthenticationProviderConfigurer object, and its build method instantiates an LdapAuthenticationProvider object:
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(ldapAuthenticator, authoritiesPopulator);
It looks like I don't have control over which LdapAuthenticationProvider will be used at the end.
As a workaround, I could check the precondition in my UserDetailsContextMapper object and throw an exception if it is not met, but it is not optimal, since in this case the LDAP server will be queried even if it's not needed.
My question is, how can I force that my custom provider will be used, or is there any other "simple" way to achieve the behaviour I want?
java spring spring-boot spring-security
add a comment
|
I need to use a custom LdapAuthenticationProvider, with only one minor change, in order to execute the authentication, a certain precondition needs to be met.
What I want basically:
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException
if (!precondition)
throw new DisabledException("");
return super.authenticate(authentication);
My WebSecurityConfigurerAdapter:
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
auth
.userDetailsService(userDetailsService)
.passwordEncoder(encoder);
if (ldapSecurityConfig.isLdapEnabled())
auth
.ldapAuthentication()
.contextSource(ldapContextSource)
.userSearchFilter(ldapSecurityConfig.getUserSearchFilter())
.ldapAuthoritiesPopulator(ldapAuthoritiesPopulator)
.userDetailsContextMapper(userDetailsContextMapper);
The problem is, that the line
auth.ldapAuthentication()
creates an LdapAuthenticationProviderConfigurer object, and its build method instantiates an LdapAuthenticationProvider object:
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(ldapAuthenticator, authoritiesPopulator);
It looks like I don't have control over which LdapAuthenticationProvider will be used at the end.
As a workaround, I could check the precondition in my UserDetailsContextMapper object and throw an exception if it is not met, but it is not optimal, since in this case the LDAP server will be queried even if it's not needed.
My question is, how can I force that my custom provider will be used, or is there any other "simple" way to achieve the behaviour I want?
java spring spring-boot spring-security
I need to use a custom LdapAuthenticationProvider, with only one minor change, in order to execute the authentication, a certain precondition needs to be met.
What I want basically:
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException
if (!precondition)
throw new DisabledException("");
return super.authenticate(authentication);
My WebSecurityConfigurerAdapter:
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
auth
.userDetailsService(userDetailsService)
.passwordEncoder(encoder);
if (ldapSecurityConfig.isLdapEnabled())
auth
.ldapAuthentication()
.contextSource(ldapContextSource)
.userSearchFilter(ldapSecurityConfig.getUserSearchFilter())
.ldapAuthoritiesPopulator(ldapAuthoritiesPopulator)
.userDetailsContextMapper(userDetailsContextMapper);
The problem is, that the line
auth.ldapAuthentication()
creates an LdapAuthenticationProviderConfigurer object, and its build method instantiates an LdapAuthenticationProvider object:
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(ldapAuthenticator, authoritiesPopulator);
It looks like I don't have control over which LdapAuthenticationProvider will be used at the end.
As a workaround, I could check the precondition in my UserDetailsContextMapper object and throw an exception if it is not met, but it is not optimal, since in this case the LDAP server will be queried even if it's not needed.
My question is, how can I force that my custom provider will be used, or is there any other "simple" way to achieve the behaviour I want?
java spring spring-boot spring-security
java spring spring-boot spring-security
edited Mar 28 at 15:07
lebigmac
asked Mar 28 at 15:01
lebigmaclebigmac
13 bronze badges
13 bronze badges
add a comment
|
add a comment
|
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400809%2fspring-security-custom-ldapauthenticationprovider%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400809%2fspring-security-custom-ldapauthenticationprovider%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown