Skip to content

Instantly share code, notes, and snippets.

@wailwinphyo2020
Last active November 29, 2022 10:39
Show Gist options
  • Save wailwinphyo2020/e34ed2aec6ef524161a247275235966e to your computer and use it in GitHub Desktop.
Save wailwinphyo2020/e34ed2aec6ef524161a247275235966e to your computer and use it in GitHub Desktop.
admins = [
'admin@tamron.chat'
]
'config-type' = 'default'
debug = [ 'server' ]
'default-virtual-host' = 'tamron.chat'
dataSource () {
default () {
uri = 'mongodb://tigase:password@172.18.0.2/tigasedb?authMechanism=SCRAM-SHA-1&authSource=admin&autoCreateUser=true'
}
}
authRepository {
default () {
cls = 'tigase.db.custom.MyAuthProvider'
}
}
package tigase.db.custom;
import tigase.auth.credentials.Credentials;
import tigase.db.*;
import tigase.db.ldap.LdapAuthProvider;
import tigase.xmpp.jid.BareJID;
import java.time.Duration;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@Repository.Meta(isDefault = true, supportedUris = {"jdbc:[^:]+:.*"})
@Repository.SchemaId(id = Schema.SERVER_SCHEMA_ID, name = Schema.SERVER_SCHEMA_NAME)
public class MyAuthProvider implements AuthRepository {
protected static final String[] non_sasl_mechs = {"password"};
protected static final String[] sasl_mechs = {"PLAIN"};
private static final Logger log = Logger.getLogger(MyAuthProvider.class.getName());
@Override
public Credentials getCredentials(BareJID user, String credentialId) throws TigaseDBException {
final String db_password = getPassword(user);
System.out.println("######################################################");
System.out.println("Password : " + db_password);
System.out.println("######################################################");
Credentials.Entry entry = new Credentials.Entry() {
@Override
public String getMechanism() {
return "PLAIN";
}
@Override
public boolean verifyPlainPassword(String plain) {
try {
return true;
} catch (Exception ex) {
log.log(Level.WARNING, "Can''t authenticate user", ex);
}
return false;
}
};
return new SingleCredential(user, getAccountStatus(user), entry);
}
@Override
public void addUser(BareJID user, String password) throws TigaseDBException {
throw new TigaseDBException("Not available");
}
@Override
public AccountStatus getAccountStatus(BareJID user) throws TigaseDBException {
return AccountStatus.active;
}
@Override
public String getPassword(BareJID user) throws TigaseDBException {
throw new TigaseDBException("Not available");
}
@Override
public String getResourceUri() {
return null;
}
@Override
public long getUsersCount() {
return -1;
}
@Override
public long getUsersCount(String domain) {
return -1;
}
@Override
public void loggedIn(BareJID jid) throws TigaseDBException {
}
@Override
public void logout(BareJID user) throws TigaseDBException {
}
@Override
public boolean otherAuth(Map<String, Object> authProps) throws TigaseDBException, AuthorizationException {
return false;
}
@Override
public void queryAuth(Map<String, Object> authProps) {
String protocol = (String) authProps.get(PROTOCOL_KEY);
if (protocol.equals(PROTOCOL_VAL_NONSASL)) {
authProps.put(RESULT_KEY, non_sasl_mechs);
}
if (protocol.equals(PROTOCOL_VAL_SASL)) {
authProps.put(RESULT_KEY, sasl_mechs);
}
}
@Override
public void removeUser(BareJID user) throws TigaseDBException {
throw new TigaseDBException("Not available");
}
@Override
public void setAccountStatus(BareJID user, AccountStatus status) throws TigaseDBException {
throw new TigaseDBException("Feature not supported");
}
@Override
public void updatePassword(BareJID user, String password) throws TigaseDBException {
throw new TigaseDBException("Not available");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment