org.eaglei.repository.model
Class User

java.lang.Object
  extended by org.eaglei.repository.model.ImmutableObjectModel
      extended by org.eaglei.repository.model.WritableObjectModel
          extended by org.eaglei.repository.model.User

public final class User
extends WritableObjectModel

User object model, reflects the user's properties in the both RDBMS and RDF database. Also manages the RDF descriptions of users. Named Graph Usage: 1. Almost all statements about a repo User are in the graph named "repo:NG_Users". 2. Ony the :hasPrincipalName statement is on the NG_Internal graph sicne it should not be exposed; there is no reason to let login names leak and it's good security practice to keep them hidden, since that just makes dictionary attacks so much easier.

Version:
$Id: $
Author:
Larry Stone Started April 26, 2010
See Also:
AuthUser, ImportExport

Field Summary
static org.openrdf.query.impl.DatasetImpl USER_DATASET
          dataset that includes relevant graphs - internal and user
static org.openrdf.model.URI USER_GRAPH
          Named graph where we create User objects.
 
Method Summary
 void addRole(javax.servlet.http.HttpServletRequest request, Role r)
          addRole - add a role
 void addRole(javax.servlet.http.HttpServletRequest request, org.openrdf.model.URI ru)
          addRole - add a role
 void addRoleAsAdministrator(javax.servlet.http.HttpServletRequest request, Role r)
          addRoleAsAdministrator - add a role WITHOUT access control checks
 boolean authenticate(java.lang.String pw)
          compare password (or credientals) without revealing anythign
 void commit(javax.servlet.http.HttpServletRequest request)
           Commits any changes to RDF database *and* RDBMS.
static void commitMultiple(javax.servlet.http.HttpServletRequest request, java.util.Collection<User> users)
          Runs commit() on a batch of users at once for greater efficiency in imports.
static User create(javax.servlet.http.HttpServletRequest request, java.lang.String username, java.lang.String password)
           Create new user instance for given username.
static User create(javax.servlet.http.HttpServletRequest request, org.openrdf.model.URI uri, java.lang.String username, java.lang.String password)
           Create new user instance for given username AND URI.
static User createAsAdministrator(javax.servlet.http.HttpServletRequest request, java.lang.String username, java.lang.String password)
           Create new user instance for given username.
 void disable()
          Remove ability to login with credentials
 boolean equals(java.lang.Object o)
           Equality is defined as EITHER URI or uesrname equal -since some instances may not have a URI at first but always(?) have a username
protected  void finalize()
          finalize - flag error if GC'ing a dirty instance, its changes are lost.
static User find(javax.servlet.http.HttpServletRequest request, org.openrdf.model.URI uri)
          Find a user record by URI; Returns null if NOT found..
static java.util.List<User> findAll(javax.servlet.http.HttpServletRequest request)
          Get all known Users from RDF DB - may not match auth'n DB.
