|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecttw.net.Server
tw.net.ocs.OCSServer
public final class OCSServer
The OCSServer receives requests from the client-side
proxies and routes them to associated subjects.
Several server instances can be maintained in the class.
If none is created explicitly, one server instance exists
which can be directly linked to an OCSClient for local
communication.
There are methods to
create instances,
get information about hosted subjects,
add and remove subjects,
constrain access,
set the key to use for encrypted data transmission,
shutdown the server, and
miscellaneous.
Server methods may also be called remotely, using proxies
implementing OCSServerAdminInterface and OCSServerUserInterface
as returned by methods of OCSClient.
Server,
OCSClient.getServerAdminProxy(),
OCSClient.getServerUserProxy(),
OCSServerAdminInterface,
OCSServerUserInterface| Field Summary |
|---|
| Fields inherited from class tw.net.Server |
|---|
DEFAULT_PORT, LOCAL, UNBOUND |
| Method Summary | |
|---|---|
void |
addAdminPassword(java.lang.String pw)
Adds a password allowing administrative access to the server. |
void |
addAdminPasswords(java.lang.String[] pw)
Adds one or more password(s) allowing administrative access to the server. |
java.lang.String |
addSubject(java.lang.Object subject)
Adds a subject to the server. |
java.lang.String |
addSubject(java.lang.Object subject,
boolean gc)
Adds a subject to the server. |
java.lang.String |
addSubject(java.lang.Object subject,
java.lang.Class c,
java.lang.String id)
Adds a subject associated with some class to the server. |
java.lang.String |
addSubject(java.lang.Object subject,
java.lang.Class c,
java.lang.String id,
boolean gc)
Adds a subject associated with some class to the server. |
java.lang.String |
addSubject(java.lang.Object subject,
java.lang.String id)
Adds a subject to the server. |
java.lang.String |
addSubject(java.lang.Object subject,
java.lang.String id,
boolean gc)
Adds a subject to the server. |
void |
addUserPassword(java.lang.String pw)
Adds a password allowing user access to the server. |
void |
addUserPasswords(java.lang.String[] pw)
Adds one or more password(s) allowing user access to the server. |
void |
allowSubjectClass(java.lang.Class c)
Allows the hosting of subjects of a certain class. |
void |
allowSubjectClasses(java.lang.String[] cc)
Allows the hosting of subjects of certain classes. |
static OCSServer |
createInstance()
Creates a server instance with default values. |
static OCSServer |
createInstance(int port,
java.lang.String name)
Creates a server instance listening on a certain port. |
void |
encryptAccordingToClient(boolean value)
Sets the server to accept both encrypting and non-encrypting clients. |
boolean |
existsSubject(java.lang.Class c)
Tells whether at least one subject of a certain class exists on this server |
boolean |
existsSubject(java.lang.Class c,
java.lang.String id)
Tells whether a certain subject exists on this server |
void |
forbidSubjectClass(java.lang.Class c)
Forbids the hosting of subjects of a certain class. |
void |
forbidSubjectClasses(java.lang.String[] cc)
Forbids the hosting of subjects of certain classes. |
static OCSServer |
getInstance(int port)
Returns a server instance identified by its port |
static OCSServer |
getInstance(java.lang.String name)
Returns a server instance identified by name |
static java.util.Collection<OCSServer> |
getInstances()
Returns all instances. |
java.lang.String |
getName()
Returns the name of the instance. |
java.lang.Object |
getSubject(java.lang.Class c)
Returns an arbitrary instance of a subject class |
java.lang.Object |
getSubject(java.lang.Class c,
java.lang.String id)
Returns an identified instance of a subject class. |
java.util.List<java.lang.Class> |
getSubjectClasses()
Returns the classes of which instances (subjects) exist on this server |
java.lang.String |
getSubjectID(java.lang.Class c)
Returns the ID of an arbitrary instance of a subject class |
java.util.List<java.lang.String> |
getSubjectNames(java.lang.Class c)
Returns the names of subjects of a certain class. |
boolean |
isLocal()
Tells whether the server is working in local mode, configured to be referenced directly by a client |
static void |
main(java.lang.String[] args)
Allows to start and stop an OCSServer, also to retrieve version information. |
boolean |
ping()
A convenience method to check the server's accessibility |
boolean |
removeAdminPassword(java.lang.String pw)
Removes a password allowing administrative access to the server. |
void |
removeAdminPasswords()
Removes all passwords allowing administrative access to the server. |
boolean |
removeSubject(java.lang.Class c,
java.lang.String id)
Removes a subject from this server |
boolean |
removeSubjects()
Removes all subjects from this server |
boolean |
removeSubjects(java.lang.Class c)
Removes all subjects of a given class from this server |
boolean |
removeUserPassword(java.lang.String pw)
Removes a password allowing user access to the server. |
void |
removeUserPasswords()
Removes all passwords allowing user access to the server. |
void |
setEncryptionKey(java.lang.String key)
Sets the key for encrypted data transmission. |
void |
setLogfile(java.lang.String f)
Sets a file to receive log messages. |
java.lang.String |
toString()
|
| Methods inherited from class tw.net.Server |
|---|
allowClientIP, allowClientIPs, forbidClientIP, forbidClientIPs, getHostAddress, getHostName, getPort, getPriority, isDaemon, pleaseStop, setDaemon, setPriority, setVerbose, start |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface tw.net.ocs.OCSServerUserInterface |
|---|
getHostAddress, getHostName, getPort |
| Methods inherited from interface tw.net.ocs.OCSServerAdminInterface |
|---|
allowClientIP, allowClientIPs, forbidClientIP, forbidClientIPs, getPriority, hashCode, isDaemon, pleaseStop, setDaemon, setPriority, setVerbose |
| Method Detail |
|---|
public void addUserPassword(java.lang.String pw)
Adds a password allowing user access to the server.
Several passwords may be used, each independently allowing
access.
If no password has been set, access to the server is
unrestricted. (Note that this is different from the
policy used with admin passwords, where the absence
of passwords means access to admin methods is forbidden.)
Note that passwords are only checked when methods are called
via proxies, i.e. thru an OCSClient. OCSServer method invocations
directly using an OCSServer object do not require authentification.
addUserPassword in interface OCSServerAdminInterfacepw - the passwordaddUserPasswords(java.lang.String[]),
addAdminPassword(java.lang.String)public void addUserPasswords(java.lang.String[] pw)
addUserPasswords in interface OCSServerAdminInterfacepw - an array of passwordaddUserPassword(java.lang.String)public boolean removeUserPassword(java.lang.String pw)
removeUserPassword in interface OCSServerAdminInterfacepw - the password
public void removeUserPasswords()
removeUserPasswords in interface OCSServerAdminInterfacepublic void addAdminPassword(java.lang.String pw)
Adds a password allowing administrative access to the server.
Several admin passwords may be used, each independently allowing
access.
If no admin password has been set, access to administration methods
of OCSServer is forbidden. (Note that this is different from the
policy used with user passwords, where the absence of passwords
means access to user methods is unlimited.)
Note that passwords are only checked when methods are called
via proxies, i.e. thru an OCSClient. OCSServer method invocations
directly using an OCSServer object do not require authentification.
addAdminPassword in interface OCSServerAdminInterfacepw - the passwordaddAdminPasswords(java.lang.String[]),
addUserPassword(java.lang.String)public void addAdminPasswords(java.lang.String[] pw)
addAdminPasswords in interface OCSServerAdminInterfacepw - an array of passwordaddAdminPassword(java.lang.String)public boolean removeAdminPassword(java.lang.String pw)
removeAdminPassword in interface OCSServerAdminInterfacepw - the password
OCSServerAdminInterface.addAdminPassword(java.lang.String)public void removeAdminPasswords()
removeAdminPasswords in interface OCSServerAdminInterfacepublic boolean isLocal()
isLocal in interface OCSServerUserInterface
public static OCSServer createInstance(int port,
java.lang.String name)
Creates a server instance listening on a certain port.
Special values of port numbers:
If 0 (zero) is specified, an arbitrary port will be used.
If -1 (=Server.LOCAL) is specified, the server will not listen on a port
but get prepared for direct use by a client within the same VM.
If a specified port is already in use, the server will bind to
some arbitrary unused port.
If no name is specified for the instance, it is given a name automatically:
A remote server will be named after its port number,
a local server will be named "LOCAL".
If the selected name proves to be already in use, it will be made
unique by appending "/[number]".
port - number of the port to listen atname - symbolic ID of the server instance
public static OCSServer createInstance()
Creates a server instance with default values.
The server will listen on default port 23229 and
be named "23229" or "23229/[number]".
If the default port is already in use, the server will bind to
some arbitrary unused port.
public static OCSServer getInstance(java.lang.String name)
name - name of the instance
public static OCSServer getInstance(int port)
port - the port number
public void forbidSubjectClass(java.lang.Class c)
Forbids the hosting of subjects of a certain class.
Note that forbidding a subject class includes
forbidding all of this class' subclasses.
If there are both forbid and allow specifications,
the latter are ignored.
forbidSubjectClass in interface OCSServerAdminInterfacec - the class of which instances must not be hostedallowSubjectClass(java.lang.Class)
public void forbidSubjectClasses(java.lang.String[] cc)
throws java.lang.ClassNotFoundException
Forbids the hosting of subjects of certain classes.
Specify classes by their qualified names, as for
use by Class.forName().
forbidSubjectClasses in interface OCSServerAdminInterfacecc - an array of class names
java.lang.ClassNotFoundExceptionforbidSubjectClass(java.lang.Class)public void allowSubjectClass(java.lang.Class c)
Allows the hosting of subjects of a certain class.
Note that allowing a subject class includes
allowing all of this class' superclasses.
If at least one class is explicitly allowed to be hosted, the
hosting of all classes not explicitly allowed
is forbidden - provided there is no forbid specification:
If at least one class has been forbidden to be hosted,
allow specifications are ignored and all classes
not explicitely forbidden are allowed.
allowSubjectClass in interface OCSServerAdminInterfacec - the class of which instances may be hostedforbidSubjectClass(java.lang.Class)
public void allowSubjectClasses(java.lang.String[] cc)
throws java.lang.ClassNotFoundException
Allows the hosting of subjects of certain classes.
Specify classes by their qualified names, as for
use by Class.forName().
allowSubjectClasses in interface OCSServerAdminInterfacecc - an array of class names
java.lang.ClassNotFoundExceptionallowSubjectClass(java.lang.Class)
public java.lang.Object getSubject(java.lang.Class c,
java.lang.String id)
Returns an identified instance of a subject class.
Note: If null is specified as the ID, null will be
returned.
Use getSubject(Class c) to retrieve an arbitrary instance
of a subject class.
getSubject in interface OCSServerUserInterfacec - the class of the requested subjectid - the ID of the subject
public java.lang.Object getSubject(java.lang.Class c)
getSubject in interface OCSServerUserInterfacec - the class of the requested subject
public java.util.List<java.lang.String> getSubjectNames(java.lang.Class c)
Returns the names of subjects of a certain class.
If null is specified for the class, the names
of all subjects of whatever class are returned.
getSubjectNames in interface OCSServerUserInterfacec - the class to which the request is restricted
public java.util.List<java.lang.Class> getSubjectClasses()
getSubjectClasses in interface OCSServerUserInterfacepublic java.lang.String getSubjectID(java.lang.Class c)
getSubjectID in interface OCSServerUserInterfacec - the subject class
public boolean existsSubject(java.lang.Class c,
java.lang.String id)
existsSubject in interface OCSServerUserInterfacec - the class of the subjectid - the ID of the subject
public boolean existsSubject(java.lang.Class c)
existsSubject in interface OCSServerUserInterfacec - the class of the subject
public boolean removeSubject(java.lang.Class c,
java.lang.String id)
removeSubject in interface OCSServerUserInterfacec - the class of the subjectid - the ID of the subject
public boolean removeSubjects(java.lang.Class c)
removeSubjects in interface OCSServerUserInterfacec - the class of the subject
public boolean removeSubjects()
removeSubjects in interface OCSServerUserInterface
public java.lang.String addSubject(java.lang.Object subject,
java.lang.Class c,
java.lang.String id,
boolean gc)
throws OCSException
Adds a subject associated with some class to the server.
The specified class may be a base class of the subject.
If the specified class is neither identical to the
subject's class nor one of its base classes, an
OCSException is thrown.
The subject will be associated with an ID.
If no ID is specified, it will be supplied automatically.
The subject can be marked for garbage collection so
that it will be removed if all proxies that may attach
to it detach from it again.
addSubject in interface OCSServerUserInterfacesubject - the subjectc - the class of the subject or a base class thereofid - the ID to associate the subject with (may be null)gc - garbage collect the subject once all proxies detach from it?
OCSException
public java.lang.String addSubject(java.lang.Object subject,
java.lang.Class c,
java.lang.String id)
throws OCSException
Adds a subject associated with some class to the server.
The specified class may be a base class of the subject.
If the specified class is neither identical to the
subject's class nor one of its base classes, an
OCSException is thrown.
The subject will be associated with an ID.
If no ID is specified, it will be supplied automatically.
The subject is not marked for garbage collection,
so it will stay on if proxies that may attach to it
detach again.
addSubject in interface OCSServerUserInterfacesubject - the subjectc - the class of the subject or a base class thereofid - the ID to associate the subject with (may be null)
OCSException
public java.lang.String addSubject(java.lang.Object subject,
java.lang.String id,
boolean gc)
throws OCSException
Adds a subject to the server.
The subject will be associated with an ID.
If no ID is specified, it will be supplied automatically.
The subject can be marked for garbage collection so
that it will be removed if all proxies that may attach
to it detach from it again.
addSubject in interface OCSServerUserInterfacesubject - the subjectid - the ID to associate the subject with (may be null)gc - garbage collect the subject once all proxies detach from it?
OCSException
public java.lang.String addSubject(java.lang.Object subject,
java.lang.String id)
throws OCSException
Adds a subject to the server.
The subject gets associated with an ID.
If none is specified, the ID is supplied automatically.
The subject is not marked for garbage collection,
so it will stay on if proxies that may attach to it
detach again.
addSubject in interface OCSServerUserInterfacesubject - the subjectid - the ID to associate the subject with (may be null)
OCSException
public java.lang.String addSubject(java.lang.Object subject,
boolean gc)
throws OCSException
Adds a subject to the server.
The subject's ID is supplied automatically.
The subject can be marked for garbage collection so
that it will be removed if all proxies that may attach
to it detach from it again.
addSubject in interface OCSServerUserInterfacesubject - the subjectgc - garbage collect the subject once all proxies detach from it?
OCSException
public java.lang.String addSubject(java.lang.Object subject)
throws OCSException
Adds a subject to the server.
The subject's ID is supplied automatically.
The subject is not marked for garbage collection,
so it will stay on if proxies that may attach to it
detach again.
addSubject in interface OCSServerUserInterfacesubject - the subject
OCSExceptionpublic boolean ping()
ping in interface OCSServerAdminInterfacepublic void setLogfile(java.lang.String f)
Sets a file to receive log messages.
If the file exists already, new messages will
be appended to it.
Note that setting a logfile does not turn off
logging to System.out but create an additional
log target.
f - the path of the log filepublic void setEncryptionKey(java.lang.String key)
Sets the key for encrypted data transmission.
Setting a key means that encryption begins.
To stop encryption, call the method with a
null argument.
(Encryption is inactive if the server is
used locally.)
setEncryptionKey in interface OCSServerAdminInterfacekey - the encryption key or nullencryptAccordingToClient(boolean)public void encryptAccordingToClient(boolean value)
Sets the server to accept both encrypting and non-encrypting clients.
Setting this option is relevant only if the server runs in encrypting mode:
If set, an encrypting server accepts and serves non-encrypting clients
as well.
If not set, an encrypting server turns non-encrypting clients away.
Per default, this option is not set.
Note that setting this option alone, does not put a server in
encrypting mode. To do this, use setEncryptionKey() with a non-empty
argument.
encryptAccordingToClient in interface OCSServerAdminInterfacevalue - allow both encrypting and non-encrypting clients?setEncryptionKey(java.lang.String)public java.lang.String getName()
public static java.util.Collection<OCSServer> getInstances()
public java.lang.String toString()
toString in interface OCSServerAdminInterfacetoString in class java.lang.Objectpublic static void main(java.lang.String[] args)
Allows to start and stop an OCSServer, also to
retrieve version information.
When starting, you can
specify passwords required from clients for user or
administrative functions,
allow / forbid clients connecting from certain IPs,
set the server to encrypted data transmission, and
allow / forbid the installation of subjects of certain classes.
Example:
java tw.net.ocs.OCSServer -start -port 12345 -adminPassword eddie -allowedClientIP 192.168+123.45.*.1 -encryptionKey secret -allowedSubjectClass my.pack.Clazz
This
- starts a server
- at port 12345
- with admin functions requiring password "eddie",
- accessible only to clients within the LAN or at an IP
which matches the pattern 123.45.*.1,
- encrypting data using the key "secret", and
- allowing subjects only of class "my.pack.Clazz".
To specify passwords for non-administrative operations, use "-userPassword".
You may specify several passwords. separated by "+".
To forbid client IPs, use "-forbiddenClientIP". If positive and negative
IP constraints are combined and patterns of both types do match,
the type of the more specific pattern will take effect. If on a par,
forbidding takes precedence. See the API doc for details!
You may specify several IPs (IP patterns), separated by "+".
Specifying an encryption key means to put the server into encrypting mode.
Specify the boolean option "-encryptAccordingToClient" in addition
to let the server accept both encrypting and non-encrypting clients;
without this option, a server running in encrypting mode will turn
non-encrypting clients away.
To allow or forbid subject classes, use "-allowedSubjectClass"
or "-forbiddenSubjectClass". Specify one or the other, not both:
If both options are given, only "-forbiddenSubjectClass" is evaluated.
When specifying classes make sure to use their qualified names,
like "my.pack.Clazz", instead of just "Clazz".
You may specify several class names, separated by "+".
When stopping a server, specify the port and the admin password.
Example:
java tw.net.ocs.OCSServer -stop -port 12345 -adminPassword eddie
This would stop the server started with the command above.
If no port is specified, the default port 23229 is assumed.
Usage:
java tw.net.ocs.OCSServer {parameters...}
-start Start a server
-stop Stop a server
-port The port number of the server
-userPassword Set / use this user password
-adminPassword Set / use this admin password
-allowedClientIP IP address of acceptable client
-forbiddenClientIP IP address of inacceptable client
-encryptionKey Encrypt data using this key
-encryptAccordingToClient Serve both encrypting and non-encrypting clients
-allowedSubjectClass Class of which subjects are allowed on the server
-forbiddenSubjectClass Class of which subjects are not allowed on the server
-logfile Log errors (activities if verbose) to this file
-verbose Make the server say a bit what it does
-version Show version information
-licensee Show licensee name
addUserPassword(java.lang.String),
addAdminPassword(java.lang.String),
Server.allowClientIPs(java.lang.String[]),
Server.forbidClientIPs(java.lang.String[]),
forbidSubjectClasses(java.lang.String[]),
allowSubjectClasses(java.lang.String[])
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
www.ocselot.net