org.eaglei.repository
Class User

java.lang.Object
  extended by org.eaglei.repository.User

public class User
extends java.lang.Object

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

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
 void checkImplicitRoles(javax.servlet.http.HttpServletRequest request)
           Ensure this user has the implicit Anonymous and Authenticated roles.
static User create(javax.servlet.http.HttpServletRequest request, java.lang.String username)
           Create new user instance for given username.
static User createAsAdministrator(javax.servlet.http.HttpServletRequest request, java.lang.String username)
           Create new user instance for given username.
static void doExportUsers(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.openrdf.rio.RDFFormat format, java.util.Set<java.lang.String> includes, java.util.Set<java.lang.String> excludes)
          Export description of user accounts to serialized RDF quads.
static void doImportUsers(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.openrdf.repository.RepositoryConnection content, java.util.Set<java.lang.String> includes, java.util.Set<java.lang.String> excludes, ImportExport.DuplicateArg duplicate, boolean transform)
          Import description of user accounts from serialized RDF quads.
 boolean equals(java.lang.Object o)
          
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.lang.Iterable<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.
 java.lang.String getFirstName()
          Getter for the field firstName.
 java.lang.String getLastName()
          Getter for the field lastName.
 java.lang.String getMbox()
          Getter for the field mbox.
 java.lang.String getPersonalName()
          Get personal name, if available, as "firstname lastname".
 java.lang.String getTitle()
          Computes the most informative "label" for a user, to present in UI.
 org.openrdf.model.URI getURI()
          Getter for the field uri.
static org.openrdf.query.Dataset getUserDataset()
           
 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 isSuperuser()
          isSuperuser
 void removeRole(javax.servlet.http.HttpServletRequest request, Role r)
          removeRole
 void removeRole(javax.servlet.http.HttpServletRequest request, org.openrdf.model.URI ru)
          removeRole
 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.
 boolean setRoles(javax.servlet.http.HttpServletRequest request, Role[] newRoles)
          setRoles
 java.lang.String toString()
          toString
 void update(javax.servlet.http.HttpServletRequest request)
          update - Commits any changes to RDF database *and* RDBMS.
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getUserDataset

public static org.openrdf.query.Dataset getUserDataset()
Returns:
dataset of graphs needed to query for all repo users' data

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.. NOTE that user instance gets auto-created for a "new" principal upon login, so this CAN be called (by that code) when checking first before creating a new Person instance.

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.lang.Iterable<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.

getURI

public org.openrdf.model.URI getURI()

Getter for the field uri.

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.

getTitle

public java.lang.String getTitle()
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.

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 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.

checkImplicitRoles

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

Ensure this user has the implicit Anonymous and Authenticated roles.

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

create

public static User create(javax.servlet.http.HttpServletRequest request,
                          java.lang.String username)
                   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.
Returns:
the new User object.
Throws:
javax.servlet.ServletException - if any.

createAsAdministrator

public static User createAsAdministrator(javax.servlet.http.HttpServletRequest request,
                                         java.lang.String username)
                                  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.
Returns:
the new User object.
Throws:
javax.servlet.ServletException - if any.

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.

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 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 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 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.

update

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

update - 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..

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

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)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

doImportUsers

public static void doImportUsers(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response,
                                 org.openrdf.repository.RepositoryConnection content,
                                 java.util.Set<java.lang.String> includes,
                                 java.util.Set<java.lang.String> excludes,
                                 ImportExport.DuplicateArg duplicate,
                                 boolean transform)
                          throws javax.servlet.ServletException,
                                 java.io.IOException
Import description of user accounts from serialized RDF quads.

Throws:
javax.servlet.ServletException
java.io.IOException

doExportUsers

public static void doExportUsers(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response,
                                 org.openrdf.rio.RDFFormat format,
                                 java.util.Set<java.lang.String> includes,
                                 java.util.Set<java.lang.String> excludes)
                          throws javax.servlet.ServletException,
                                 java.io.IOException
Export description of user accounts to serialized RDF quads.

Throws:
javax.servlet.ServletException
java.io.IOException


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