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;








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?










share|improve this question
































    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?










    share|improve this question




























      0












      0








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 15:07







      lebigmac

















      asked Mar 28 at 15:01









      lebigmaclebigmac

      13 bronze badges




      13 bronze badges

























          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
          );



          );














          draft saved

          draft discarded
















          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.




















          draft saved

          draft discarded















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript