• No results found

Project Structure

In document A secure mobile social network (Page 53-56)

8. Server Implementation

8.2 Project Structure

In the server side implementation, we have separated the project into several parts. The first part is used to communicate with the BSF to execute the GBA protocol and implement the HTTP Digest. The second part is used to define the resources and the resource structure.

In the second part, the JAXB annotation of the XmlRootElement has been used to serialise the resource structure so the output of the resource can be presented in a

XML format. Take user info as an example, we could simply define a UserInfo class, and a userName, impu are the attributes. The code 8-2 illustrates the class of UserInfo, and the table 8-2 shows the output of the XML structure of different resources.

@XmlRootElement class UserInfo {

private String userName; private String impu;

UserInfo(String _userName, String _impu) {userName=_userName; impu=_impu;} }

Code Code

CodeCode 8-28-28-28-2 UserInfoUserInfoUserInfoUserInfo ExampleExampleExampleExample

Six resources have been defined in the second part, they are userInfo, groupInfo, pendingInviteInfo, groupRoleInfo, memberGroupRoleInfo and memberRoleInfo. UserInfo, groupInfo and pendingInviteInfo deliver user information, group information, online pending invitation information. Table 8-2 simply shows the six resources and the XML structure of these resources.

Table Table

The third part of the project is a connector to establish a bridge between the web server and the database. When a client sends a request to view or manipulate the resource, this part of the project is invoked. For example, a server receives a delete request from a client that is the owner of a group and he/she wants to delete the group. Consequently, all the group members have to be removed from the group. The function below belongs to one of the connector classes called GroupService, and the class will be instantiated in the serverRest part that is the fourth part of the project and the function below will be invoked so that all the members can be removed from the group. In the example code 8-6-2-A, “delete_group_by_owner” is a stored procedure that checks the membership of the owner and that removes all the members from the group, so that the members cannot update their membership assertion from the MSNP after the group has been removed.

public void deleteGroupByOwner(String groupName, String ownerName) throws SQLException {

procedure = connection.prepareCall("{CALL delete_group_by_owner(?,?)}"); procedure.setString(1, groupName); procedure.setString(2, ownerName); procedure.execute(); procedure.close(); } Example Example

ExampleExample codecodecodecode 8888----66----266 222-A-A-A-A:::: AAAA connectorconnectorconnectorconnector betweenbetweenbetweenbetween thethethethe serverserverserver andserverandandand thethethethe database.database.database.database.

The fourth part is delivering the REST web service, so the server could respond according to the client request. JAX-RS defines annotations that we have used in this part of the project. The code example 8-6-2-B explains how the REST service works. Every user is allowed to obtain his/her own information. When a REST server receives a request from a client to retrieve the user's own information, the server will check whether the user has the right to send such a request. If yes, it will return the user's information. Otherwise, it returns empty information. The function of the below example code is used to implement a response for user Get request and verifies if the resource is going to be presented or not. The first annotation @Path(“/user”) shows the resource URI ishttp://localhost:8080/SwinServer/userand UserService has been instantiated so that REST web service could connect to the database. The second @Path shows the parameter that follows http://localhost:8080/SwinServer/user URI. @Produces annotation indicates the resource will present in XML and JSON format. The code after @Produces is used to set the user IMPU value based on what the BSF responded. The user name sent to the REST server and the IMPU value sent by the BSF would match the user name and the IMPU stored in the database, then the user information could be displayed to the client.

import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @Path("/user")

public class UserRest {

private static UserService userService = new UserService(); @GET

@Path("/{userName}")

@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public UserInfo getUser(@PathParam("userName") String userName) throws SQLException {

String userIMPU = AuthenticationFilter.USER_IMPU; return userService.checkUser(userName, userIMPU);} }

Example Example

ExampleExample codecodecodecode 8888----6666----2222-B-B-B-B :::: RESTRESTRESTREST serviceserviceserviceservice ofofofof useruseruseruser resource.resource.resource.resource.

The last part of the project contains all the different tools that may be utilized in the previous parts. The tools can be different XML parsers that disassembles the different resources from the XML structures documents to the normal text that can be displayed according to the mobile application interface design, so several XML resource handlers have been implemented. There is another tool that is used to connect the web server to the database, so the resource can be viewed and manipulated.

In document A secure mobile social network (Page 53-56)

Related documents