DataSnap.Role Authorization Sample

From Appmethod Code Examples
Jump to: navigation, search

This sample demonstrates User Role Authorization.

Location

You can find the Role Authorization sample project at:

Description

The User Role Authorization application shows:

  • The user authorization roles.
  • How to create a DataSnap role authorization server and clients that can connect to it.
  • How to create a DataSnap HTTP to TCP tunneling server.

How to Use the Sample

The User Role Authorization application is structured in two major parts; the client(s) and the server.

How to Use the Server

There are two server projects; one of them is called AuthServerProject and the other one is called TunnelServerProject.

  1. Navigate to Start | Programs | Appmethod 1.14 | Samples and go to Object Pascal\DataSnap\Authorization.
  2. Open the AuthServerProject.dproj project.
  3. Build the AuthServerProject.dproj project.
  4. Run the application by selecting the Run > Run menu from within the IDE, or by hitting F9.
  5. Add, edit or remove user roles. Observe the user interface, click on the Display Server Methods button to display a list of available server methods.
  6. Navigate to Start | Programs | Appmethod 1.14 | Samples and go to Object Pascal\DataSnap\Authorization.
  7. Open the TunnelServerProject.dproj project.
  8. Build the TunnelServerProject.dproj project.
  9. Run the application by selecting the Run > Run menu from within the IDE, or by hitting F9.
  10. Make sure the Port is set as 8082, Host is localhost, and TCP/IP port is 211.
  11. Start the HTTP to TCP tunnel server via the Start HTTP button.

How to Use the Client(s)

There are two sample clients that can be used with the User Role Authorization application. The clients are called SimpleDelphiClient and SimpleDelphiRestClient. They can be used with the role authorization server, at the same time.

  1. Navigate to Start | Programs | Appmethod 1.14 | Samples and go to Object Pascal\DataSnap\Authorization.
  2. Open the SimpleDelphiClient.dproj project.
  3. Build the SimpleDelphiClient.dproj project.
  4. Run the application by selecting the Run > Run menu from within the IDE, or by hitting F9.
  5. Navigate to Start | Programs | Appmethod 1.14 | Samples and go to Object Pascal\DataSnap\Authorization.
  6. Open the SimpleDelphiRestClient.dproj project.
  7. Build the SimpleDelphiRestClient.dproj project.
  8. Run the application by selecting the Run > Run menu from within the IDE, or by hitting F9.

How to Use the Client(s) with the Server

When you have all four applications running, you can see how they work together:

  1. Switch to the Object Pascal DataSnap Client running application.
  2. Set the Protocol as TCP/IP and the Port to 211.
  3. Click the ReverseString button and observe the results in the log window. You can change the string to be reversed at any time and try again.
  4. Switch to the Role Authorization Test Server running application and stop HTTP, but leave TCP active.
  5. Switch to the DataSnap HTTP to TCP tunnel server running application. Make sure the HTTP listener port is 8082, Host is localhost and TCP/IP port is 211.
  6. Switch back to the Object Pascal DataSnap Client running application.
  7. Set the Protocol as HTTP and the Port as 8082.
  8. Hit ReverseString and observe the results. Then close the connection using the Close Connection button.
  9. Switch back to the Role Authorization Test Server running application and re-enable the HTTP listening on port 8081.
  10. Now switch to the Object Pascal DataSnap REST Client running application.
  11. This application cannot connect via TCP so only HTTP options are viable. Set the Port to 8081. Then test the connection.
  12. Hit ReverseString and observe the results.
  13. Again, switch to the Role Authorization Test Server running application and stop HTTP, but leave TCP active.
  14. Go back to the Object Pascal DataSnap REST Client application and select the Port as 8082.
  15. Press ReverseString and the connection is done through the tunnel.

Files

The files for this sample include:

Role Authorization Test Server files

File Contains

AuthServerProject

The Role Authorization Test Server project.

FormUnit

The main form that is the user interface for the Role Authorization Test Server.

RoleItemFormUnit

The form that is the Role Item dialog box.

UserRoleItemFormUnit

The form that is the User / Role dialog box.

ServerContainerUnit1

The server container for the Role Authorization Test Server project.

ServerMethodsUnit1

Server methods available on the Role Authorization Test Server.

ServerUtils

Various server utilities.

UsersAndRoles

Various user and roles describing classes.

SimpleServerClass

The server class definition and implementation.

HTTP to TCP Tunnel Server files

File Contains

TunnelServerProject

The DataSnap HTTP to TCP Tunnel Server project.

TunnelServerContainerUnit

The server container for the DataSnap HTTP to TCP Tunnel Server project.

TunnelServerFormUnit

The main form that is the user interface for the DataSnap HTTP to TCP Tunnel Server.

DataSnap Client files

File Contains

SimpleDelphiClient

The Object Pascal DataSnap Client project.

SimpleClientFormUnit

The main form that is the user interface for the Object Pascal DataSnap Client.

DataSnap REST Client files

File Contains

SimpleDelphiRestClient

The Object Pascal DataSnap REST Client project.

SimpleRestClientFormUnit

The main form that is the user interface for the Object Pascal DataSnap REST Client.

Classes

  • TServerMethods1 implements the server methods available for Role Authorization Test Server.
  • TUserRoleItem implements an user role.
  • TUserRoleItems implements a collection of user roles.

Note: Major parts of program functionality are implemented directly inside the main forms that also hold visual components. See the source code for details.

Uses

See Also