java - In memory and custom providers all together -
i'm setting spring security (v4.0.1) web application. want have 2 authentication providers, "in-memory" 1 manage administrator account , custom 1 refers own implementation. system should attempt authentication against "in-memory" provider first of , against custom 1 in second place. code looks this:
@autowired public void configureglobal(authenticationmanagerbuilder auth, authenticationprovider provider) throws exception { auth.inmemoryauthentication() .withuser("admin") .password("s3cr3t") .authorities("admin"); auth.authenticationprovider(provider); } however, code leads framework try custom implementation first. makes bit of sense, since authenticationmanagerbuilder#authenticationprovider method adds provider internal list while authenticationmanagerbuilder#inmemoryauthentication 1 configures internally. how manage work?
you can create inmemoryuserdetailsmanagerconfigurer manually , tell configure on authenticationmanagerbuilder when have finished configuring installs it's authenticationprovider before custom one:
@autowired public void configureglobal(authenticationmanagerbuilder auth, authenticationprovider provider) throws exception { inmemoryconfigurer() .withuser("admin") .password("s3cr3t") .authorities("admin") .and() .configure(auth); auth.authenticationprovider(provider); } private inmemoryuserdetailsmanagerconfigurer<authenticationmanagerbuilder> inmemoryconfigurer() { return new inmemoryuserdetailsmanagerconfigurer<>(); } normally happens inmemoryuserdetailsmanagerconfigurer created , added list of configurers should applied when authenticationmanager built - after you've installed custom authenticationprovider.
Comments
Post a Comment