Skip to content

Commit ece4365

Browse files
committed
Add authenticate() method.
1 parent 9f6850d commit ece4365

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ The connection is opened via a data source identified by `getDataSourceName()`,
240240

241241
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.
242242

243+
### Authentication
244+
Services that require authentication can override the following method, which returns `true` by default:
245+
246+
```java
247+
protected boolean authenticate(HttpServletRequest request, HttpServletResponse response) { ... }
248+
```
249+
250+
If this method returns `false`, the requested operation will not be performed.
251+
243252
### Request and Repsonse Properties
244253
The following methods provide access to the request and response objects associated with the current invocation:
245254

kilo-server/src/main/java/org/httprpc/kilo/WebService.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,11 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
845845
setConnection(connection);
846846

847847
try {
848-
invoke(request, response);
848+
if (authenticate(request, response)) {
849+
invoke(request, response);
850+
}
851+
852+
response.flushBuffer();
849853

850854
if (connection != null) {
851855
if (response.getStatus() / 100 == 2) {
@@ -911,6 +915,22 @@ protected String getDataSourceName() {
911915
return null;
912916
}
913917

918+
/**
919+
* Authenticates a service request.
920+
*
921+
* @param request
922+
* The HTTP servlet request.
923+
*
924+
* @param response
925+
* The HTTP servlet response.
926+
*
927+
* @return
928+
* {@code true} if the request was authenticated; {@code false}, otherwise.
929+
*/
930+
protected boolean authenticate(HttpServletRequest request, HttpServletResponse response) {
931+
return true;
932+
}
933+
914934
/**
915935
* Invokes a service method.
916936
*

0 commit comments

Comments
 (0)