Storing Sprint Boot users in a database with Grails 3.0

How do you store users in a database with a new plain vanilla Grails 3.0 application?

Background:

  1. The Shiro and Spring Security plugins are not yet available for Grails 3.0 (and it sounds like Spring Boot is the future for Grails security).
  2. There are various examples out there showing how to use inMemoryAuthentication(), but they seem completely pointless as passwords end up being stored in plain text (besides, it only takes about 30 seconds of effort to create a domain model in Grails).
  3. Pretty much all Grails applications need this functionality.
  4. I’m using MongoDB
  5. Related:

I currently have inMemoryAuthentication() working with the following:

build.gradle

compile "org.springframework.boot:spring-boot-starter-security"

grails-app/conf/spring/resources.groovy

import com.tincanworks.AppSecurityConfig
beans = {
   webSecurityConfiguration(AppSecurityConfig)
   }

AppSecurityConfig.groovy

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter

class AppSecurityConfig extends WebSecurityConfigurerAdapter {

   @Override
   protected void configure(HttpSecurity http) throws Exception {
      http
         .authorizeRequests()
            .antMatchers("/").permitAll()
            .antMatchers("/assets/**").permitAll()
            .antMatchers("/admin/**").hasAnyRole("admin")
            .anyRequest().authenticated()
         .and()
            .formLogin().permitAll()
         .and()
            .logout().permitAll()
      }

   @Autowired
   public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
      auth
         .inMemoryAuthentication()
            .withUser("user").password("123456").roles("user")
            .and()
            .withUser("admin").password("1qaz2wsx").roles("user", "admin");
      }

}

It seems like the answer may be related to =”http://docs.spring.io/spring-security/site/docs/3.0.x/reference/core-services.html” rel=”nofollow”>JdbcDaoImpl, but I have no idea how to hook that up in Grails.


Download storing.sprint.boot.users.in.a.database.with.grails.3.0.zip
Direct Link


Download


Download storing.sprint.boot.users.in.a.database.with.grails.3.0.zip
Mediafire


Download


Download storing.sprint.boot.users.in.a.database.with.grails.3.0.zip
Oboom


Download

Both comments and pings are currently closed.

Comments are closed.