Project

General

Profile

getIid deprecated? What's the alternative

J B
Added about 3 years ago

Hi,

I have inherited some old plugin code that used getIid from AuthRepository. Not it is not compiling. I searched all the helps and forums but didn't find any alternative.

Is there one?

Thanks


Replies (6)

Added by Wojciech Kapcia TigaseTeam almost 3 years ago

If you could be more specific it would help:

  • which plugin you used?

  • what it returned? please provide full and exact method signature. We usually don't remove methods and single similar one could be tigase.db.UserRepository.getUserUID(BareJID)

Added by J B almost 3 years ago

Sorry about the typo in the original email as well as being cryptic. What I meant to say was that the code is now not compiling.

It is a sessionhandler plugin. I am trying to compile it against 5.2.3 tag code of tigase from git. One of our developers had pasted the code (for a different reason) on the forum: https://projects.tigase.org/boards/15/topics/4338

However - for your convenience - below is the copy/paste of the same code that is now not compiling. The error I get is that the signature is missing for the getIid call: session.getAuthRepository().getIid(session.getBareJID()).

I looked at the documentation and the java file of AuthRepository and getIid is indeed no longer there.

Thanks

J

Here is the actual code:

public class SessionHandlerPlugin extends XMPPProcessor implements XMPPProcessorIfc {

    public static final int THRESHOLD_LIMIT = 1;

    public static final String PLUGIN_ID = "my-SessionHandlerPlugin";


    @Override

public String id() {

    return PLUGIN_ID;

}


    @Override

public void process(Packet packet, XMPPResourceConnection session, NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings) throws XMPPException {


    if (session == null || !session.isAuthorized()) {

        return;

    }

    try {

        String resource = session.getResource();


        log.log(Level.WARNING, "ppp resource = " + resource);


        try {

            if (session.getBareJID() == null) {

                logout(session);

            } else {

                String installationId = session.getAuthRepository().getIid(session.getBareJID());

                if (installationId == null || "".equals(installationId)) {

                    logout(session);

                } else if (installationId.equals(resource)) {

                    // continue normal login i.e. do nothing

                    long tempHigestLong = 0l;

                    int indexOfSessionNotToBeLoggedOut = -1;

                    List<XMPPResourceConnection> activeSessions = session.getActiveSessions();

                    if (activeSessions.size() > THRESHOLD_LIMIT) {


                        for (int i = 0; i < activeSessions.size(); i++) {

                            if (tempHigestLong < activeSessions.get(i).getCreationTime()) {

                                tempHigestLong = activeSessions.get(i).getCreationTime();

                                indexOfSessionNotToBeLoggedOut = i;

                            }

                        }


                        for (int i = 0; i < activeSessions.size(); i++) {

                            if (i != indexOfSessionNotToBeLoggedOut) {

                                activeSessions.get(i).logout();

                            }

                        }

                    }

                } else {

                    // iid and resrouce are not equal

                    logout(session);

                }

            }

        } catch (TigaseDBException | SQLException e) {

            logout(session);

        }

    } catch (XMPPException eee) {


    }

}


private void logout(XMPPResourceConnection session) throws XMPPException {

    if (session.isAuthorized()) {

        session.logout();

    }

    throw new XMPPException("Sorry you cannot login");

}

}

Added by J B almost 3 years ago

I looked at all the tags from 5.0.0 to 7.0.0 - didn't find this version of AuthRepository.java - so attaching the local copy from the build server that we have on our end. As you can see - this version of AuthRepository has getIid

void updatePassword(BareJID user, String password)

                throws UserNotFoundException, TigaseDBException;


void updateIid(BareJID user, String iid) throws UserNotFoundException, TigaseDBException;


String getIid(BareJID user) throws UserNotFoundException, TigaseDBException, SQLException;

} // AuthRepository

I am also attaching pom.xml and build.xml if that provides any additional data/help.

Thanks

Added by Wojciech Kapcia TigaseTeam almost 3 years ago

J B wrote:

I looked at all the tags from 5.0.0 to 7.0.0 - didn't find this version of AuthRepository.java - so attaching the local copy from the build server that we have on our end. As you can see - this version of AuthRepository has getIid

Given this comes from your local copy and that our repository doesn't have any indication of this methods then I'm inclined to say that they were added by your developer (i.e. he modified sources of Tigase sources) and it was never part of Tigase.

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam almost 3 years ago

I am the original author of the code in Tigase and I can confirm, there was never such a method in AuthRepository. At least I cannot recall anything like it.

What Tigase version your code is based on?

Added by J B almost 3 years ago

Thanks Artur - my guess is the same - i.e. the developer tried to make some changes to AuthRepository.java in addition to adding the plugin code.

Looking at the pom.xml it seems he used 5.2.x version

    (1-6/6)