tigase用户集成

tigase官方说明

目前支持的有

At the moment the Tigase server offers following authentication connectors:

  • 'mysql''pgsql''derby' - standard authentication connector used to load user login data from the main user database used by the Tigase server. In fact the same physical implementation is used for all JDBC databases.
  • 'drupal' - is the authentication connector used to integrate the Tigase server with Drupal CMS.
  • 'libresource' - is the authentication connector used to integrate the Tigase server with Libresource Collaboration platform.
  • 'tigase-auth' - is the authentication connector which can be used with any database. It executes stored procedures to perform all actions. Therefore it is a very convenient way to integrate the server with an external database if you don't want to expose the database structure. You just have to provide a set of stored procedures in the database. While implementing all stored procedures expected by the server might be a bit of work it allows you to hide the database structure and change the SP implementation at any time. You can add more actions on user login/logout without restarting or touching the server. And the configuration on the server side is very simple. For detailed description of this implementation please refer to Tigase Auth documentation. 
  • 'tigase-custom' - is the authentication connector which can be used with any database. Unlike the 'tigase-auth' connector it allows you to define SQL queries in the configuration file. The advantage of this implementation is that you don't have to touch your database. You can use either simple plain SQL queries or stored procedures. The configuration is more difficult as you have to enter carefully all SQL queries in the config file and changing the query usually involves restarting the server. For more details about this implementation and all configuration parameters please refer to Tigase Custom Auth documentation.

http://www.tigase.org/content/custom-authentication-connectors


1.tigase-custom

需要处理:只需通过init.properties,配置用户数据库和对应的sql语句(或者存储过程)

缺点:很多业务系统都服务化,包括用户系统,直接sql访问有违服务化目的,也不易做进一步处理;

Tigase Custom Auth connector

http://www.tigase.org/content/tigase-custom-auth-connector

2.tigase-auth

至上需要写2个存储过程,

The absolute minimum of stored procedures you have to implement is:

  • TigUserLoginPlainPw - to perform user authentication. The procedure is always called when the user tries to login to the XMPP server. This is the only procedure which must be implemented and actually must work.
  • TigUserLogout - to perform user logout. The procedure is always called when the user logouts or disconnects from the server. This procedure must be implemented but it can be empty and can do nothing. It just needs to exist because Tigase expect it to exist and attempts to call it.

http://www.tigase.org/content/tigase-auth-connector

3.LDAP authentication connector

需要有LDAP服务,目前没有,对LDAP也不熟悉,也不做选择;

http://www.tigase.org/content/ldap-authentication-connector


4.implement tigase.db.AuthRepository 

看下jdbc的处理JDBCRepository.java;因为我们有统一的用户系统,选择使用rpc服务做验证;

http://www.tigase.org/node/1324

tigase默认用的是 TigaseCustomAuth,在getAuthRepository里被创建;

currently Tigase use "tigase.db.jdbc.TigaseCustomAuth" if no --auth-db was configured

禁用匿名认证

处理之前,先要了解下auth的机制,参考http://www.tigase.org/content/sasl-custom-mechanisms-and-configurationhttp://www.tigase.org/content/sasl-custom-mechanisms-and-configuration,tigase默认 

The factory which is available and registered by default is 'tigase.auth.TigaseSaslServerFactory' which provides PLAIN and ANONYMOUS mechanisms.

也没太搞明白匿名认证的作用,所以就把他先禁用了

http://my.oschina.net/greki/blog/213312

继承AuthRepository 接口;

纠结的是里面*Auth的3个方法;5.1的release说明,其他2个以备抛弃,全走otherAuth,

所有主要实现otherAuth方法。

但是如果你是覆盖TigaseCustomAuth,那就要注意跟其他方法数据库操作的兼容

主要是登录的时候,online_status要+1;看下原先的存储过程

http://www.tigase.org/content/tigase-xmpp-server-510-beta-3

流程

tigase用户集成

设置验证完自动创建用户

添加autoCreateUser=true

user-db-uri=jdbc:mysql://192.168.1.15:3306/tigasedb?user=tigase&password=tigase&useUnicode=true&characterEncoding=UTF-8&autoCreateUser=true

tigase自动创建流程在,JDBCRepository.java

(这里有个问题,主要默认创建的密码,密码为空的话,tig_users.account-status的状态为-1,禁用)

	private long getUserUID(DataRepository repo, BareJID user_id, boolean autoCreate)
					throws SQLException, UserNotFoundException {
		// OK
		long result = getUserUID(repo, user_id);
		if (result <= 0) {
			if (autoCreate) {
				// OK
				result = addUserRepo(repo, user_id);
			} else {
				throw new UserNotFoundException("User does not exist: " + user_id);
			}    // end of if (autoCreate) else
		}      // end of if (isnext) else
		return result;
	}

