Use the Web service provided by Domino to verify users in Java applications

Source: Internet
Author: User
Implement a simple login function, enter the user name and password, and jump to the corresponding page correctly. If the error message is incorrect, the user here is verified in the domino names library.

The implementation method is roughly as follows: Domino provides a Web Service for user authentication. The parameters received are the user name and password, and then a simple user object is returned to the client, contains the username, email address, abbreviation, and correct password in the personal document of the Names Database. Call this web service in a Java application, parse the returned object, and perform page Jump Based on the object information.

1. XXX in Domino. NSF (preferably not written in the Names Database) creates a new Web Service Provider test in the database, which can be written in LotusScript or Java. Here we use the LotusScript, (options) Section:

Option public
% Include "lsxsd. lss"

In the (declarations) Section, the verification method is as follows:

Dim ss as notessession
Class dominouser' defines the objects returned to the client
Public userid as string
Public username as string
Public lastname as string
Public password as Boolean
Public email as string
End Class
Class wstest
Sub new
Set Ss = new notessession
End sub
Function getdominouserbyid (UID as string, PWD as string) as dominouser 'receives two parameters
Set getdominouserbyid = new dominouser
Dim dB as notesdatabase
Dim view as notesview
Dim doc as notesdocument
Set DB = ss. getdatabase ("Kenny", "names. nsf") 'matches the names Library
Set view = dB. getview ("selfperson ")
Set Doc = view. getdocumentbykey (UID) 'to obtain the personal document
If not Doc is nothing then ', the entered PWD parameter cannot be blank.
If ss. verifypassword (PWD, Doc. httppassword (0) then ', the Web Password is verified here.
Getdominouserbyid. Password = true
Else
Getdominouserbyid. Password = false
End if
Getdominouserbyid. userid = uid 'is equivalent to shortname
Getdominouserbyid. Username = Doc. fullname (0)
Getdominouserbyid. lastname = Doc. lastname (0)
Getdominouserbyid. Email = Doc. internetaddress (0)
End if
End Function
End Class

The data format returned by the service to the client is roughly as follows:

<Returnmethodvalue>
<Userid> XYZ </userid>
<Username> XXX </username>
<Lastname> XXX </lastname>
<Password> 1 </password>
<Email> XXX@xxx.com </Email>
</Returnmethodvalue>

2. Some settings are required for Web service attributes:

If the name is test, the URL is test? The WSDL and porttype classes are the class names of the implementation methods. They are equivalent to the Web service entry and must be specified.

Here, the security level can be set to 1. If you select this option, you have access permissions.

The SOAP message format is rpc/encoded.

3. Of course, make the externalProgramTo call this web service, you also need to have access permissions for the database and server:

The database ACL sets the anonymous user permission to at least the reader.

The preceding setting sets the Web service runtime security level to 1, so it is necessary to ensure that the server permits restricted proxy execution ,.

4. Create a Java Web project and create a simple logon interface. For the sake of simplicity, the presentation layer of this example uses JSF. The method in userbean corresponding to the response event of the logon button is as follows:

Public String loginactiondomino () throws malformedurlexception, exception {
URL url = new URL (http: // localhost/study/xxx. nsf/test? WSDL );
Client c = new client (URL );
Object [] Results = C. Invoke ("getdominouserbyid", new object [] {userid, password}); // method name, passing 2 parameters
Document OBJ = (document) Results [0]; // XML object returned by Web Service
/* If you do not know the format of the objects returned by WSDL, use this method to print and observe
Transformerfactory TF = transformerfactory. newinstance ();
Transformer T = TF. newtransformer ();
Bytearrayoutputstream Bos = new bytearrayoutputstream ();
T. Transform (New domsource (OBJ), new streamresult (BOS ));
String STR = Bos. tostring ("UTF-8 ");
System. Out. println (STR );*/
// Parse the DOM object
If (obj. getelementsbytagname ("userid"). Item (0). getfirstchild ()! = NULL)
This. userid = obj. getelementsbytagname ("userid"). Item (0). getfirstchild (). getnodevalue ();
If (obj. getelementsbytagname ("username"). Item (0). getfirstchild ()! = NULL)
This. Username = obj. getelementsbytagname ("username"). Item (0). getfirstchild (). getnodevalue ();
If (obj. getelementsbytagname ("password"). Item (0). getfirstchild ()! = NULL)
This. Password = obj. getelementsbytagname ("password"). Item (0). getfirstchild (). getnodevalue ();
If (obj. getelementsbytagname ("lastname"). Item (0). getfirstchild ()! = NULL)
This. lastname = obj. getelementsbytagname ("lastname"). Item (0). getfirstchild (). getnodevalue ();
If (obj. getelementsbytagname ("email"). Item (0). getfirstchild ()! = NULL)
This. Email = obj. getelementsbytagname ("email"). Item (0). getfirstchild (). getnodevalue ();
If (this. Username = NULL ){
Clear ();
This. errmsg = "the user name does not exist !!! ";
Return "deny ";
} Else if (this. Password. Equals ("0 ")){
Clear ();
This. errmsg = "Incorrect password !!! ";
Return "deny ";
} Else {
This. errmsg = "Logon successful !!! ";
Return "success ";
}
}

In addition, the call of web service here is xfire, so you need to put the xfire-all-1.2.6.jar package under the project.

5. Release the Java project to Tomcat, but also need to put the wsdl4j-1.6.1.jar and XmlSchema-1.2.jar of the two packages in the Tomcat library path, no will report an error. Access the project in IE and enter the user name and password for Logon verification:

After Successful Logon with the correct user in names:

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.