Package org.jcsp.net.security
Class SimpleSecurityAuthority
java.lang.Object
org.jcsp.net.security.SimpleSecurityAuthority
- All Implemented Interfaces:
Serializable
,SecurityAuthority
,SecurityService
,Service
,ServiceUserObject
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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
The challenge for this authority containing a timestamp and block of random data.private static final class
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 final class
Represents the user ID for this authority.private static final class
Represents the authenticated user token for this authority. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Vector
Set of permitted users.private static final int
Sets the length of the challenge packet.private UserToken
The token of the current user.private static final Random
A random number generater for creating challenges.private boolean
Flag indicating if the service is running or not.private SecurityAuthority
The user control object that avoids giving out the full administrative interface. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate AccessDeniedException
accessDenied
(String reason) Creates and returns an exception associated with this authority.Creates a new challenge packet containing a timestamp and some random data.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.createUserID
(String username) Creates and returns a user ID valid for this authority that represents the given user name.createUserToken
(UserID user) Creates and returns an authentication token valid for this authority that represents the given user name.void
Removes a user from the set of permitted users.private String
Returns the initial username if one is specified in the preferences.Returns the authority interface for this service.boolean
Initializes the service, setting a current user and the list of permitted users from the XML configuration file.boolean
Returns true iff the service is running.void
Clears the currently logged on user.void
Sets the currently logged on user.void
Adds a user to the set of permitted users.boolean
start()
Sets the service running.boolean
stop()
Stops the service.toString()
Returns a string description of this authority.boolean
Checks if the generated response corresponds to one expected from a permitted user.
-
Field Details
-
CHALLENGE_LENGTH
private static final int CHALLENGE_LENGTHSets the length of the challenge packet.- See Also:
-
currentUser
The token of the current user. -
rnd
A random number generater for creating challenges. -
allowedUsers
Set of permitted users. -
serviceRunning
private boolean serviceRunningFlag indicating if the service is running or not. -
userObject
The user control object that avoids giving out the full administrative interface.
-
-
Constructor Details
-
SimpleSecurityAuthority
public SimpleSecurityAuthority()Creates a new simple authority. The current username will be found from the preferences if available under the "user" variable. The system property "org.jcsp.net.security.user" will be checked first and take preference. If no user is found the name "default_user" is assumed.
-
-
Method Details
-
createChallenge
Creates a new challenge packet containing a timestamp and some random data. The response must be returned within around 1 minute for the response to be considered valid so don't keep it too long.- Specified by:
createChallenge
in interfaceSecurityAuthority
- Returns:
- the new challenge packet.
-
validateResponse
Checks if the generated response corresponds to one expected from a permitted user. The response must have come within a minute of the challenge being generated.- Specified by:
validateResponse
in interfaceSecurityAuthority
- Parameters:
c
- the challenge returned bycreateChallenge
.r
- the response generated by the other authority.- Returns:
- true if the response is permitted.
-
createResponse
Creates a response to the challenge based on the currently logged in user.- Specified by:
createResponse
in interfaceSecurityAuthority
- Parameters:
c
- the challenge to respond to.- Returns:
- the response.
-
logonUser
Sets the currently logged on user. If there is already a user logged in, they are logged off.- Specified by:
logonUser
in interfaceSecurityAuthority
- Parameters:
u
- the user's token.- Throws:
AccessDeniedException
- if the user token is not valid for this authority.
-
logoffUser
public void logoffUser()Clears the currently logged on user. After this call thecreateResponse
method will fail until another user is logged in.- Specified by:
logoffUser
in interfaceSecurityAuthority
-
permitUserAccess
Adds a user to the set of permitted users.- Specified by:
permitUserAccess
in interfaceSecurityAuthority
- Parameters:
u
- the user ID to add.- Throws:
AccessDeniedException
- if the ID was not allocated by this authority.
-
denyUserAccess
Removes a user from the set of permitted users.- Specified by:
denyUserAccess
in interfaceSecurityAuthority
- Parameters:
u
- the user ID to remove.- Throws:
AccessDeniedException
- if the ID was not allocated by this authority.
-
start
public boolean start()Sets the service running. -
stop
public boolean stop()Stops the service. -
isRunning
public boolean isRunning()Returns true iff the service is running. -
init
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".
-
getUserObject
Returns the authority interface for this service. A seperate user object is returned to avoid giving away the service control interface also.- Specified by:
getUserObject
in interfaceService
- Returns:
- a
ServiceUserObject
.
-
createUserID
Creates and returns a user ID valid for this authority that represents the given user name.- Parameters:
username
- the unique user name.- Returns:
- the user ID.
-
createUserToken
Creates and returns an authentication token valid for this authority that represents the given user name. Note that no additional credentials are supplied because this authority does not support passwords or anything more secure (hence the word 'Simple' in its name :).- Parameters:
user
- the user ID to authenticate.- Returns:
- the authentication token.
- Throws:
AccessDeniedException
- if the user ID is not valid for this authority.
-
toString
Returns a string description of this authority. -
createResponse
private void createResponse(SimpleSecurityAuthority.SimpleChallenge c, SimpleSecurityAuthority.SimpleUserID u, byte[] b) Creates a response for the given challenge using a given user ID. This is used to create an actual response and also to create the expected response for a given user.- Parameters:
c
- the challenge request.u
- the user ID to create a response for.b
- the array to place the response in.
-
accessDenied
Creates and returns an exception associated with this authority.- Parameters:
reason
- the reason field of the exception.
-
getUserFromPrefs
Returns the initial username if one is specified in the preferences. The user preferences take precedence over the system preferences.- Returns:
- the user name or null if none is found.
-