public class TigaseCustomAuth extends Object implements AuthRepository
{ call
then the server
assumes this is a stored procedure call, otherwise it is executed as a plain
SQL query. Each configuration value is stripped from white characters on both
ends before processing.
Please don't use semicolon ';'
at the end of the query as many
JDBC drivers get confused and the query may not work for unknown obvious
reason.
Some queries take arguments. Arguments are marked by question marks
'?'
in the query. Refer to the configuration parameters
description for more details about what parameters are expected in each
query.
Example configuration.
The first example shows how to put a stored procedure as a query with 2
required parameters.
add-user-query={ call TigAddUserPlainPw(?, ?) }The same query with plain SQL parameters instead:
add-user-query=insert into users (user_id, password) values (?, ?)Created: Sat Nov 11 22:22:04 2006
Repository.Meta
Modifier and Type | Field and Description |
---|---|
static String |
DEF_ADDUSER_KEY
Query adding a new user to the database.
|
static String |
DEF_ADDUSER_QUERY
Field description
|
static String |
DEF_CONNVALID_KEY
Query executing periodically to ensure active connection with the database.
|
static String |
DEF_DELUSER_KEY
Removes a user from the database.
|
static String |
DEF_DELUSER_QUERY
Field description
|
static String |
DEF_DISABLEACCOUNT_KEY |
static String |
DEF_DISABLEACCOUNT_QUERY |
static String |
DEF_ENABLEACCOUNT_KEY |
static String |
DEF_ENABLEACCOUNT_QUERY |
static String |
DEF_GETPASSWORD_KEY
Retrieves user password from the database for given user_id (JID).
|
static String |
DEF_GETPASSWORD_QUERY
Field description
|
static String |
DEF_INITDB_KEY
Database initialization query which is run after the server is started.
|
static String |
DEF_INITDB_QUERY
Field description
|
static String |
DEF_LISTDISABLEDACCOUNTS_KEY |
static String |
DEF_LISTDISABLEDACCOUNTS_QUERY |
static String |
DEF_NONSASL_MECHS
Field description
|
static String |
DEF_NONSASL_MECHS_KEY
Comma separated list of NON-SASL authentication mechanisms.
|
static String |
DEF_SASL_MECHS
Field description
|
static String |
DEF_SASL_MECHS_KEY
Comma separated list of SASL authentication mechanisms.
|
static String |
DEF_UPDATEPASSWORD_KEY
Updates (changes) password for a given user_id (JID).
|
static String |
DEF_UPDATEPASSWORD_QUERY
Field description
|
static String |
DEF_USERLOGIN_KEY
Performs user login.
|
static String |
DEF_USERLOGIN_QUERY
Field description
|
static String |
DEF_USERLOGOUT_KEY
This query is called when user logs out or disconnects.
|
static String |
DEF_USERLOGOUT_QUERY
Field description
|
static String |
DEF_USERS_COUNT_KEY
Field description
|
static String |
DEF_USERS_COUNT_QUERY
Field description
|
static String |
DEF_USERS_DOMAIN_COUNT_KEY
Field description
|
static String |
DEF_USERS_DOMAIN_COUNT_QUERY
Field description
|
static String |
NO_QUERY |
static String |
SP_STARTS_WITH
Field description
|
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, USERNAME_KEY
Constructor and Description |
---|
TigaseCustomAuth() |
Modifier and Type | Method and Description |
---|---|
void |
addUser(BareJID user,
String password)
Describe
addUser method here. |
boolean |
digestAuth(BareJID user,
String digest,
String id,
String alg)
Deprecated.
|
protected String |
getParamWithDef(Map<String,String> params,
String key,
String def) |
String |
getPassword(BareJID user) |
String |
getResourceUri()
getResourceUri method returns database connection string. |
long |
getUsersCount()
getUsersCount method is thread safe. |
long |
getUsersCount(String domain)
This method is only used by the server statistics component to report
number of registered users for given domain.
|
void |
initRepository(String connection_str,
Map<String,String> params)
The method is called to initialize the data repository.
|
boolean |
isUserDisabled(BareJID user) |
void |
logout(BareJID user)
Describe
logout method here. |
boolean |
otherAuth(Map<String,Object> props)
Describe
otherAuth method here. |
boolean |
plainAuth(BareJID user,
String password)
Deprecated.
|
void |
queryAuth(Map<String,Object> authProps)
queryAuth returns mechanisms available for authentication. |
void |
removeUser(BareJID user)
Describe
removeUser method here. |
void |
setUserDisabled(BareJID user,
Boolean value) |
void |
updatePassword(BareJID user,
String password)
Describe
updatePassword method here. |
public static final String DEF_CONNVALID_KEY
select 1
public static final String DEF_INITDB_KEY
update tig_users set online_status = 0
public static final String DEF_ADDUSER_KEY
(user_id (JID), password)
Example query:
insert into tig_users (user_id, user_pw) values (?, ?)
public static final String DEF_DELUSER_KEY
(user_id (JID))
Example query:
delete from tig_users where user_id = ?
public static final String DEF_GETPASSWORD_KEY
(user_id (JID))
Example query:
select user_pw from tig_users where user_id = ?
public static final String DEF_UPDATEPASSWORD_KEY
(password, user_id (JID))
Example query:
update tig_users set user_pw = ? where user_id = ?
public static final String DEF_USERLOGIN_KEY
user-login-query
or get-password-query
.
If both queries are defined then user-login-query
is used.
Normally this method should be only used with plain text password
authentication or sasl-plain.
The Tigase server expects a result set with user_id to be returned from the
query if login is successful and empty results set if the login is
unsuccessful.
Takes 2 arguments: (user_id (JID), password)
Example query:
select user_id from tig_users where (user_id = ?) AND (user_pw = ?)
public static final String DEF_USERLOGOUT_KEY
(user_id (JID))
Example query:
update tig_users, set online_status = online_status - 1 where user_id = ?
public static final String DEF_USERS_COUNT_KEY
public static final String DEF_USERS_DOMAIN_COUNT_KEY
public static final String DEF_LISTDISABLEDACCOUNTS_KEY
public static final String DEF_DISABLEACCOUNT_KEY
public static final String DEF_ENABLEACCOUNT_KEY
public static final String DEF_NONSASL_MECHS_KEY
password
and digest
.
digest
mechanism can work only with
get-password-query
active and only when password are stored in
plain text format in the database.public static final String DEF_SASL_MECHS_KEY
PLAIN
, DIGEST-MD5
, CRAM-MD5
.
"Non-PLAIN" mechanisms will work only with the
get-password-query
active and only when passwords are stored
in plain text format in the database.public static final String NO_QUERY
public static final String DEF_INITDB_QUERY
public static final String DEF_ADDUSER_QUERY
public static final String DEF_DELUSER_QUERY
public static final String DEF_GETPASSWORD_QUERY
public static final String DEF_UPDATEPASSWORD_QUERY
public static final String DEF_USERLOGIN_QUERY
public static final String DEF_USERLOGOUT_QUERY
public static final String DEF_USERS_COUNT_QUERY
public static final String DEF_USERS_DOMAIN_COUNT_QUERY
public static final String DEF_LISTDISABLEDACCOUNTS_QUERY
public static final String DEF_DISABLEACCOUNT_QUERY
public static final String DEF_ENABLEACCOUNT_QUERY
public static final String DEF_NONSASL_MECHS
public static final String DEF_SASL_MECHS
public static final String SP_STARTS_WITH
public void addUser(BareJID user, String password) throws UserExistsException, TigaseDBException
AuthRepository
addUser
method here.addUser
in interface AuthRepository
user
- a BareJID
valuepassword
- a String
valueUserExistsException
- if an error occursTigaseDBException
- if an error occurs@Deprecated public boolean digestAuth(BareJID user, String digest, String id, String alg) throws UserNotFoundException, TigaseDBException, AuthorizationException
AuthRepository
digestAuth
method performs non-sasl, digest authentication
as described in non-sasl authentication
XEP-0078
For now it is empty and always returns false
as I don't
have description for database with passwords.digestAuth
in interface AuthRepository
user
- a BareJID
value of user namedigest
- a String
value password digest sumid
- a String
value session ID used for digest sum
calculation.alg
- a String
value of algorithm ID used for digest sum
calculation.boolean
value true
on successful
authentication, false
on authentication failure.UserNotFoundException
- if an given user name is not found in
the authentication repository.TigaseDBException
- if an error occurs during during accessing
database;AuthorizationException
- if an error occurs during authentication
process.public String getResourceUri()
AuthRepository
getResourceUri
method returns database connection string.getResourceUri
in interface AuthRepository
String
value of database connection string.public long getUsersCount()
getUsersCount
method is thread safe. It uses local variable
for storing Statement
.getUsersCount
in interface AuthRepository
long
number of user accounts in database.public long getUsersCount(String domain)
AuthRepository
getUsersCount
in interface AuthRepository
long
number of registered users in the repository.public void initRepository(String connection_str, Map<String,String> params) throws DBInitException
Repository
resource_uri
parameter as the database connection string or via params
map if
the required repository parameters are more complex or both.initRepository
in interface Repository
connection_str
- value in most cases representing the database connection string.params
- is a Map
with repository properties necessary to initialize
and perform all the functions. The initialization parameters are implementation dependent.DBInitException
- if there was an error during repository initialization.
Some implementations, though, perform so called lazy initialization so even though there
is a problem with the underlying repository it may not be signaled through this method
call.public void logout(BareJID user) throws UserNotFoundException, TigaseDBException
AuthRepository
logout
method here.logout
in interface AuthRepository
user
- a BareJID
valueUserNotFoundException
- if an error occursTigaseDBException
- if an error occurspublic boolean otherAuth(Map<String,Object> props) throws UserNotFoundException, TigaseDBException, AuthorizationException
AuthRepository
otherAuth
method here.otherAuth
in interface AuthRepository
props
- a Map
valueboolean
valueUserNotFoundException
- if an error occursTigaseDBException
- if an error occursAuthorizationException
- if an error occurs@Deprecated public boolean plainAuth(BareJID user, String password) throws UserNotFoundException, TigaseDBException, AuthorizationException
AuthRepository
plainAuth
method performs non-sasl, plain authentication
as described in non-sasl authentication
XEP-0078.plainAuth
in interface AuthRepository
user
- a BareJID
value of user namepassword
- a String
value of plain user password.boolean
value true
on successful
authentication, false
on authentication failure.UserNotFoundException
- if an given user name is not found in
the authentication repository.TigaseDBException
- if an error occurs during during accessing
database;AuthorizationException
- if an error occurs during authentication
process.public void queryAuth(Map<String,Object> authProps)
AuthRepository
queryAuth
returns mechanisms available for authentication.queryAuth
in interface AuthRepository
authProps
- a Map
value with parameters for authentication.public void removeUser(BareJID user) throws UserNotFoundException, TigaseDBException
AuthRepository
removeUser
method here.removeUser
in interface AuthRepository
user
- a BareJID
valueUserNotFoundException
- if an error occursTigaseDBException
- if an error occurspublic void updatePassword(BareJID user, String password) throws UserNotFoundException, TigaseDBException
AuthRepository
updatePassword
method here.updatePassword
in interface AuthRepository
user
- a BareJID
valuepassword
- a String
valueUserNotFoundException
TigaseDBException
- if an error occurspublic String getPassword(BareJID user) throws UserNotFoundException, TigaseDBException
getPassword
in interface AuthRepository
UserNotFoundException
TigaseDBException
public boolean isUserDisabled(BareJID user) throws UserNotFoundException, TigaseDBException
isUserDisabled
in interface AuthRepository
UserNotFoundException
TigaseDBException
public void setUserDisabled(BareJID user, Boolean value) throws UserNotFoundException, TigaseDBException
setUserDisabled
in interface AuthRepository
UserNotFoundException
TigaseDBException
Copyright © 2018 "Tigase, Inc.". All rights reserved.