D. How to customize a UWS ?
3. User identification
Without a user identification all jobs are visible by anyone. So everybody is able to modify a job (start/stop/delete it, change its parameters, ...) as he wants. However with this library you can specify a way to identify a user in function of the received request.
How does it work ?
Before interpreting a request the UWS tries to identify the user thanks to an object which implements the interface UserIdentifier. In this interface there is only one function: extractUserId(UWSUrl, HttpServletRequest). This function must return the ID of the user identified from the given UWS URL and request.
Notes:
- By default, a UWS does not identify the user (there is no default identifier). Consequently all the jobs are visible and modifiable by everybody.
- With the function JobList.getJobs(String) you can retrieve only the jobs of the specified user. By default, it is done by all requests which have to manage jobs lists.
How to customize ?
You have to implement the interface UserIdentifier and to set the resulting class to your UWS thanks to the method setUserIdentifier(UserIdentifier). Here is an example:
public class MyExtendedUWS extends QueuedExtendedUWS { ... public MyExtendedUWS(int nbMaxRunningJobs) throws UWSException { ... // Add a user identification (by IP address): setUserIdentifier(new UserIdentifier() { private static final long serialVersionUID = 1L; @Override public String extractUserId(UWSUrl urlInterpreter, HttpServletRequest request) throws UWSException { return request.getRemoteAddr(); } }); } ... }
Note:
In this example, the user is actually a machine because the user identification is based on an IP address. Obviously it is not the best way to identify a user, because he can not access its jobs from another machine. Besides if there are several users on the same machine any of them can access to the same jobs. However this type of user identification is widely enough for this tutorial !