Results 1 to 4 of 4

Thread: add User in runtime with JDBC authentication

  1. #1
    Join Date
    Nov 2009
    Posts
    2

    Unhappy add User in runtime with JDBC authentication

    Hello, everyone.

    I am new to Spring Security, so I got a problem with user registration. I have some AuthenticationJdbcDao with 2 methods addUser and addUserAuthority.
    Code:
    public class AuthenticationJdbcDao extends JdbcDaoImpl implements AuthenticationDao {
    
        private static final String ADD_USER_QUERY = "INSERT INTO users (username, password, enabled) VALUES (?, ?, ?)";
        private static final String ADD_USER_AUTHORITY_QUERY = "INSERT INTO authorities (username, authority) VALUES (?, ?)";
    
        public void addUser(String name, String password) {
            getJdbcTemplate().update(ADD_USER_QUERY, new Object[] {name, password, true});
        }
    
        public void addUserAuthority(String name, Authority authority) {
            getJdbcTemplate().update(ADD_USER_AUTHORITY_QUERY, new Object[] {name, authority.name()});
        }
    
    }
    All I want to do is simply register new user like this
    Code:
    User user = new User();
    user.setName(name);
    userDao.save(user);
    String userId = "" + user.getId();
    logger.debug("Trying add user with id " + userId);
    authenticationDao.addUser(userId, password); // <- exception here
    authenticationDao.addUserAuthority(userId, Authority.USER_ROLE);
    But when I try invoke code above I get
    Caused by: org.postgresql.util.PSQLException: ERROR: permission denied for relation users
    at org.postgresql.core.v3.QueryExecutorImpl.receiveEr rorResponse(QueryExecutorImpl.java:1592)
    at org.postgresql.core.v3.QueryExecutorImpl.processRe sults(QueryExecutorImpl.java:1327)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(Q ueryExecutorImpl.java:192)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.java:451)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execut eWithFlags(AbstractJdbc2Statement.java:350)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execut eUpdate(AbstractJdbc2Statement.java:304)
    at org.apache.commons.dbcp.DelegatingPreparedStatemen t.executeUpdate(DelegatingPreparedStatement.java:1 02)
    at org.springframework.jdbc.core.JdbcTemplate$2.doInP reparedStatement(JdbcTemplate.java:798)
    at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:591)
    ... 38 more

    I would be very thankful if anyone could explain me how can get rid of it.

  2. #2
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    Seems like however you've configured your JDBC connection or database user isn't correct. This is a database permissions error, nothing to do with Spring Security.
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  3. #3
    Join Date
    Nov 2009
    Posts
    2

    Smile Thanks a lot

    My fault. Thank you VERY much!

  4. #4
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    No need for thanks, you were the one who figured it out
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •