AuthRepository and UserRepository

Keren Meir
Added over 5 years ago


Is there any way to access user repository while the auth repository code is running?

I mean: If the debug is in function "addUser" in "TigaseAuth" class, can I access user Repository (I need the "getData" function to get roster and other stuff from "tigase_pairs" table in db)


Replies (5)

Added by Wojciech Kapcia TigaseTeam over 5 years ago

You could use RepositoryFactory:

String uri = System.getProperty( "user-db-uri" );
UserRepository userRepository = RepositoryFactory.getUserRepository( null, uri, null );
String data = userRepository.getData( ... );

Added by Artur Hefczyc TigaseTeam over 5 years ago

It depends on the context. There are different APIs available, so it depends on where from you want to access the user repository. My suggestion is to wait for the addUser() to complete before calling any getData() for the user as during adding user some metadata are populated in the DB so there might be conflict if you run getData() at the same time.

Added by Keren Meir over 5 years ago

I used a regular sql statement to get my data, but now I have another problem....

The scenario is:

  1. The admin add new user through HTTP REST API.

  2. The scripts run the "addUser(BareJID user, final String password)" function in TigaseAuth.

  3. I added my changes before the end of the function: (DoMyChecks(user) function)

public void addUser(BareJID user, final String password)
            throws UserExistsException, TigaseDBException {
        ResultSet rs = null;
        try {
            PreparedStatement add_user_plain_pw_sp =
                    data_repo.getPreparedStatement(user, ADD_USER_PLAIN_PW_QUERY);
            synchronized (add_user_plain_pw_sp) {
                add_user_plain_pw_sp.setString(1, user.toString());
                add_user_plain_pw_sp.setString(2, password);
                rs = add_user_plain_pw_sp.executeQuery();   
        } catch (SQLIntegrityConstraintViolationException e) {
            throw new UserExistsException("Error while adding user to repository, user exists?", e);
        } catch (SQLException e) {
            throw new TigaseDBException("Problem accessing repository.", e);
        } finally {
            data_repo.release(null, rs);
  1. In the end of my checks I want to send packet to some users. (for example, if the admin added user3 to the system, I want that user1 and user2 add user3 automatically, or at least let user1 and user2 know that user3 is been added to the system (maybe by iq msg)).

The problem is that in TigaseAuth I don't have any session or something that I can send the message.

Do you have any suggestion please?


Added by Artur Hefczyc TigaseTeam over 5 years ago

The best way would be to modify the admin script for HTTP REST API component instead of the addUser(...) method. You can run addUser(...) method from the admin script, then DoYourChecks(), then generate and send packets (messages) to any user you want, you can even update contact lists for users.

Added by Keren Meir over 5 years ago

Thank you! I'll try to implement it in the groovy script....