Announcement Announcement Module
No announcement yet.
add User in runtime with JDBC authentication Page Title Module
Move Remove Collapse
This topic is closed
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.
    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,});
    All I want to do is simply register new user like this
    User user = new 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(
    at org.postgresql.core.v3.QueryExecutorImpl.processRe sults(
    at org.postgresql.core.v3.QueryExecutorImpl.execute(Q
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execut eWithFlags(
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execut eUpdate(
    at org.apache.commons.dbcp.DelegatingPreparedStatemen t.executeUpdate( 02)
    at org.springframework.jdbc.core.JdbcTemplate$2.doInP reparedStatement(
    at org.springframework.jdbc.core.JdbcTemplate.execute (
    ... 38 more

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

  • #2
    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.


    • #3
      Thanks a lot

      My fault. Thank you VERY much!


      • #4
        No need for thanks, you were the one who figured it out