Social Media

Auto-generating Spring Security Tutorial – Custom JDBC Realms

This post builds on the set of spring-security posts I have done, and particularly my last post on Default JDBC Realms. The code is available on github, and spring-security-generator and the instructions to run the application are contained in the previous tutorial.

We also have a requirement to use a custom JDBC realm with the structure –

USER PASSWORD ROLES
customadmin customadmin ROLE_CUSTOM_ADMIN

Custom JDBC Tables

Spring-Security-Generator

Using spring-security-generator we now select “JDBC Realm (Custom)” and supply the queries –

The screen configuration is then –

screen-shot-2016-11-07-at-21-00-50

We then generate the code –

The key difference between this tutorial and the previous is that we supply the SQL directly to the usersByUsernameQuery and authoritiesByUsernameQuery

We can now copy this code to the parkrunpb applicaiton, and login using customadmin/customadmin

About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About

follow me on:

Leave a Comment:

1 comment
Rajesh says 08/05/2017

Hi sir, I want to supply the uri and authority in antMatcher() and in access() from database using spring security how i can achieve it

Reply
Add Your Reply