public class SimpleSecurityAuthority extends java.lang.Object implements SecurityService
Provides a basic security authority based on unique names. No passwords are used - a user is identified by a name which is guarded by a minimal protection scheme. This class is supplied as an example of implementing a security authority and not a robust implementation suitable for long term use.
Modifier and Type | Class and Description |
---|---|
private static class |
SimpleSecurityAuthority.SimpleChallenge
The challenge for this authority containing a timestamp and block of random data.
|
private static class |
SimpleSecurityAuthority.SimpleResponse
The response for this authority, consisting of a block of data which has been mangled based on the
timestamp and ID of the user creating the response.
|
private static class |
SimpleSecurityAuthority.SimpleUserID
Represents the user ID for this authority.
|
private static class |
SimpleSecurityAuthority.SimpleUserToken
Represents the authenticated user token for this authority.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Vector |
allowedUsers
Set of permitted users.
|
private static int |
CHALLENGE_LENGTH
Sets the length of the challenge packet.
|
private UserToken |
currentUser
The token of the current user.
|
private static java.util.Random |
rnd
A random number generater for creating challenges.
|
private boolean |
serviceRunning
Flag indicating if the service is running or not.
|
private SecurityAuthority |
userObject
The user control object that avoids giving out the full administrative interface.
|
Constructor and Description |
---|
SimpleSecurityAuthority()
Creates a new simple authority.
|
Modifier and Type | Method and Description |
---|---|
private AccessDeniedException |
accessDenied(java.lang.String reason)
Creates and returns an exception associated with this authority.
|
Challenge |
createChallenge()
Creates a new challenge packet containing a timestamp and some random data.
|
Response |
createResponse(Challenge c)
Creates a response to the challenge based on the currently logged in user.
|
private void |
createResponse(SimpleSecurityAuthority.SimpleChallenge c,
SimpleSecurityAuthority.SimpleUserID u,
byte[] b)
Creates a response for the given challenge using a given user ID.
|
UserID |
createUserID(java.lang.String username)
Creates and returns a user ID valid for this authority that represents the given user name.
|
UserToken |
createUserToken(UserID user)
Creates and returns an authentication token valid for this authority that represents the given
user name.
|
void |
denyUserAccess(UserID u)
Removes a user from the set of permitted users.
|
private java.lang.String |
getUserFromPrefs()
Returns the initial username if one is specified in the preferences.
|
ServiceUserObject |
getUserObject()
Returns the authority interface for this service.
|
boolean |
init(ServiceSettings s)
Initializes the service, setting a current user and the list of permitted users from the XML
configuration file.
|
boolean |
isRunning()
Returns true iff the service is running.
|
void |
logoffUser()
Clears the currently logged on user.
|
void |
logonUser(UserToken u)
Sets the currently logged on user.
|
void |
permitUserAccess(UserID u)
Adds a user to the set of permitted users.
|
boolean |
start()
Sets the service running.
|
boolean |
stop()
Stops the service.
|
java.lang.String |
toString()
Returns a string description of this authority.
|
boolean |
validateResponse(Challenge c,
Response r)
Checks if the generated response corresponds to one expected from a permitted user.
|
private static final int CHALLENGE_LENGTH
private UserToken currentUser
private static final java.util.Random rnd
private java.util.Vector allowedUsers
private boolean serviceRunning
private SecurityAuthority userObject
public SimpleSecurityAuthority()
public Challenge createChallenge()
createChallenge
in interface SecurityAuthority
public boolean validateResponse(Challenge c, Response r)
validateResponse
in interface SecurityAuthority
c
- the challenge returned by createChallenge
.r
- the response generated by the other authority.public Response createResponse(Challenge c)
createResponse
in interface SecurityAuthority
c
- the challenge to respond to.public void logonUser(UserToken u) throws AccessDeniedException
logonUser
in interface SecurityAuthority
u
- the user's token.AccessDeniedException
- if the user token is not valid for this authority.public void logoffUser()
createResponse
method will
fail until another user is logged in.logoffUser
in interface SecurityAuthority
public void permitUserAccess(UserID u) throws AccessDeniedException
permitUserAccess
in interface SecurityAuthority
u
- the user ID to add.AccessDeniedException
- if the ID was not allocated by this authority.public void denyUserAccess(UserID u) throws AccessDeniedException
denyUserAccess
in interface SecurityAuthority
u
- the user ID to remove.AccessDeniedException
- if the ID was not allocated by this authority.public boolean start()
public boolean stop()
public boolean isRunning()
public boolean init(ServiceSettings s)
Initializes the service, setting a current user and the list of permitted users from the XML configuration file. For example:
<SERVICE ...> <SETTING name="logonUser" value="foo@bar.com"/> <SETTING name="permitUser0" value="a"/> <SETTING name="permitUser1" value="b"/> </SETTING>
This sets the current user to be "foo@bar.com" but will allow responses from users "a" and "b".
public ServiceUserObject getUserObject()
getUserObject
in interface Service
ServiceUserObject
.public UserID createUserID(java.lang.String username)
username
- the unique user name.public UserToken createUserToken(UserID user) throws AccessDeniedException
user
- the user ID to authenticate.AccessDeniedException
- if the user ID is not valid for this authority.public java.lang.String toString()
toString
in class java.lang.Object
private void createResponse(SimpleSecurityAuthority.SimpleChallenge c, SimpleSecurityAuthority.SimpleUserID u, byte[] b)
c
- the challenge request.u
- the user ID to create a response for.b
- the array to place the response in.private AccessDeniedException accessDenied(java.lang.String reason)
reason
- the reason field of the exception.private java.lang.String getUserFromPrefs()