java - Configure JDBC Authentication in Spring Boot -
goal: add jdbc authentication spring boot default security configurations.
source can found here
per spring boot docs
configure global authenticationmanager autowiring authenticationmanagerbuilder method in 1 of @configuration classes
and spring security docs example:
@autowired private datasource datasource; @autowired public void configureglobal(authenticationmanagerbuilder auth) throws exception { auth .jdbcauthentication() .datasource(datasource) .withdefaultschema() .withuser("user").password("password").roles("user").and() .withuser("admin").password("password").roles("user", "admin"); }
given above, added following (found here):
@configuration @enableauthorizationserver @enableresourceserver public class authenticationmanagerconfig { @autowired private datasource datasource; @autowired public void configureglobal(authenticationmanagerbuilder auth) throws exception { auth.jdbcauthentication() .datasource(datasource) .withdefaultschema() .withuser("user").password("password").roles("role_user").and() .withuser("admin").password("password").roles("role_user", "role_admin"); } }
with resulting error:
java.lang.illegalstateexception: cannot apply org.springframework.security.config.annotation.authentication.configurers.provisioning.jdbcuserdetailsmanagerconfigurer@13404f75 built object
and further logs, can see auto config doing it's thing when shouldn't be:
2016-02-02 22:52:48.047 debug 30487 --- [ost-startstop-1] eglobalauthenticationautowiredconfigurer : eagerly initializing {org.springframework.boot.autoconfigure.security.springbootwebsecurityconfiguration=org.springframework.boot.autoconfigure.security.springbootwebsecurityconfiguration$$enhancerbyspringcglib$$627430a8@78acaa86} 2016-02-02 22:52:48.074 debug 30487 --- [ost-startstop-1] .s.bootglobalauthenticationconfiguration : eagerly initializing {user=com.msyla.usergreeter.user.user$$enhancerbyspringcglib$$3cd414fd@73128671, coreconfig=com.msyla.usergreeter.user.core.config.coreconfig$$enhancerbyspringcglib$$30c07250@6ed3c66b} 2016-02-02 22:52:48.095 info 30487 --- [ost-startstop-1] b.a.s.authenticationmanagerconfiguration : using default security password: 5b33158f-156d-43f4-892f-6c452f15e1cc
question: being asked here have default boot configurations exception of user being stored, jdbc instead of in memory. doing incorrectly? docs wrong? have tried several other routes no avail.
thanks in advance!
if want override default security configuration, make sure extending websecurityconfigureradapter
class
@configuration @enableauthorizationserver @enableresourceserver public class authenticationmanagerconfig extends websecurityconfigureradapter { // ... }
and remove prefix role_ on role definition, added automatically spring.
Harrah's Cherokee Casino - TITNIA® Co.
ReplyDeleteThe Cherokee Valley River Casino. Harrah's Cherokee Casino features snow peak titanium spork over 1,600 slots, titanium scissors 110 table galaxy watch 3 titanium games, a poker room, titanium quartz a seasonal outdoor swimming pool, guy tang titanium toner