jacquard 1.12.0 by The Web Engineering Factory and Toolworks

uk.co.weft.dbutil
Class JDBCUserKluge

java.lang.Object
  extended byuk.co.weft.htform.ResourceConsumerImpl
      extended byuk.co.weft.dbutil.JDBCUserKluge
All Implemented Interfaces:
ResourceConsumer

public class JDBCUserKluge
extends ResourceConsumerImpl

JDBC does not provide any unified or portable way to deal with adding modifying and deleting user accounts, but in an application its often important that a user should be able to change their password; this is an attempt to provide a consistent, database independent API for creating, modifying and deleting database-layer user accounts. Obviously, it depends on the currently logged in user having authority to do these things. The per-database-type syntax for carrying out the operations is loaded from a repository as an XML document. A list of repositories is searched with the hard-wired last fallback being one at www.weft.co.uk which I will maintain. As new syntaxes are added to this repository they will automatically become available to all Jacquard applications out there in netland, even if they were not available when the application was compiled. Clearly this class could be extended. It could cover creating and deleting groups, and other areas of variant syntax. If you extend it I would be grateful of patches. Yes, it's a kluge, but just at this moment I'm feeling pretty proud of it. TODO: Create JDBCUserKlugeLite which uses the same syntax repository meachanism but isn't dependent on the whole Jacquard infrastructure.


Field Summary
static java.lang.String ADDSYNTAXTOKEN
          a token on which I will seek in my configuration 'extra' password syntaxes over and above those I already know
protected static java.lang.String ADDTOGROUPTOKEN
          values of the templatetype attribute: add to group
protected static java.lang.String BUNDLEELEMENTTAG
          tokens which name elements in the XML dialect I expect: the bundle of templates
protected static java.lang.String CHANGEPASSTOKEN
          values of the templatetype attribute: change password
protected static java.lang.String CREATEUSERTOKEN
          values of the templatetype attribute: create user
protected static java.lang.String DBTYPEATTRIBUTETAG
          tokens which name elements in the XML dialect I expect: the database type
protected static java.lang.String DELETEUSERTOKEN
          values of the templatetype attribute: drop user
protected static java.lang.String GROUPATTRIBUTETAG
          tokens which name elements in the XML dialect I expect: the template
protected static java.lang.String JDBCPROTOCOLPART
          the protocol part of a JDBC URL
protected static java.lang.String LEAVEGROUPTOKEN
          values of the templatetype attribute: remove from group
