org.elkoserver.foundation.server.metadata
Class AuthDesc

java.lang.Object
  extended by org.elkoserver.foundation.server.metadata.AuthDesc
All Implemented Interfaces:
Encodable

public class AuthDesc
extends Object
implements Encodable

Descriptor containing information required or presented to authorize a connection.


Field Summary
static AuthDesc theOpenAuth
          Singleton open authorization descriptor.
 
Constructor Summary
AuthDesc(String mode, OptString code, OptString id)
          JSON-driven constructor.
AuthDesc(String mode, String code, String id)
          Direct constructor.
 
Method Summary
 String code()
          Get the authorization code.
 JSONLiteral encode(EncodeControl control)
          Encode this object for transmission or persistence.
static AuthDesc fromProperties(BootProperties props, String propRoot, Trace appTrace)
          Produce an AuthDesc object from information contained in the server configuration properties.
 String id()
          Get the authorization ID.
 String mode()
          Get the authorization mode.
 boolean verify(AuthDesc auth)
          Check an authorization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theOpenAuth

public static final AuthDesc theOpenAuth
Singleton open authorization descriptor. This may be used in all circumstances where open mode authorization is required or presented.

Constructor Detail

AuthDesc

public AuthDesc(String mode,
                String code,
                String id)
Direct constructor.

Parameters:
mode - Authorization mode.
code - Authorization code, or null if not relevant.
id - Authorization ID, or null if not relevant.

AuthDesc

@JSONMethod(value={"mode","code","id"})
public AuthDesc(String mode,
                                OptString code,
                                OptString id)
JSON-driven constructor.

Parameters:
mode - Authorization mode.
code - Optional authorization code.
id - Optional authorization ID.
Method Detail

code

public String code()
Get the authorization code.

Returns:
the authorization code (or null if there is none).

fromProperties

public static AuthDesc fromProperties(BootProperties props,
                                      String propRoot,
                                      Trace appTrace)
Produce an AuthDesc object from information contained in the server configuration properties.

The authorization mode is extracted from propRoot+".auth.mode". Currently, there are three possible authorization mode values that are recognized: "open", "password", and "reservation".

Open mode is unrestricted access. No additional descriptive information is required for open mode.

Password mode requires a secret code string for access. This code string is extracted from propRoot+".auth.code". Additionally, an identifier may also be required, which will be extracted from propRoot+".auth.id" if that property is present.

Reservation mode requires a reservation string for access. The reservation string is communicated via a separate pathway, but it optionally may be associated with an identifier extracted from propRoot+".auth.id".

Parameters:
props - The properties themselves.
propRoot - Prefix string for all the properties describing the authorization information of interest.
appTrace - Trace object for error logging.
Returns:
an AuthDesc object constructed according to the properties rooted at 'propRoot' as described above, or null if no such valid authorization information could be found.

id

public String id()
Get the authorization ID.

Returns:
the authorization ID (or null if there is none).

mode

public String mode()
Get the authorization mode.

Returns:
the authorization mode.

verify

public boolean verify(AuthDesc auth)
Check an authorization. This authorization descriptor is treated as a set of requirements. The authorization descriptor given in the 'auth' parameter is treated as a presented set of authorization credentials. The credentials are compared to the requirements to see if they satisfy them.

Parameters:
auth - Authorization credentials being presented.
Returns:
true if 'auth' correctly authorizes connection under the authorization configuration described by this object.

encode

public JSONLiteral encode(EncodeControl control)
Encode this object for transmission or persistence.

Specified by:
encode in interface Encodable
Parameters:
control - Encode control determining what flavor of encoding should be done.
Returns:
a JSON literal representing this object.