Methods Summary |
---|
private boolean | checkAccess(ora.jwsnut.chapter6.headerbookservice.Authentication auth)Check whether the calling user is authenticated.
boolean allowed = false;
if (userName != null && password != null && auth != null) {
// Authentication is configured.
return userName.equals(auth.getUserName()) &&
password.equals(auth.getPassword());
}
return allowed;
|
public void | destroy()
// Nothing to do
|
public void | getBookAuthor(java.lang.String title, javax.xml.rpc.holders.StringHolder author, ora.jwsnut.chapter6.headerbookservice.Authentication auth, javax.xml.rpc.holders.CalendarHolder calendarHolder)Gets the author for a books with a given title
calendarHolder.value = new GregorianCalendar();
String authorName = HeaderBookServiceServantData.getBookAuthor(title);
if (authorName == null || !checkAccess(auth)) {
throw new HeaderBookServiceException("Unknown author: " + title);
}
author.value = authorName;
|
public int | getBookCount(ora.jwsnut.chapter6.headerbookservice.Authentication auth, javax.xml.rpc.holders.CalendarHolder calendarHolder)Gets the number of books known to the service
calendarHolder.value = new GregorianCalendar();
String[] titles = HeaderBookServiceServantData.getBookTitles();
return titles == null || !checkAccess(auth) ? 0 : titles.length;
|
public java.lang.String | getBookTitle(int index, ora.jwsnut.chapter6.headerbookservice.Authentication auth, javax.xml.rpc.holders.CalendarHolder calendarHolder)Gets the title of a given book.
calendarHolder.value = new GregorianCalendar();
String[] bookTitles = HeaderBookServiceServantData.getBookTitles();
if (bookTitles == null || index < 0 || index >= bookTitles.length || !checkAccess(auth)) {
return null;
}
return bookTitles[index];
|
public void | init(java.lang.Object context)
endpointContext = (ServletEndpointContext)context;
// Get the authorized user name and password from the init parameters
ServletContext servletContext = endpointContext.getServletContext();
userName = servletContext.getInitParameter("UserName");
password = servletContext.getInitParameter("Password");
|
public void | log(java.lang.String value, ora.jwsnut.chapter6.headerbookservice.Authentication auth, javax.xml.rpc.holders.CalendarHolder calendarHolder)Makes a log entry.
calendarHolder.value = new GregorianCalendar();
if (checkAccess(auth)) {
endpointContext.getServletContext().log(new Date() + ": " + value);
}
|