Skip to content

Commit

Permalink
Add authenticate() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
gk-brown committed Nov 2, 2024
1 parent 9f6850d commit ece4365
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ The connection is opened via a data source identified by `getDataSourceName()`,

Auto-commit is disabled so an entire request will be processed within a single transaction. If the request completes successfully, the transaction is committed. Otherwise, it is rolled back.

### Authentication
Services that require authentication can override the following method, which returns `true` by default:

```java
protected boolean authenticate(HttpServletRequest request, HttpServletResponse response) { ... }
```

If this method returns `false`, the requested operation will not be performed.

### Request and Repsonse Properties
The following methods provide access to the request and response objects associated with the current invocation:

Expand Down
22 changes: 21 additions & 1 deletion kilo-server/src/main/java/org/httprpc/kilo/WebService.java
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,11 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
setConnection(connection);

try {
invoke(request, response);
if (authenticate(request, response)) {
invoke(request, response);
}

response.flushBuffer();

if (connection != null) {
if (response.getStatus() / 100 == 2) {
Expand Down Expand Up @@ -911,6 +915,22 @@ protected String getDataSourceName() {
return null;
}

/**
* Authenticates a service request.
*
* @param request
* The HTTP servlet request.
*
* @param response
* The HTTP servlet response.
*
* @return
* {@code true} if the request was authenticated; {@code false}, otherwise.
*/
protected boolean authenticate(HttpServletRequest request, HttpServletResponse response) {
return true;
}

/**
* Invokes a service method.
*
Expand Down

0 comments on commit ece4365

Please sign in to comment.