org.qtunes.webcontrol
Class WebController

java.lang.Object
  extended by org.qtunes.webcontrol.WebController
All Implemented Interfaces:
Service, WebHandler

public class WebController
extends Object
implements Service, WebHandler

An example web interface for the qTunes server. This serves any requests beginning with the path "/qtunes/" with the WebHandler handler. Some simple examples if this is running on port 8080 would be to call curl like so

 curl http://localhost:8080/qtunes/db/getTracks
 curl http://localhost:8080/qtunes/db/Player/addTrack?1
 curl http://localhost:8080/qtunes/db/Player/setVolume?40
 curl http://localhost:8080/qtunes/db/db/getField?1,'Title'
 
Login can be done one of two ways: Either basic authentication:
 curl http://localhost:8080/qtunes/auth/login?user=johnsmith&password=secret
 
or using a digest authentication. In this case the supplied URL looks like this:
 curl http://localhost:8080/qtunes/auth/login?user=johnsmith&nonce=12345&digest=fgkDFZYtvPYz61SoXB9TKg
 
where 'user' is the username, 'nonce' is a numeric value which should match the one supplied by the server (although currently any value will do) and 'digest' is the Base64-encoded value of MD5(nonce + MD5(username+password)). The "nonce" value in this expression is the nonce integer value represented as a bigendian 4-byte value, and "username+password' are the UTF-8 bytes of the username concatenated with the password.


Constructor Summary
WebController()
           
 
Method Summary
protected  void activate(org.osgi.service.component.ComponentContext context)
           
 void addUser(String user, String password, String[] allowances)
          Add an authorized user and password to this Service.
 void addUserDigest(String user, String digest, String[] allowances)
          Add an authorized user and password to this Service.
protected  void deactivate(org.osgi.service.component.ComponentContext context)
           
 String getShortName()
           
 void handle(WebConnection con)
           
 void setWebService(WebService service)
           
 void startService(ServiceContext context)
           
 void stopService()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebController

public WebController()
Method Detail

startService

public void startService(ServiceContext context)
Specified by:
startService in interface Service

setWebService

public void setWebService(WebService service)

stopService

public void stopService()
Specified by:
stopService in interface Service

getShortName

public String getShortName()
Specified by:
getShortName in interface Service

addUser

public void addUser(String user,
                    String password,
                    String[] allowances)
Add an authorized user and password to this Service. The supplied parameters are the username and the cleartext password, which will be encoded and passed to addUserDigest(java.lang.String, java.lang.String, java.lang.String[]).

Parameters:
user - the username
password - the password
allowances - the list of Allowances this user has

addUserDigest

public void addUserDigest(String user,
                          String digest,
                          String[] allowances)
Add an authorized user and password to this Service. The supplied parameters are the username, and the base64-encoded MD5 checksum of username+password, which allows the password to be sent over the wire in a safer fashion that cleartext. More exactly, the argument should be base64(md5(utf8(username+password))) where "base64" will encode a byte array as Base-64, "md5" will calculate the MD5 checksum of the specified bytes, and "utf8" will return the bytes of the specified String as UTF-8

Parameters:
user - the username
digest - the digest of the username and password
allowances - the list of Allowances this user has

handle

public void handle(WebConnection con)
            throws IOException
Specified by:
handle in interface WebHandler
Throws:
IOException

activate

protected void activate(org.osgi.service.component.ComponentContext context)

deactivate

protected void deactivate(org.osgi.service.component.ComponentContext context)