客户端登录成功,发送设置昵称等信息,主要通过iq设置vcard

<iq xmlns="jabber:client" type="set" id="aac6a">
<vCard xmlns="vcard-temp">
<NICKNAME>admin swr</NICKNAME>
</vCard>
</iq>

如何配置依赖的环境配置

以为要调用外部服务验证,也许你需要配置验证服务的地址等;

1.增加自定义配置项

直接在init.properties里配置,如--my-config-xxx=xxxx

通过System.getProperty("my-config-xxx");//调试发现的,不一定是最好的方式

2.借用--auth-db-uri

借用--auth-db-uri=http://xxxxxx配置自定义;

通过initRepository(final String connection_str, Map<String, String> params)

参数connection_str获取,当然这样就不能再根据connection_str创建连接user_db的repository了;

所以我采用的是第一种,来配置验证的,user_db依然保留,来实现查询用户数等其他方法;

开发工程搭建和调试

新建maven工程,依赖tigaseserver,配置启动类为Xmppserver.

需要拷贝几个cert、etc、scripts(可选)、jars到目录下;

设置参考:http://my.oschina.net/greki/blog/209538

tigase用户集成

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>


 <groupId>com.greenline.im</groupId>
 <artifactId>tigase-ext</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>


 <name>tigase</name>
 <url>http://maven.apache.org</url>
 
 <build>
 <plugins>
 
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <version>2.3.2</version>
 <configuration>
 <source>1.7</source>
 <target>1.7</target>
 </configuration>
 </plugin>
 <plugin>
 <groupId>org.apache.felix</groupId>
 <artifactId>maven-bundle-plugin</artifactId>
 <version>2.4.0</version>
 <extensions>true</extensions>
 <configuration>
 <instructions combine.inherited="append">
 <Implementation-Title>${project.name}</Implementation-Title>
 <Implementation-Version>${project.version}-b${gitVersion}/${buildNumber}</Implementation-Version>
 <Implementation-Build>${gitVersion}/${buildNumber} (${maven.build.timestamp})</Implementation-Build>
 <Bundle-Activator>tigase.archive.Activator</Bundle-Activator>
 <Bundle-SymbolicName>${project.artifactId};singleton=true</Bundle-SymbolicName>
 </instructions>
 </configuration>
 </plugin>
 </plugins>
 <resources>
 <resource>
 <directory>src/main/resources</directory>
 </resource>
 </resources>
 <extensions>
 <extension>
 <groupId>org.apache.maven.wagon</groupId>
 <artifactId>wagon-ssh-external</artifactId>
 <version>2.2</version>
 </extension>
 <extension>
 <groupId>org.apache.maven.wagon</groupId>
 <artifactId>wagon-ssh</artifactId>
 <version>2.2</version>
 </extension>
 </extensions>


 </build>
 <!--  <dependencyManagement>-->
 <dependencies>
 <dependency>
 <groupId>tigase</groupId>
 <artifactId>tigase-server</artifactId>
 <version>5.2.1-SNAPSHOT</version>
 <scope>provided</scope>
 </dependency>
 <dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-api</artifactId>
 <version>1.6.4</version>
 <scope>provided</scope>
 </dependency>
 <dependency>
 <groupId>org.apache.felix</groupId>
 <artifactId>org.osgi.core</artifactId>
 <version>1.4.0</version>
 <scope>provided</scope>
 <type>bundle</type>
 </dependency>
 <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>3.8.1</version>
 <scope>test</scope>
 </dependency>
 </dependencies>
 <repositories>
 <repository>
 <id>tigase</id>
 <name>Tigase repository</name>
 <url>http://maven.tigase.org</url>
 </repository>
 <repository>
 <id>tigase-snapshot</id>
 <name>Tigase repository</name>
 <url>http://build.xmpp-test.net/maven/</url>
 <snapshots>
 <enabled>true</enabled>
 </snapshots>
 </repository>
 </repositories>
 <distributionManagement>
 <repository>
 <id>tigase</id>
 <name>Tigase repository</name>
 <url>scp://maven.tigase.org:/home/webapp/maven-repository</url>
 </repository>
 <snapshotRepository>
 <id>tigase-snapshot</id>
 <name>Tigase snapshot repository</name>
 <url>scp://build.xmpp-test.net:/home/maven/repository</url>
 </snapshotRepository>
 </distributionManagement>
</project>

 
 
 
 
 
  
  
  
  

5.debug tigase

--debug=xmpp.XMPPIOService

http://www.tigase.org/tigase-debuging


你可能感兴趣的:(tigase用户集成)