protected static int MAXSLOTS
          the maximum number of slots in a query that we will believe (i.e.
protected static java.lang.String MISSINGGROUPTOKEN
          something to put in for a group name where there should be no group name
protected static java.lang.String MISSINGPASSWORDTOKEN
          something to put in for a password where there should be no password
protected static java.lang.String PASSATTRIBUTETAG
          tokens which name elements in the XML dialect I expect: the template
protected  java.util.Vector repositories
          the vector of repository URLs which I will try in reverse order
protected  java.lang.String repository
          the fallback repository from which I will fetch syntax specifiers
protected  java.util.Hashtable syntaxes
          the password syntaxes I know about
static java.lang.String SYNTAXREPOSITORYTOKEN
          a token on which I will seek the URL of the syntax repository in my configuration
protected static java.lang.String TEMPLATEELEMENTTAG
          tokens which name elements in the XML dialect I expect: the template
protected static int TEMPLATETYPEADDTOGROUP
          the type of a template to add a user to a group
protected static int TEMPLATETYPECHANGEPASS
          the type of a template to change a user's password
protected static int TEMPLATETYPECREATEUSER
          the type of a template to create a user
protected static int TEMPLATETYPEDELETEUSER
          the type of a template to delete a user
protected static int TEMPLATETYPELEAVEGROUP
          the type of a template to remove a user from a group
protected static java.lang.String TYPEATTRIBUTETAG
          tokens which name elements in the XML dialect I expect: the template
protected static java.lang.String USERATTRIBUTETAG
          tokens which name elements in the XML dialect I expect: the template
 
Fields inherited from class uk.co.weft.htform.ResourceConsumerImpl
resourceBundleName
 
Fields inherited from interface uk.co.weft.htform.ResourceConsumer
RESOURCEBUNDLEMAGICTOKEN
 
Constructor Summary
JDBCUserKluge()
          create a new Kluge which knows only about the default repository
JDBCUserKluge(Context config)
          create a new Kluge which also knows about a repository specified in this config
 
Method Summary
 void addRepository(java.lang.String repository)
          add this URL to my repositories.
 uk.co.weft.dbutil.JDBCUserKluge.UserSyntax addSyntax(Document doc)
          initialise me from this document, assumed to be in my own special XML format
 void addUser(Context context, java.lang.String user, java.lang.String password)
          Add a user over the JDBC connection implied by this context with this username and this password
 void addUserToGroup(Context context, java.lang.String username, java.lang.String group)
          add this user to this group over the JDBC connection implied by this context
 void changePassword(Context context, java.lang.String password)
          Change password for the currently logged in user over the JDBC connection implied by this context to this password
 void changePassword(Context context, java.lang.String username, java.lang.String password)
          Change password for the a user over the JDBC connection implied by this context to this password
protected  java.lang.String dbTypeFromUrl(java.lang.String url)
          take a JDBC URL and extract the dbtype string
 void dropUser(Context context, java.lang.String user)
          drop a user over the JDBC connection implied by this context
protected  uk.co.weft.dbutil.JDBCUserKluge.UserSyntax fetchSyntax(java.lang.String dbtype)
          fetch the syntax specifier for this database type identifier
 void removeUserFromGroup(Context context, java.lang.String username, java.lang.String group)
          remove this user from this group over the JDBC connection implied by this context
 
Methods inherited from class uk.co.weft.htform.ResourceConsumerImpl
getContextOrResource, getResource, getResourceOrContext, getResourceString, grs, grs, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMPLATETYPECREATEUSER

protected static final int TEMPLATETYPECREATEUSER
the type of a template to create a user

See Also:
Constant Field Values

TEMPLATETYPECHANGEPASS

protected static final int TEMPLATETYPECHANGEPASS
the type of a template to change a user's password

See Also:
Constant Field Values

TEMPLATETYPEDELETEUSER

protected static final int TEMPLATETYPEDELETEUSER
the type of a template to delete a user

See Also:
Constant Field Values

TEMPLATETYPEADDTOGROUP

protected static final int TEMPLATETYPEADDTOGROUP
the type of a template to add a user to a group

See Also:
Constant Field Values

TEMPLATETYPELEAVEGROUP

protected static final int TEMPLATETYPELEAVEGROUP
the type of a template to remove a user from a group

See Also:
Constant Field Values

BUNDLEELEMENTTAG

protected static final java.lang.String BUNDLEELEMENTTAG
tokens which name elements in the XML dialect I expect: the bundle of templates

See Also:
Constant Field Values

DBTYPEATTRIBUTETAG

protected static final java.lang.String DBTYPEATTRIBUTETAG
tokens which name elements in the XML dialect I expect: the database type

See Also:
Constant Field Values

TEMPLATEELEMENTTAG

protected static final java.lang.String TEMPLATEELEMENTTAG
tokens which name elements in the XML dialect I expect: the template

See Also:
Constant Field Values

TYPEATTRIBUTETAG

protected static final java.lang.String TYPEATTRIBUTETAG
tokens which name elements in the XML dialect I expect: the template

See Also:
Constant Field Values

USERATTRIBUTETAG

protected static final java.lang.String USERATTRIBUTETAG
tokens which name elements in the XML dialect I expect: the template

See Also:
Constant Field Values

PASSATTRIBUTETAG

protected static final java.lang.String PASSATTRIBUTETAG
tokens which name elements in the XML dialect I expect: the template

See Also:
Constant Field Values

GROUPATTRIBUTETAG

protected static final java.lang.String GROUPATTRIBUTETAG
tokens which name elements in the XML dialect I expect: the template

See Also:
Constant Field Values

JDBCPROTOCOLPART

protected static final java.lang.String JDBCPROTOCOLPART
the protocol part of a JDBC URL

See Also:
Constant Field Values

CREATEUSERTOKEN

protected static final java.lang.String CREATEUSERTOKEN
values of the templatetype attribute: create user

See Also:
Constant Field Values

CHANGEPASSTOKEN

protected static final java.lang.String CHANGEPASSTOKEN
values of the templatetype attribute: change password

See Also:
Constant Field Values

DELETEUSERTOKEN

protected static final java.lang.String DELETEUSERTOKEN
values of the templatetype attribute: drop user

See Also:
Constant Field Values

ADDTOGROUPTOKEN

protected static final java.lang.String ADDTOGROUPTOKEN
values of the templatetype attribute: add to group

See Also:
Constant Field Values

LEAVEGROUPTOKEN

protected static final java.lang.String LEAVEGROUPTOKEN
values of the templatetype attribute: remove from group

See Also:
Constant Field Values

MISSINGPASSWORDTOKEN

protected static final java.lang.String MISSINGPASSWORDTOKEN
something to put in for a password where there should be no password

See Also:
Constant Field Values

MISSINGGROUPTOKEN

protected static final java.lang.String MISSINGGROUPTOKEN
something to put in for a group name where there should be no group name

See Also:
Constant Field Values

ADDSYNTAXTOKEN

public static final java.lang.String ADDSYNTAXTOKEN
a token on which I will seek in my configuration 'extra' password syntaxes over and above those I already know

See Also:
Constant Field Values

SYNTAXREPOSITORYTOKEN

public static final java.lang.String SYNTAXREPOSITORYTOKEN
a token on which I will seek the URL of the syntax repository in my configuration

See Also:
Constant Field Values

MAXSLOTS

protected static final int MAXSLOTS
the maximum number of slots in a query that we will believe (i.e. the maximum legal value of any of the 'user', 'pass', 'group' attributes of the template element

See Also:
Constant Field Values

syntaxes

protected java.util.Hashtable syntaxes
the password syntaxes I know about


repository

protected java.lang.String repository
the fallback repository from which I will fetch syntax specifiers


repositories

protected java.util.Vector repositories
the vector of repository URLs which I will try in reverse order

Constructor Detail

JDBCUserKluge

public JDBCUserKluge()
create a new Kluge which knows only about the default repository


JDBCUserKluge

public JDBCUserKluge(Context config)
create a new Kluge which also knows about a repository specified in this config

Parameters:
config - a context which may have details of another repository
Method Detail

addRepository

public void addRepository(java.lang.String repository)
add this URL to my repositories. The repositories are searched in reverse order so the last added is searched first

Parameters:
repository - the URL of a repository

addSyntax

public uk.co.weft.dbutil.JDBCUserKluge.UserSyntax addSyntax(Document doc)
                                                     throws DataStoreException
initialise me from this document, assumed to be in my own special XML format

Throws:
DataStoreException

fetchSyntax

protected uk.co.weft.dbutil.JDBCUserKluge.UserSyntax fetchSyntax(java.lang.String dbtype)
                                                          throws DataStoreException
fetch the syntax specifier for this database type identifier

Parameters:
dbtype - a database type identifier, being the full sub-protocol part of a JDBC URL which specifies the database type being addressed
Throws:
DataStoreException - if syntax cannot be fetched.

dbTypeFromUrl

protected java.lang.String dbTypeFromUrl(java.lang.String url)
                                  throws DataFormatException
take a JDBC URL and extract the dbtype string

Parameters:
url - the JDBC url
Returns:
the full sub-protocol part
Throws:
DataFormatException

addUser

public void addUser(Context context,
                    java.lang.String user,
                    java.lang.String password)
             throws DataStoreException
Add a user over the JDBC connection implied by this context with this username and this password

Parameters:
context - the context
user - the username.
password - the password.
Throws:
DataStoreException - if the database misbehaves in an expected way
Since:
Jacquard 1.10.1 SQLException is no longer thrown.

dropUser

public void dropUser(Context context,
                     java.lang.String user)
              throws DataStoreException
drop a user over the JDBC connection implied by this context

Parameters:
context - the context
user - the username.
Throws:
DataStoreException - if the database misbehaves in an expected way
Since:
Jacquard 1.10.1 SQLException is no longer thrown.

changePassword

public void changePassword(Context context,
                           java.lang.String password)
                    throws DataStoreException
Change password for the currently logged in user over the JDBC connection implied by this context to this password

Parameters:
context - the context
password - the password.
Throws:
DataStoreException - if the database misbehaves in an expected way
Since:
Jacquard 1.10.1 SQLException is no longer thrown.

changePassword

public void changePassword(Context context,
                           java.lang.String username,
                           java.lang.String password)
                    throws DataStoreException
Change password for the a user over the JDBC connection implied by this context to this password

Parameters:
context - the context
username - the username.
password - the password.
Throws:
DataStoreException - if the database misbehaves in an expected way
Since:
Jacquard 1.10.1 SQLException is no longer thrown.

addUserToGroup

public void addUserToGroup(Context context,
                           java.lang.String username,
                           java.lang.String group)
                    throws DataStoreException
add this user to this group over the JDBC connection implied by this context

Parameters:
context - the context
username - the user name
group - the group
Throws:
DataStoreException - if the database misbehaves in an expected way

removeUserFromGroup

public void removeUserFromGroup(Context context,
                                java.lang.String username,
                                java.lang.String group)
                         throws java.sql.SQLException,
                                DataStoreException
remove this user from this group over the JDBC connection implied by this context

Parameters:
context - the context
username - the user name
group - the group
Throws:
DataStoreException - if the database misbehaves in an expected way
java.sql.SQLException

jacquard 1.12.0 by The Web Engineering Factory and Toolworks