2.17.2: 2011-06-17

net.sf.basedb.core
Class FileServer

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<D>
      extended by net.sf.basedb.core.OwnedItem<D>
          extended by net.sf.basedb.core.SharedItem<D>
              extended by net.sf.basedb.core.CommonItem<FileServerData>
                  extended by net.sf.basedb.core.FileServer
All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Ownable, Removable, Shareable

public class FileServer
extends CommonItem<FileServerData>

This class represents a file server that is used to store external files. A File should be associated with a file server if authentication is required to access the file.

Since:
2.16
Author:
Nicklas
Last modified
$Date $

Field Summary
static int MAX_CERTIFICATE_LENGTH
          The maximum length of the server certificate that can be stored in the database.
static int MAX_PASSWORD_LENGTH
          The maximum length of the password that can be stored in the database.
static int MAX_USERNAME_LENGTH
          The maximum length of the username that can be stored in the database.
static Item TYPE
          The type of item represented by this class.
 
Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Constructor Summary
FileServer(FileServerData data)
           
 
Method Summary
static FileServer getById(DbControl dc, int id)
          Get a FileServer item when you know the ID.
 byte[] getClientCertificate()
          Get the client certificate that BASE should use to authenticate with the server when connecting with https.
 String getClientCertificatePassword()
          Get the password that is needed to unlock the client certificate.
 X509Certificate getClientX509Certificate()
          Get the X.509 certificate for the client.
 ItemQuery<File> getFiles()
          Get a query returning all files that has been registered with this server.
static FileServer getNew(DbControl dc)
          Create a new FileServer item.
 String getPassword()
          Get the password that is used when authenticating with the file server.
static ItemQuery<FileServer> getQuery()
          Get a new query object for this class.
 byte[] getServerCertificate()
          Get the public server certificate that indicates that we should only trust the server if it can present a certificate that matches this.
 X509Certificate getServerX509Certificate()
          Get the X.509 certificate for the server.
 org.apache.http.conn.ssl.SSLSocketFactory getSSLSocketFactory()
          Get a socket factory that can be used to create SSL connections to the given server.
 Item getType()
          Get the type of item represented by the object.
 String getUsername()
          Get the username that is required to authenticate with the file server.
 Set<ItemProxy> getUsingItems()
          Get all files registered with this server.
 boolean hasPassword()
          Is a password set or not?
 boolean isUsed()
          Checks if there are files registered with this server.
 void setClientCertificate(byte[] certificate)
          Set the client certificate that BASE should use to authenticate with the server when connecting with https.
 void setClientCertificatePassword(String password)
          Set the password that is needed to unlock the client certificate.
 void setPassword(String password)
          Set the password to use when authenticating with the file server.
 void setServerCertificate(byte[] certificate)
          Set the public server certificate so that BASE can trust https connections to the server.
 void setUsername(String username)
          Set the username that is required to authenticate with the file server.
 
Methods inherited from class net.sf.basedb.core.CommonItem
getDescription, getName, isRemoved, setDescription, setName, setRemoved, toTransferable
 
Methods inherited from class net.sf.basedb.core.SharedItem
getItemKey, getProjectKey, initPermissions, isShared, onBeforeCommit, setItemKey, setProjectKey, toTransferable
 
Methods inherited from class net.sf.basedb.core.OwnedItem
getOwner, isOwner, setOwner, takeOwnership, toTransferable
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
 
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
 
Methods inherited from interface net.sf.basedb.core.Ownable
getOwner, isOwner, setOwner, takeOwnership
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.FILESERVER, getType()

MAX_USERNAME_LENGTH

public static final int MAX_USERNAME_LENGTH
The maximum length of the username that can be stored in the database.

See Also:
setUsername(String), Constant Field Values

MAX_PASSWORD_LENGTH

public static final int MAX_PASSWORD_LENGTH
The maximum length of the password that can be stored in the database.

See Also:
setPassword(String), Constant Field Values

MAX_CERTIFICATE_LENGTH

public static final int MAX_CERTIFICATE_LENGTH
The maximum length of the server certificate that can be stored in the database.

See Also:
setServerCertificate(byte[]), setClientCertificate(byte[]), Constant Field Values
Constructor Detail

FileServer

FileServer(FileServerData data)
Method Detail

getNew

public static FileServer getNew(DbControl dc)
                         throws BaseException
Create a new FileServer item.

Parameters:
dc - The DbControl which will be used for permission checking and database access
Returns:
The new FileServer item
Throws:
BaseException - If there is an error

getById

public static FileServer getById(DbControl dc,
                                 int id)
                          throws ItemNotFoundException,
                                 PermissionDeniedException,
                                 BaseException
