Java Project Single Sign-on Discuz

Source: Internet
Author: User

First, demand analysis

A Java project and a discuz forum need to be integrated to enable single sign-on functionality between them. But Discuz is written by PHP, the two languages do not know how to integrate it? The official information found that Discuz was not open to say what the user interface and so on. But found the goods ucenter, apparently this goods and Discuze is a family. So, the next integration we are going to use ucenter as middleware to implement the user sharing between non-language projects.


Second, about Ucenter

Before I introduce the method, I think it is necessary to talk about Ucenter first and understand how it works.

Ucenter's Chinese meaning is "User Center", where U represents user, also represents you, the meaning is "User Center", or "You (end user) of the center." Ucenter is a bridge of information transfer between the various products of Comsenz in the future. Through Ucenter, stationmaster can seamlessly integrate Comsenz series products, even more third-party applications, realize the user's one-stop login and the unified management of personal information, points and other information.

The above is the official introduction, plainly speaking, it is a bridge. For example a application in the user login, notify Ucenter, and then ucenter this message to B AH C ah, and so on other applications, thus achieving a single sign-on. If you're too tired, take a look at the picture below (go to the network):

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/C8/wKiom1ThRLaj6N6aAAC75IFJVWk495.jpg "title=" 9.png " alt= "Wkiom1thrlaj6n6aaac75ifjvwk495.jpg"/>

Well, that's probably the process. The user logs in and sends a notification to the Ucenter Service. The ucenter then pushes the message to another application, the app accepts the message settings cookie, and so on, realizes the synchronous login, the logout.


Iii. steps of the method

1. Set Ucenter:

In the finished discuz, we will generally check the synchronization installation Ucenter, then you can from the Discuz backstage, login to the ucenter background to set up,

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/C8/wKiom1ThRnfQD6XMAAE58r3YW5A079.jpg "title=" 1.png " alt= "Wkiom1thrnfqd6xmaae58r3yw5a079.jpg"/>

Or you can enter http://localhost (or IP)/uc_server to jump to the login page. Select the administrator login, the account password is the Administrator account password Discuz management background.

However, there will be a small bug here. Discuz after upgrading to version 3.x, there is no response to login here. The official community has provided a solution, in fact very simple, as long as the modification of the admin.php file can be. And the file is in the uc_server/model/admin.php of your project.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/C8/wKiom1ThR-mQeoLpAAV_1IpWo0U087.jpg "title=" 2.png " alt= "Wkiom1thr-mqeolpaav_1ipwo0u087.jpg"/>

Information in the red box after opening the file:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/C4/wKioL1ThSUvhQH9VAAIDuH_c30Y675.jpg "title=" 3.png " alt= "Wkiol1thsuvhqh9vaaiduh_c30y675.jpg"/>

Well, after modification, save to log back in again OK.

2, Ucenter background application settings

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/C8/wKiom1ThSSeDzwIbAAGIMVtU_ck789.jpg "title=" 4.png " alt= "Wkiom1thssedzwibaagimvtu_ck789.jpg"/>

You can see the Discuz app with ID 1 in app Management, and all you have to do is add the other apps you want to integrate on this platform.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/C4/wKioL1ThSoCR4BBEAAMltGWTlaY130.jpg "title=" 5.png " alt= "Wkiol1thsocr4bbeaamltgwtlay130.jpg"/>

Fill in, there are some comments, if you still do not know, please poke here: http://faq.comsenz.com/library/UCenteruse/useuse/useuse_addapp.htm official tutorial.

Once added, you will see Application management in the following example:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/C8/wKiom1ThSi-hKetwAAKERXeURpU547.jpg "title=" 6.png " alt= "Wkiom1thsi-hketwaakerxeurpu547.jpg"/>

More apps, keep in mind the ID of this new app and the communication key that was previously added when it will be used. And on the right display communication failure is normal, MO panic, because your other application has not started, not configured AH!

3, the file configuration in the new application

This new application, is to integrate the Java project. First, look here: http://faq.comsenz.com/library/UCenter/introduction/introduction_interface.htm This is an open Ucenter development interface for the Discuz community , unfortunately, the example is also written in PHP. But already someone has written a Java version of the interface according to the interface, called: Discuz-ucenter_api_for_java. The example of this article is also implemented by it, the demo structure is as follows.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/C8/wKiom1ThTRLQBYzpAAGVjVOw9jQ856.jpg "title=" 10.png "alt=" Wkiom1thtrlqbyzpaagvjvow9jq856.jpg "/>

Good Let's start by modifying the most important configuration file: Config.properties (This is the profile in the demo project, depending on how you integrate the changes into your project, such as when I integrate into my own project and then the Application.properties file)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/C5/wKioL1ThTo3yuh9AAAPyA4Om6u8603.jpg "title=" 7.png " alt= "Wkiol1thto3yuh9aaapya4om6u8603.jpg"/>

UC_API is your Discuz project Ucenter accept the information address (not necessarily the IP address, you can make your domain name address), this address will have a uc.php File receive processing information.

UC_IP is to prevent your project domain name from being parsed incorrectly while writing the actual IP address.

Uc_key is the communication key that adds the app when you add a new app in Ucenter Admin.

Uc_appid is the ID of the app Oh ~ before a reminder oh.

Of course, there is a configuration to do, and that is your Web. xml file:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/C5/wKioL1ThUC7ifu-1AAQLBqGzB6U818.jpg "title=" 8.png " alt= "Wkiol1thuc7ifu-1aaqlbqgzb6u818.jpg"/>

Are configured, we start testing. And so on, still have to say, uc.java this is actually processing ucenter send the information. The Phpfuctions.java is the processing class that the application sends the request to Ucenter. In the demo, we can analyze and see.

4. Test results

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/C5/wKioL1ThU6zwU8gbAAD5--FZOa0945.jpg "title=" 11.png "alt=" Wkiol1thu6zwu8gbaad5--fzoa0945.jpg "/>

Run Jsp_ demo.jsp file Oh, remember your first registration number Notice Ucenter, here is a doubt: when you register, Ucenter database is a new user, but it did not notify Discuz,discuz but no new user data, so the first registration and failed to sync to the user, need to new users to Discuz Once logged in, the user data can be synchronized with each other.

When you log in successfully, you will find the JS code returned by the paragraph: 650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M00/59/C5/ Wkiol1thvk2ynt7haafxhk2uycu102.jpg "title=" 12.png "alt=" Wkiol1thvk2ynt7haafxhk2uycu102.jpg "/>

Yes, this JS code is once again send a request to Ucenter told him, "Man, I have been properly logged in, modified the cookie those, trouble you with other guys say, let them also synchronize with me." So it's important to say this JS code. If it returns an error or requests a communication failure, it will not be possible to implement the app synchronization.

5, the demo of this article has made some changes to the original interface, the perfect solution to the Chinese registration, login and other issues.


Third, conclusion

The Chinese New Year is coming soon, this is the last blog post, writing a little hasty. Bless everyone in advance, Happy New Year! In the new year, step by step to Daniel Road. Or the original sentence: Sharing is a kind of happiness, perseverance is a kind of spirit.


Since the article attachments can only be uploaded within 2M, I put the demo to Baidu network disk: HTTP://PAN.BAIDU.COM/S/1CUFHK



This article is from the "Learning and Thinking" blog, please be sure to keep this source http://linhongyu.blog.51cto.com/6373370/1614618

Java Project Single Sign-on Discuz

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.