Announcement Announcement Module
Collapse
No announcement yet.
Spring Roo - Spring Security - Sql Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Roo - Spring Security - Sql

    Hello everybody,

    I'm trying to use Roo with Spring Security and a mysql database.
    Moreover I want to use scaffolding so as to manage my users.
    Following instructions in
    http://static.springsource.org/sprin...ix-schema.html

    I've tried a lot of things like:

    Code:
    entity --class ~.domain.Users --identifierField username --identifierColumn username --permitReservedWords 
    field string --fieldName username --notNull --sizeMin 3 --sizeMax 50
    field string --fieldName password --notNull
    field boolean --fieldName enabled --notNull true
    But I'm not able to get Roo to generate my tables like I'll do manually

    Code:
    CREATE TABLE users(
    username varchar(50) NOT NULL PRIMARY KEY,
    password varchar(50) NOT NULL,
    enabled BOOLEAN NOT NULL);
    
    CREATE TABLE authorities(
    username varchar( 50 ) NOT NULL ,
    authority varchar( 50 ) NOT NULL ,
    CONSTRAINT fk_authorities_users FOREIGN KEY ( username ) REFERENCES users( username )
    );
    CREATE UNIQUE INDEX ix_auth_username ON authorities(username,authority);
    btw as 'user' and 'member' are sql reserved keywords nothing work.

    How could I use Spring Roo / Spring Security / a mysql database?
    Has someone already done it?

    Many thanks.

  • #2
    In order to 'tweak' JPA in a way that it generates the exact tables you want you may need to adjust some of the annotations in your domain entities manually. As for the use of reserved words a workaround would be to change the table names so there is no clash. In the Spring Security application context you can then configure the custom table names.

    Generally, this is certainly something that could be useful for the Spring Security addon in Roo itself (automatic scaffolding of user/role management, signup forms, etc) so if you want you can open a ticket as a feature request for this.

    Comment


    • #3
      feature request for a better spring security addon opened

      At first, thank you for your explanation Stephan.

      I've just open a feature request for a better spring security addon created in Jira:

      http://jira.springsource.org/browse/ROO-532

      Comment


      • #4
        I've tried with this script


        Code:
        entity --class com.crmizer.domain.crmo.rbac.Users --testAutomatically 
        field string --fieldName username --notNull --sizeMax 50
        field string --fieldName password --notNull --sizeMax 50
        field boolean --fieldName enabled --notNull 
        field string --fieldName shortname --notNull --sizeMax 20
        finder add --finderName findUsersesByShortnameLike --class *
        finder add --finderName findUsersesByEnabled --class * 
        finder add --finderName findUsersesByShortnameLikeAndEnabled --class *
        
        entity --class com.crmizer.domain.crmo.rbac.Authorities --testAutomatically 
        field string --fieldName username --notNull --sizeMax 50
        field string --fieldName authority --notNull --sizeMax 50
        finder add --finderName findAuthoritiesesByAuthorityLike --class *
        finder add --finderName findAuthoritiesesByAuthorityLikeAndUsernameLike --class *
        finder add --finderName findAuthoritiesesByUsernameLike --class *
        
        entity --class com.crmizer.domain.crmo.rbac.Persistent_logins
        field string --fieldName username --notNull --sizeMax 64
        field string --fieldName series --notNull --sizeMax 64
        field string --fieldName token --notNull --sizeMax 64
        field date --fieldName last_used --type java.util.Calendar --persistenceType JPA_TIMESTAMP --notNull 
        finder add --finderName findPersistent_loginsesByUsernameLike --class *
        And then added the constraints manually using the sql maven plugin with


        Code:
        	      <plugin>
        				<groupId>org.codehaus.mojo</groupId>
        				<artifactId>sql-maven-plugin</artifactId>
        				<version>1.2</version>
        
        	        	<dependencies>
        				<!-- specify the dependent jdbc driver here -->
        					<dependency>
        						<groupId>com.mysql.jdbc</groupId>
        						<artifactId>com.springsource.com.mysql.jdbc</artifactId>
        						<version>5.1.6</version>
        					</dependency>
        				</dependencies>
        				
        				<!-- common configuration shared by all executions -->
        				<configuration>
        					<driver>com.mysql.jdbc.Driver</driver>
        					<url>jdbc:mysql://localhost:3306/xxxx</url>
        					<username>uuu</username>
        					<password>ppp</password>
        				</configuration>
        				<executions>
        					<execution>
        						<id>sqlinit</id>
        						<phase>test</phase>
        						<goals>
        							<goal>execute</goal>
        						</goals>
        						<configuration>
        							<autocommit>true</autocommit>
        							<srcFiles>
        								<srcFile>src/test/resources/sql_init.sql</srcFile>
        							</srcFiles>
        						</configuration>
        					</execution>
        				</executions>
        								
        				
        			</plugin>
        And this run every time I make "mvn test" so my initial data is inserted, you can add here the sql constraints and indexes there.
        -Be careful with "hibernate.hbm2ddl.auto"
        -Take into accout that "remembeme" is not working with spring-security-3.0.1.RELEASE right now.

        Comment


        • #5
          I want to know of using PostgreSQL with this entities...

          Comment

          Working...
          X