Get a FileServer item when you know the ID.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
id - The ID of the item to load
Returns:
The FileServer item
Throws:
ItemNotFoundException - If an item with the specified ID is not found
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException - If there is another error

getQuery

public static ItemQuery<FileServer> getQuery()
Get a new query object for this class.

Returns:
An ItemQuery object

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Returns:
A value indicating the type of item

isUsed

public boolean isUsed()
               throws BaseException
Checks if there are files registered with this server.

Overrides:
isUsed in class BasicItem<FileServerData>
Returns:
TRUE if this item is used, FALSE otherwise
Throws:
BaseException - If there is another error
See Also:
BasicItem.getUsingItems()

getUsingItems

public Set<ItemProxy> getUsingItems()
Get all files registered with this server.

Overrides:
getUsingItems in class BasicItem<FileServerData>
Returns:
A set containing proxies for the items, or an empty set if no items are using this item
See Also:
BasicItem.addUsingItems(Set, Item, org.hibernate.Query)

getUsername

public String getUsername()
Get the username that is required to authenticate with the file server.

Returns:
A username or null if authentication is not required

setUsername

public void setUsername(String username)
                 throws PermissionDeniedException,
                        InvalidDataException
Set the username that is required to authenticate with the file server.

Parameters:
username - The new username, null if not authentication is required
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the username is longer than MAX_USERNAME_LENGTH

getPassword

public String getPassword()
Get the password that is used when authenticating with the file server. NOTE! Write permission is required to read the password.

Returns:
The password (which may be null)
See Also:
hasPassword()

hasPassword

public boolean hasPassword()
Is a password set or not?


setPassword

public void setPassword(String password)
                 throws PermissionDeniedException,
                        InvalidDataException
Set the password to use when authenticating with the file server.

Parameters:
password - The new password (can be null)
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the password is longer than MAX_PASSWORD_LENGTH

getServerCertificate

public byte[] getServerCertificate()
Get the public server certificate that indicates that we should only trust the server if it can present a certificate that matches this. This property is typically only needed to access servers using https that has a self-signed certificate. Servers which has a valid certificate signed by a trusted certification authority should be automatically trusted by BASE without setting this property. The certificate must be a X.509 certificate in either binary or base64-encoded DER format.

Returns:
A byte array with the certificate or null if no certificate has been set
See Also:
getServerX509Certificate()

setServerCertificate

public void setServerCertificate(byte[] certificate)
Set the public server certificate so that BASE can trust https connections to the server. See getServerCertificate() for more information. The certificate must be a X.509 certificate in either binary or base64-encoded DER format.

Parameters:
certificate - The server certificate or null if no certificate is required

getServerX509Certificate

public X509Certificate getServerX509Certificate()
Get the X.509 certificate for the server.

Returns:
The server certificate or null if no certificate has been specified

getClientCertificate

public byte[] getClientCertificate()
Get the client certificate that BASE should use to authenticate with the server when connecting with https. This property is typically needed when the server requires clients to authenticate themselves using a certificate. The certificate must be a PKCS #12 certificate in binary format, and it should contain only one certificate. NOTE! WRITE permission is required to read this property since it may contain sensitive data, use getClientX509Certificate() to get the public information from the certificate.

Returns:
A byte array with the certificate or null if no certificate has been set
See Also:
getClientX509Certificate()

setClientCertificate

public void setClientCertificate(byte[] certificate)
Set the client certificate that BASE should use to authenticate with the server when connecting with https. The certificate must be a PKCS #12 certificate in binary format, and it should contain only one certificate.

Parameters:
certificate - The client certificate or null if no certificate is required

getClientX509Certificate

public X509Certificate getClientX509Certificate()
Get the X.509 certificate for the client.

Returns:
The client certificate or null if no certificate has been specified

getClientCertificatePassword

public String getClientCertificatePassword()
Get the password that is needed to unlock the client certificate. NOTE! WRITE permission is required to read this property.

Returns:
The password (which may be null)

setClientCertificatePassword

public void setClientCertificatePassword(String password)
                                  throws PermissionDeniedException,
                                         InvalidDataException
Set the password that is needed to unlock the client certificate.

Parameters:
password - The new password (can be null)
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the password is longer than MAX_PASSWORD_LENGTH

getSSLSocketFactory

public org.apache.http.conn.ssl.SSLSocketFactory getSSLSocketFactory()
Get a socket factory that can be used to create SSL connections to the given server. If a server and/or client certificate has been specified for this file server the socket factory will be created with those certificates. Otherwise, the default (as configured in base.config) certificates are used.

Returns:
A SSL socket factory

getFiles

public ItemQuery<File> getFiles()
Get a query returning all files that has been registered with this server.


2.17.2: 2011-06-17