Class MongoRepository

  • All Implemented Interfaces:
    tigase.db.AuthRepository, tigase.db.DataSourceAware<MongoDataSource>, tigase.db.Repository, tigase.db.UserRepository, tigase.db.util.RepositoryVersionAware, MongoRepositoryVersionAware

    public class MongoRepository
    extends tigase.db.AbstractAuthRepositoryWithCredentials
    implements tigase.db.UserRepository, tigase.db.DataSourceAware<MongoDataSource>, MongoRepositoryVersionAware
    MongoRepository is implementation of UserRepository and AuthRepository which supports MongoDB data store.
    Author:
    andrzej
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface tigase.db.AuthRepository

        tigase.db.AuthRepository.AccountStatus, tigase.db.AuthRepository.DefaultCredentials, tigase.db.AuthRepository.SingleCredential
      • Nested classes/interfaces inherited from interface tigase.db.Repository

        tigase.db.Repository.Meta, tigase.db.Repository.SchemaId
      • Nested classes/interfaces inherited from interface tigase.db.util.RepositoryVersionAware

        tigase.db.util.RepositoryVersionAware.SchemaVersion
      • Nested classes/interfaces inherited from interface tigase.db.UserRepository

        tigase.db.UserRepository.UserRemovedEvent
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean autoCreateUser  
      protected static java.lang.String DOMAIN_KEY  
      protected static java.lang.String ID_KEY  
      protected static java.lang.String NODES_COLLECTION  
      protected static java.lang.String USER_CREDENTIALS_COLLECTION  
      protected static java.lang.String USERS_COLLECTION  
      • Fields inherited from interface tigase.db.AuthRepository

        DATA_KEY, DIGEST_ID_KEY, DIGEST_KEY, MACHANISM_KEY, PASSWORD_KEY, PROTOCOL_KEY, PROTOCOL_VAL_NONSASL, PROTOCOL_VAL_SASL, REALM_KEY, RESULT_KEY, SERVER_NAME_KEY, USER_ID_KEY
    • Constructor Summary

      Constructors 
      Constructor Description
      MongoRepository()  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addDataList​(tigase.xmpp.jid.BareJID user, java.lang.String subnode, java.lang.String key, java.lang.String[] list)  
      void addUser​(tigase.xmpp.jid.BareJID user)  
      void addUser​(tigase.xmpp.jid.BareJID user, java.lang.String password)  
      protected byte[] calculateHash​(java.lang.String user)  
      protected byte[] generateId​(tigase.xmpp.jid.BareJID user)  
      tigase.db.AuthRepository.AccountStatus getAccountStatus​(tigase.xmpp.jid.BareJID user)  
      java.util.Collection<java.lang.String> getCredentialIds​(tigase.xmpp.jid.BareJID user)  
      tigase.auth.credentials.Credentials getCredentials​(tigase.xmpp.jid.BareJID user, java.lang.String credentialId)  
      java.lang.String getData​(tigase.xmpp.jid.BareJID user, java.lang.String key)  
      java.lang.String getData​(tigase.xmpp.jid.BareJID user, java.lang.String subnode, java.lang.String key)  
      java.lang.String getData​(tigase.xmpp.jid.BareJID user, java.lang.String subnode, java.lang.String key, java.lang.String def)  
      java.lang.String[] getDataList​(tigase.xmpp.jid.BareJID user, java.lang.String subnode, java.lang.String key)  
      java.util.Map<java.lang.String,​java.lang.String> getDataMap​(tigase.xmpp.jid.BareJID user, java.lang.String subnode)  
      <T> java.util.Map<java.lang.String,​T> getDataMap​(tigase.xmpp.jid.BareJID user, java.lang.String subnode, java.util.function.Function<java.lang.String,​T> converter)  
      java.lang.String[] getKeys​(tigase.xmpp.jid.BareJID user)  
      java.lang.String[] getKeys​(tigase.xmpp.jid.BareJID user, java.lang.String subnode)  
      java.lang.String getResourceUri()  
      java.lang.String[] getSubnodes​(tigase.xmpp.jid.BareJID user)  
      java.lang.String[] getSubnodes​(tigase.xmpp.jid.BareJID user, java.lang.String subnode)  
      java.util.List<tigase.xmpp.jid.BareJID> getUsers()  
      long getUsersCount()  
      long getUsersCount​(java.lang.String domain)  
      long getUserUID​(tigase.xmpp.jid.BareJID user)
      Deprecated.
      void initRepository​(java.lang.String resource_uri, java.util.Map<java.lang.String,​java.lang.String> params)
      Deprecated.
      void loggedIn​(tigase.xmpp.jid.BareJID jid)  
      void logout​(tigase.xmpp.jid.BareJID user)  
      boolean otherAuth​(java.util.Map<java.lang.String,​java.lang.Object> authProps)  
      void queryAuth​(java.util.Map<java.lang.String,​java.lang.Object> authProps)  
      protected <T> java.util.List<T> readAllDistinctValuesForField​(com.mongodb.client.MongoCollection<org.bson.Document> collection, java.lang.String field, org.bson.Document crit)  
      void removeCredential​(tigase.xmpp.jid.BareJID user, java.lang.String credentialId)  
      void removeData​(tigase.xmpp.jid.BareJID user, java.lang.String key)  
      void removeData​(tigase.xmpp.jid.BareJID user, java.lang.String subnode, java.lang.String key)  
      void removeSubnode​(tigase.xmpp.jid.BareJID user, java.lang.String subnode)  
      void removeUser​(tigase.xmpp.jid.BareJID user)  
      void setAccountStatus​(tigase.xmpp.jid.BareJID user, tigase.db.AuthRepository.AccountStatus status)  
      void setData​(tigase.xmpp.jid.BareJID user, java.lang.String key, java.lang.String value)  
      void setData​(tigase.xmpp.jid.BareJID user, java.lang.String subnode, java.lang.String key, java.lang.String value)  
      void setDataList​(tigase.xmpp.jid.BareJID user, java.lang.String subnode, java.lang.String key, java.lang.String[] list)  
      void setDataSource​(MongoDataSource dataSource)  
      void updateCredential​(tigase.xmpp.jid.BareJID user, java.lang.String credentialId, java.lang.String password)  
      void updatePassword​(tigase.xmpp.jid.BareJID user, java.lang.String password)  
      tigase.db.util.SchemaLoader.Result updateSchema​(java.util.Optional<tigase.util.Version> oldVersion, tigase.util.Version newVersion)  
      boolean userExists​(tigase.xmpp.jid.BareJID user)  
      • Methods inherited from class tigase.db.AbstractAuthRepositoryWithCredentials

        getCredentialsDecoder, getCredentialsEncoder, getPassword, isMechanismSupported, setCredentialsCodecs
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface tigase.db.AuthRepository

        getUsernames, isUserDisabled, setUserDisabled
    • Field Detail

      • USERS_COLLECTION

        protected static final java.lang.String USERS_COLLECTION
        See Also:
        Constant Field Values
      • USER_CREDENTIALS_COLLECTION

        protected static final java.lang.String USER_CREDENTIALS_COLLECTION
        See Also:
        Constant Field Values
      • NODES_COLLECTION

        protected static final java.lang.String NODES_COLLECTION
        See Also:
        Constant Field Values
      • autoCreateUser

        @ConfigField(desc="Auto create user",
                     alias="autoCreateUser=")
        protected boolean autoCreateUser
    • Constructor Detail

      • MongoRepository

        public MongoRepository()
    • Method Detail

      • addDataList

        public void addDataList​(tigase.xmpp.jid.BareJID user,
                                java.lang.String subnode,
                                java.lang.String key,
                                java.lang.String[] list)
                         throws tigase.db.UserNotFoundException,
                                tigase.db.TigaseDBException
        Specified by:
        addDataList in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • addUser

        public void addUser​(tigase.xmpp.jid.BareJID user)
                     throws tigase.db.UserExistsException,
                            tigase.db.TigaseDBException
        Specified by:
        addUser in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserExistsException
        tigase.db.TigaseDBException
      • addUser

        public void addUser​(tigase.xmpp.jid.BareJID user,
                            java.lang.String password)
                     throws tigase.db.UserExistsException,
                            tigase.db.TigaseDBException
        Specified by:
        addUser in interface tigase.db.AuthRepository
        Throws:
        tigase.db.UserExistsException
        tigase.db.TigaseDBException
      • calculateHash

        protected byte[] calculateHash​(java.lang.String user)
                                throws tigase.db.TigaseDBException
        Throws:
        tigase.db.TigaseDBException
      • generateId

        protected byte[] generateId​(tigase.xmpp.jid.BareJID user)
                             throws tigase.db.TigaseDBException
        Throws:
        tigase.db.TigaseDBException
      • getAccountStatus

        public tigase.db.AuthRepository.AccountStatus getAccountStatus​(tigase.xmpp.jid.BareJID user)
                                                                throws tigase.db.TigaseDBException
        Specified by:
        getAccountStatus in interface tigase.db.AuthRepository
        Throws:
        tigase.db.TigaseDBException
      • getCredentials

        public tigase.auth.credentials.Credentials getCredentials​(tigase.xmpp.jid.BareJID user,
                                                                  java.lang.String credentialId)
                                                           throws tigase.db.TigaseDBException
        Specified by:
        getCredentials in interface tigase.db.AuthRepository
        Throws:
        tigase.db.TigaseDBException
      • getData

        public java.lang.String getData​(tigase.xmpp.jid.BareJID user,
                                        java.lang.String subnode,
                                        java.lang.String key,
                                        java.lang.String def)
                                 throws tigase.db.UserNotFoundException,
                                        tigase.db.TigaseDBException
        Specified by:
        getData in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • getData

        public java.lang.String getData​(tigase.xmpp.jid.BareJID user,
                                        java.lang.String subnode,
                                        java.lang.String key)
                                 throws tigase.db.UserNotFoundException,
                                        tigase.db.TigaseDBException
        Specified by:
        getData in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • getData

        public java.lang.String getData​(tigase.xmpp.jid.BareJID user,
                                        java.lang.String key)
                                 throws tigase.db.UserNotFoundException,
                                        tigase.db.TigaseDBException
        Specified by:
        getData in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • getDataMap

        public java.util.Map<java.lang.String,​java.lang.String> getDataMap​(tigase.xmpp.jid.BareJID user,
                                                                                 java.lang.String subnode)
                                                                          throws tigase.db.TigaseDBException
        Specified by:
        getDataMap in interface tigase.db.UserRepository
        Throws:
        tigase.db.TigaseDBException
      • getDataMap

        public <T> java.util.Map<java.lang.String,​T> getDataMap​(tigase.xmpp.jid.BareJID user,
                                                                      java.lang.String subnode,
                                                                      java.util.function.Function<java.lang.String,​T> converter)
                                                               throws tigase.db.TigaseDBException
        Specified by:
        getDataMap in interface tigase.db.UserRepository
        Throws:
        tigase.db.TigaseDBException
      • getDataList

        public java.lang.String[] getDataList​(tigase.xmpp.jid.BareJID user,
                                              java.lang.String subnode,
                                              java.lang.String key)
                                       throws tigase.db.UserNotFoundException,
                                              tigase.db.TigaseDBException
        Specified by:
        getDataList in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • getKeys

        public java.lang.String[] getKeys​(tigase.xmpp.jid.BareJID user,
                                          java.lang.String subnode)
                                   throws tigase.db.UserNotFoundException,
                                          tigase.db.TigaseDBException
        Specified by:
        getKeys in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • getKeys

        public java.lang.String[] getKeys​(tigase.xmpp.jid.BareJID user)
                                   throws tigase.db.UserNotFoundException,
                                          tigase.db.TigaseDBException
        Specified by:
        getKeys in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • getResourceUri

        public java.lang.String getResourceUri()
        Specified by:
        getResourceUri in interface tigase.db.AuthRepository
        Specified by:
        getResourceUri in interface tigase.db.UserRepository
      • getSubnodes

        public java.lang.String[] getSubnodes​(tigase.xmpp.jid.BareJID user)
                                       throws tigase.db.UserNotFoundException,
                                              tigase.db.TigaseDBException
        Specified by:
        getSubnodes in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • getSubnodes

        public java.lang.String[] getSubnodes​(tigase.xmpp.jid.BareJID user,
                                              java.lang.String subnode)
                                       throws tigase.db.UserNotFoundException,
                                              tigase.db.TigaseDBException
        Specified by:
        getSubnodes in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • getCredentialIds

        public java.util.Collection<java.lang.String> getCredentialIds​(tigase.xmpp.jid.BareJID user)
                                                                throws tigase.db.TigaseDBException
        Specified by:
        getCredentialIds in interface tigase.db.AuthRepository
        Throws:
        tigase.db.TigaseDBException
      • getUserUID

        @Deprecated
        public long getUserUID​(tigase.xmpp.jid.BareJID user)
                        throws tigase.db.TigaseDBException
        Deprecated.
        Should be removed as only relational DB are using this and it is not required by any other code
        Specified by:
        getUserUID in interface tigase.db.UserRepository
        Throws:
        tigase.db.TigaseDBException
      • getUsers

        public java.util.List<tigase.xmpp.jid.BareJID> getUsers()
                                                         throws tigase.db.TigaseDBException
        Specified by:
        getUsers in interface tigase.db.UserRepository
        Throws:
        tigase.db.TigaseDBException
      • getUsersCount

        public long getUsersCount()
        Specified by:
        getUsersCount in interface tigase.db.AuthRepository
        Specified by:
        getUsersCount in interface tigase.db.UserRepository
      • getUsersCount

        public long getUsersCount​(java.lang.String domain)
        Specified by:
        getUsersCount in interface tigase.db.AuthRepository
        Specified by:
        getUsersCount in interface tigase.db.UserRepository
      • initRepository

        @Deprecated
        public void initRepository​(java.lang.String resource_uri,
                                   java.util.Map<java.lang.String,​java.lang.String> params)
                            throws tigase.db.DBInitException
        Deprecated.
        Specified by:
        initRepository in interface tigase.db.Repository
        Throws:
        tigase.db.DBInitException
      • loggedIn

        public void loggedIn​(tigase.xmpp.jid.BareJID jid)
                      throws tigase.db.TigaseDBException
        Specified by:
        loggedIn in interface tigase.db.AuthRepository
        Throws:
        tigase.db.TigaseDBException
      • logout

        public void logout​(tigase.xmpp.jid.BareJID user)
                    throws tigase.db.UserNotFoundException,
                           tigase.db.TigaseDBException
        Specified by:
        logout in interface tigase.db.AuthRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • otherAuth

        public boolean otherAuth​(java.util.Map<java.lang.String,​java.lang.Object> authProps)
                          throws tigase.db.UserNotFoundException,
                                 tigase.db.TigaseDBException,
                                 tigase.db.AuthorizationException
        Specified by:
        otherAuth in interface tigase.db.AuthRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
        tigase.db.AuthorizationException
      • queryAuth

        public void queryAuth​(java.util.Map<java.lang.String,​java.lang.Object> authProps)
        Specified by:
        queryAuth in interface tigase.db.AuthRepository
      • readAllDistinctValuesForField

        protected <T> java.util.List<T> readAllDistinctValuesForField​(com.mongodb.client.MongoCollection<org.bson.Document> collection,
                                                                      java.lang.String field,
                                                                      org.bson.Document crit)
                                                               throws com.mongodb.MongoException
        Throws:
        com.mongodb.MongoException
      • removeCredential

        public void removeCredential​(tigase.xmpp.jid.BareJID user,
                                     java.lang.String credentialId)
                              throws tigase.db.TigaseDBException
        Specified by:
        removeCredential in interface tigase.db.AuthRepository
        Throws:
        tigase.db.TigaseDBException
      • removeData

        public void removeData​(tigase.xmpp.jid.BareJID user,
                               java.lang.String key)
                        throws tigase.db.UserNotFoundException,
                               tigase.db.TigaseDBException
        Specified by:
        removeData in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • removeData

        public void removeData​(tigase.xmpp.jid.BareJID user,
                               java.lang.String subnode,
                               java.lang.String key)
                        throws tigase.db.UserNotFoundException,
                               tigase.db.TigaseDBException
        Specified by:
        removeData in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • removeSubnode

        public void removeSubnode​(tigase.xmpp.jid.BareJID user,
                                  java.lang.String subnode)
                           throws tigase.db.UserNotFoundException,
                                  tigase.db.TigaseDBException
        Specified by:
        removeSubnode in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • removeUser

        public void removeUser​(tigase.xmpp.jid.BareJID user)
                        throws tigase.db.UserNotFoundException,
                               tigase.db.TigaseDBException
        Specified by:
        removeUser in interface tigase.db.AuthRepository
        Specified by:
        removeUser in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • setAccountStatus

        public void setAccountStatus​(tigase.xmpp.jid.BareJID user,
                                     tigase.db.AuthRepository.AccountStatus status)
                              throws tigase.db.TigaseDBException
        Specified by:
        setAccountStatus in interface tigase.db.AuthRepository
        Throws:
        tigase.db.TigaseDBException
      • setData

        public void setData​(tigase.xmpp.jid.BareJID user,
                            java.lang.String key,
                            java.lang.String value)
                     throws tigase.db.UserNotFoundException,
                            tigase.db.TigaseDBException
        Specified by:
        setData in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • setData

        public void setData​(tigase.xmpp.jid.BareJID user,
                            java.lang.String subnode,
                            java.lang.String key,
                            java.lang.String value)
                     throws tigase.db.UserNotFoundException,
                            tigase.db.TigaseDBException
        Specified by:
        setData in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • setDataList

        public void setDataList​(tigase.xmpp.jid.BareJID user,
                                java.lang.String subnode,
                                java.lang.String key,
                                java.lang.String[] list)
                         throws tigase.db.UserNotFoundException,
                                tigase.db.TigaseDBException
        Specified by:
        setDataList in interface tigase.db.UserRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • setDataSource

        public void setDataSource​(MongoDataSource dataSource)
        Specified by:
        setDataSource in interface tigase.db.DataSourceAware<MongoDataSource>
      • updateCredential

        public void updateCredential​(tigase.xmpp.jid.BareJID user,
                                     java.lang.String credentialId,
                                     java.lang.String password)
                              throws tigase.db.TigaseDBException
        Specified by:
        updateCredential in interface tigase.db.AuthRepository
        Throws:
        tigase.db.TigaseDBException
      • updatePassword

        public void updatePassword​(tigase.xmpp.jid.BareJID user,
                                   java.lang.String password)
                            throws tigase.db.UserNotFoundException,
                                   tigase.db.TigaseDBException
        Specified by:
        updatePassword in interface tigase.db.AuthRepository
        Throws:
        tigase.db.UserNotFoundException
        tigase.db.TigaseDBException
      • updateSchema

        public tigase.db.util.SchemaLoader.Result updateSchema​(java.util.Optional<tigase.util.Version> oldVersion,
                                                               tigase.util.Version newVersion)
                                                        throws tigase.db.TigaseDBException
        Specified by:
        updateSchema in interface tigase.db.util.RepositoryVersionAware
        Throws:
        tigase.db.TigaseDBException
      • userExists

        public boolean userExists​(tigase.xmpp.jid.BareJID user)
        Specified by:
        userExists in interface tigase.db.UserRepository