static User findByUsername(javax.servlet.http.HttpServletRequest request, java.lang.String pname)
          find a record by username, i.e.
 org.openrdf.model.URI getAuthType()
          Get the URI identifying the kind of authorization behind this user, needed for export and import.
 java.lang.String getFirstName()
          Getter for the field firstName.
 java.lang.String getLabel()
          Computes the most informative "label" for a user, to present in UI.
 java.lang.String getLastName()
          Getter for the field lastName.
 java.lang.String getMbox()
          Getter for the field mbox.
 java.lang.String getPassword()
          Getter for password.
 java.lang.String getPersonalName()
          Get personal name, if available, as "firstname lastname".
 org.openrdf.model.URI getURI()
          Getter for the field uri.
 java.lang.String getUsername()
          Getter for the field username.
 int hashCode()
          
 boolean hasRoleP(Role r)
          has role predicate - the P suffix is a Lisp thing
 boolean hasRoleP(org.openrdf.model.URI ru)
          hasRoleP
 boolean isLoginable()
          does this user have credentials to be able to login.
 boolean isSuperuser()
          isSuperuser
 void recreate(javax.servlet.http.HttpServletRequest request, org.openrdf.model.URI newURI, java.lang.String newUsername, java.lang.String pw)
          Create a new user graph to replace the existing user, for import.
 void reinstate(java.lang.String pw)
          Restore ability to login with credentials
 void removeRole(javax.servlet.http.HttpServletRequest request, Role r)
          removeRole
 void removeRole(javax.servlet.http.HttpServletRequest request, org.openrdf.model.URI ru)
          removeRole
 void setAuthType(javax.servlet.http.HttpServletRequest request, org.openrdf.model.URI uri)
          Ignores request but arg is there for uniformity.
 void setFirstName(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Change value of first name.
 void setIsSuperuser(boolean su)
          setIsSuperuser
 void setLastName(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Setter for the field lastName.
 void setMbox(javax.servlet.http.HttpServletRequest request, java.lang.String mbox)
          Setter for the field mbox.
 void setPassword(javax.servlet.http.HttpServletRequest request, java.lang.String pw)
          Ignores request but arg is there for uniformity.
 boolean setProperty(javax.servlet.http.HttpServletRequest request, org.openrdf.model.URI property, java.lang.String value)
          Set a random property on the user (for RDF import).
 boolean setRoles(javax.servlet.http.HttpServletRequest request, Role[] newRoles)
          setRoles
 java.lang.String toString()
          toString
 
Methods inherited from class org.eaglei.repository.model.WritableObjectModel
decacheInstance, isDirty, setDirty, update
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

USER_GRAPH

public static final org.openrdf.model.URI USER_GRAPH
Named graph where we create User objects. Note taht the hasPrincipalName is still on the Internal graph, it's confidential.


USER_DATASET

public static final org.openrdf.query.impl.DatasetImpl USER_DATASET
dataset that includes relevant graphs - internal and user

Method Detail

findByUsername

public static User findByUsername(javax.servlet.http.HttpServletRequest request,
                                  java.lang.String pname)
                           throws javax.servlet.ServletException
find a record by username, i.e. login principal name Returns null if NOT found.

Parameters:
request - a HttpServletRequest object.
pname - principal name (from user account RDBMS).
Returns:
the User object, or null if none found.
Throws:
javax.servlet.ServletException - if any.

find

public static User find(javax.servlet.http.HttpServletRequest request,
                        org.openrdf.model.URI uri)
                 throws javax.servlet.ServletException
Find a user record by URI; Returns null if NOT found..

Parameters:
request - a HttpServletRequest object.
uri - the URI of a person object
Returns:
the User object, or null if none found.
Throws:
javax.servlet.ServletException - if any.

findAll

public static java.util.List<User> findAll(javax.servlet.http.HttpServletRequest request)
                                    throws javax.servlet.ServletException

Get all known Users from RDF DB - may not match auth'n DB.
XXX TODO should add start and count for pagination

Parameters:
request - a HttpServletRequest object.
Returns:
resulting Users in a Iterable object.
Throws:
javax.servlet.ServletException - if any.

create

public static User create(javax.servlet.http.HttpServletRequest request,
                          java.lang.String username,
                          java.lang.String password)
                   throws javax.servlet.ServletException

Create new user instance for given username. Returns User object with URI and username set; nothing else. Fails if there is an existing user with the same principal. Requires Administrator role.

Parameters:
request - a HttpServletRequest object.
username - principal name, a String object.
password - the password or null if not login-able
Returns:
the new org.eaglei.repository.User object.
Throws:
javax.servlet.ServletException - if any.

createAsAdministrator

public static User createAsAdministrator(javax.servlet.http.HttpServletRequest request,
                                         java.lang.String username,
                                         java.lang.String password)
                                  throws javax.servlet.ServletException

Create new user instance for given username. Returns User object with URI and username set; nothing else. Fails if there is an existing user with the same principal. Skip access test -- THIS IS VERY DANGEROUS, only for bootstrapping the authentication.

Parameters:
request - a HttpServletRequest object.
username - principal name, a String object.
password - the password or null if not login-able
Returns:
the new org.eaglei.repository.User object.
Throws:
javax.servlet.ServletException - if any.

create

public static User create(javax.servlet.http.HttpServletRequest request,
                          org.openrdf.model.URI uri,
                          java.lang.String username,
                          java.lang.String password)
                   throws javax.servlet.ServletException

Create new user instance for given username AND URI. Returns User object with URI and username set; nothing else. Fails if there is an existing user with the same principal. Requires Administrator role.

Parameters:
request - a HttpServletRequest object.
username - principal name, a String object.
password - the password or null if not login-able
Returns:
the new org.eaglei.repository.User object.
Throws:
javax.servlet.ServletException - if any.

getURI

public org.openrdf.model.URI getURI()

Getter for the field uri.

Specified by:
getURI in class ImmutableObjectModel
Returns:
a URI object.

getUsername

public java.lang.String getUsername()

Getter for the field username.

Returns:
a String object.

getFirstName

public java.lang.String getFirstName()

Getter for the field firstName.

Returns:
a String object or null if not set.

getLastName

public java.lang.String getLastName()

Getter for the field lastName.

Returns:
a String object or null if not set.

getMbox

public java.lang.String getMbox()

Getter for the field mbox.

Returns:
a String object or null if not set.

getLabel

public java.lang.String getLabel()
Computes the most informative "label" for a user, to present in UI. Format is, ideally, "username (firstname lastname)" But it reverts to bare username or even URI if none is available.

Specified by:
getLabel in class ImmutableObjectModel
Returns:
label as a String object.

getPersonalName

public java.lang.String getPersonalName()

Get personal name, if available, as "firstname lastname".

Returns:
name in String or else empty string if there is none; never null.

hasRoleP

public boolean hasRoleP(Role r)
has role predicate - the P suffix is a Lisp thing

Parameters:
r - role as a org.eaglei.repository.Role object.
Returns:
a boolean, true if this User has indicated role.

hasRoleP

public boolean hasRoleP(org.openrdf.model.URI ru)

hasRoleP

Parameters:
ru - role as a URI object.
Returns:
a boolean, true if this User has indicated role.

isSuperuser

public boolean isSuperuser()

isSuperuser

- convenience method to test for superuser (administrator) role

Returns:
a boolean, true if this User has Superuser (Admin) role.

setIsSuperuser

public void setIsSuperuser(boolean su)

setIsSuperuser

- change local value of Superuser bit WITHOUT updating the RDF description, ONLY for cached local User object.

Parameters:
su - a boolean, true if this User has Superuser (Admin) role.

setFirstName

public void setFirstName(javax.servlet.http.HttpServletRequest request,
                         java.lang.String name)
                  throws javax.servlet.ServletException
Change value of first name. Setting it to null clears it.

Parameters:
request - a HttpServletRequest object.
name - first name a String object.
Throws:
javax.servlet.ServletException - if any.

setLastName

public void setLastName(javax.servlet.http.HttpServletRequest request,
                        java.lang.String name)
                 throws javax.servlet.ServletException

Setter for the field lastName.

Parameters:
request - a HttpServletRequest object.
name - a String object.
Throws:
javax.servlet.ServletException - if any.

setMbox

public void setMbox(javax.servlet.http.HttpServletRequest request,
                    java.lang.String mbox)
             throws javax.servlet.ServletException

Setter for the field mbox.

Parameters:
request - a HttpServletRequest object.
mbox - a String object.
Throws:
javax.servlet.ServletException - if any.

setProperty

public boolean setProperty(javax.servlet.http.HttpServletRequest request,
                           org.openrdf.model.URI property,
                           java.lang.String value)
                    throws javax.servlet.ServletException
Set a random property on the user (for RDF import).

Returns:
true if it was a valid property, false if ignored.
Throws:
javax.servlet.ServletException

recreate

public void recreate(javax.servlet.http.HttpServletRequest request,
                     org.openrdf.model.URI newURI,
                     java.lang.String newUsername,
                     java.lang.String pw)
              throws javax.servlet.ServletException
Create a new user graph to replace the existing user, for import. Clear all properties and roles, add back username, and credentials if given.

Throws:
javax.servlet.ServletException

addRole

public void addRole(javax.servlet.http.HttpServletRequest request,
                    org.openrdf.model.URI ru)
             throws javax.servlet.ServletException

addRole - add a role

Parameters:
request - a HttpServletRequest object.
ru - Role to add, as a URI object.
Throws:
javax.servlet.ServletException - if any.

addRole

public void addRole(javax.servlet.http.HttpServletRequest request,
                    Role r)
             throws javax.servlet.ServletException

addRole - add a role

Parameters:
request - a HttpServletRequest object.
r - role to add as a org.eaglei.repository.Role object.
Throws:
javax.servlet.ServletException - if any.

addRoleAsAdministrator

public void addRoleAsAdministrator(javax.servlet.http.HttpServletRequest request,
                                   Role r)
                            throws javax.servlet.ServletException

addRoleAsAdministrator - add a role WITHOUT access control checks

Parameters:
request - a HttpServletRequest object.
r - role to add as a org.eaglei.repository.Role object.
Throws:
javax.servlet.ServletException - if any.

removeRole

public void removeRole(javax.servlet.http.HttpServletRequest request,
                       org.openrdf.model.URI ru)
                throws javax.servlet.ServletException

removeRole

Parameters:
request - a HttpServletRequest object.
ru - role to remove as a URI object.
Throws:
javax.servlet.ServletException - if any.

removeRole

public void removeRole(javax.servlet.http.HttpServletRequest request,
                       Role r)
                throws javax.servlet.ServletException

removeRole

Parameters:
request - a HttpServletRequest object.
r - role to remove as a org.eaglei.repository.Role object.
Throws:
javax.servlet.ServletException - if any.

setRoles

public boolean setRoles(javax.servlet.http.HttpServletRequest request,
                        Role[] newRoles)
                 throws javax.servlet.ServletException

setRoles

make the user's set of roles equal to contents of this array

Parameters:
request - a HttpServletRequest object.
role - array of Role objects which should be the new role set
Returns:
true if any roles were actually changed.
Throws:
javax.servlet.ServletException - if any.

commit

public void commit(javax.servlet.http.HttpServletRequest request)
            throws javax.servlet.ServletException

Commits any changes to RDF database *and* RDBMS. Also recomputes rdfs:label, passes superuser bit into RDBMS. Does *not* need to check access again here because the only operatiosn taht set "dirty" are already access-protected..

Overrides:
commit in class WritableObjectModel
Parameters:
request - a HttpServletRequest object.
Throws:
javax.servlet.ServletException - if any.

commitMultiple

public static void commitMultiple(javax.servlet.http.HttpServletRequest request,
                                  java.util.Collection<User> users)
                           throws javax.servlet.ServletException
Runs commit() on a batch of users at once for greater efficiency in imports.

Throws:
javax.servlet.ServletException

finalize

protected void finalize()
                 throws java.lang.Throwable

finalize - flag error if GC'ing a dirty instance, its changes are lost.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

toString

public java.lang.String toString()

toString

Overrides:
toString in class java.lang.Object
Returns:
a String object.

equals

public boolean equals(java.lang.Object o)
Equality is defined as EITHER URI or uesrname equal -since some instances may not have a URI at first but always(?) have a username

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

isLoginable

public boolean isLoginable()
does this user have credentials to be able to login.

Returns:
true if user can login (i.e. is not disabled)

authenticate

public boolean authenticate(java.lang.String pw)
compare password (or credientals) without revealing anythign

Returns:
true if given credential would let user login

getPassword

public java.lang.String getPassword()
Getter for password.


setPassword

public void setPassword(javax.servlet.http.HttpServletRequest request,
                        java.lang.String pw)
Ignores request but arg is there for uniformity.


disable

public void disable()
Remove ability to login with credentials


reinstate

public void reinstate(java.lang.String pw)
Restore ability to login with credentials


getAuthType

public org.openrdf.model.URI getAuthType()
Get the URI identifying the kind of authorization behind this user, needed for export and import. XXX waiting for a pluggable auth interface


setAuthType

public void setAuthType(javax.servlet.http.HttpServletRequest request,
                        org.openrdf.model.URI uri)
Ignores request but arg is there for uniformity. XXX Not really implemented, just a sanity check for now. XXX waiting for a pluggable auth interface



Copyright © 2009-2011 Eagle-I. All Rights Reserved.