Announcement Announcement Module
Collapse
No announcement yet.
add User in runtime with JDBC authentication Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • 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.
    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
    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.

    Comment


    • #3
      Thanks a lot

      My fault. Thank you VERY much!

      Comment


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

        Comment

        Working...
        X