com.knowgate.acl
Class ACLUser

java.lang.Object
  extended bycom.knowgate.dataobjs.DBPersist
      extended bycom.knowgate.acl.ACLUser
All Implemented Interfaces:
java.util.Map

public final class ACLUser
extends DBPersist

Object mapping for k_users table registers

Version:
3.0

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
static short ClassId
           
 
Fields inherited from class com.knowgate.dataobjs.DBPersist
AllVals, sAuditCls, sAuditUsr, sTransactId
 
Constructor Summary
ACLUser()
          Default constructor.
ACLUser(JDCConnection oConn, java.lang.String sUserGUID)
          Constructs ACLUser and load attributes from k_users table
ACLUser(java.lang.String sUserGUID)
          Constructs ACLUser and set GUID
 
Method Summary
 int addToACLGroups(JDCConnection oConn, java.lang.String sGroupList)
          Add User to Groups.
 int clearACLGroups(JDCConnection oConn)
          Remove user from all security role groups
static java.lang.String create(JDCConnection oConn, java.lang.Object[] Values)
          Deprecated. Use standard put/store methods instead.
 boolean delete(JDCConnection oConn)
          Delete a register from database
static boolean delete(JDCConnection oConn, java.lang.String sUserGUID)
          Delete User
 DBSubset getAddresses(JDCConnection oConn)
          Get Addresses associated with user at k_x_addr_user table.
static java.lang.String getEmailFromId(JDCConnection oConn, java.lang.String sUserId)
          Get User main e-mail from its GUID.
 DBSubset getGroups(JDCConnection oConn)
          Get security role groups to witch this user belongs looking a k_x_group_user table.
static java.lang.String getIdFromEmail(JDCConnection oConn, java.lang.String sUserEMail)
          Get User Unique Id.
static java.lang.String getIdFromNick(java.sql.Connection oConn, int iDomainId, java.lang.String sUserNick)
          Get User Unique Id.
static java.lang.String getIdFromNick(JDCConnection oConn, int iDomainId, java.lang.String sUserNick)
          Get User Unique Id.
 java.lang.String getMailFolder(JDCConnection oConn, java.lang.String sFolderName)
          Get GUID of user mail folder category
 java.lang.String getMailRoot(JDCConnection oConn)
          Get GUID of user mail root category
 int getRolesForApplication(JDCConnection oConn, int iIdApp, java.lang.String sGuWorkArea)
          Get roles of this user for a given application and workarea
 boolean isAdminForApplication(JDCConnection oConn, int iIdApp)
          Find out if this user has administrator role in his default workarea over given application
 boolean isAdminForApplication(JDCConnection oConn, int iIdApp, java.lang.String sGuWorkArea)
          Find out if this user has administrator role over given application and workarea
 boolean isDomainAdmin(JDCConnection oConn)
          Find out is this user has administrator.
 boolean isGuestForApplication(JDCConnection oConn, int iIdApp)
          Find out if this user has guest role in his default workarea over given application
 boolean isPowerUserForApplication(JDCConnection oConn, int iIdApp)
          Find out if this user has power user role in his default workarea over given application
 boolean isPowerUserForApplication(JDCConnection oConn, int iIdApp, java.lang.String sGuWorkArea)
          Find out if this user has power user role over given application and workarea
 boolean isUserForApplication(JDCConnection oConn, int iIdApp)
          Find out if this user has plain user role in his default workarea over given application
 boolean isUserForApplication(JDCConnection oConn, int iIdApp, java.lang.String sGuWorkArea)
          Find out if this user has plain user role over given application and workarea
 int removeFromACLGroup(JDCConnection oConn, java.lang.String sIdGroup)
          Remove User from Group.
 boolean store(JDCConnection oConn)
          Store ACLUser
 
Methods inherited from class com.knowgate.dataobjs.DBPersist
allcaps, allcaps, changelog, clear, clone, containsKey, containsValue, entrySet, exists, get, get, getAuditClassName, getCreationDate, getDate, getDateFormated, getDateShort, getDecimal, getDecimalFormated, getDouble, getDoubleFormated, getFloat, getFloatFormated, getInt, getInteger, getItemMap, getItems, getShort, getString, getStringNull, getTable, getTable, getTableName, getTime, getTimeOfDay, getTimestamp, getUIdFromName, isEmpty, isNull, iterator, keySet, load, load, parseXML, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, putAll, putAll, remove, remove, replace, replace, replace, replace, setAuditTransact, setAuditUser, size, toLowerCase, toUpperCase, toXML, toXML, toXML, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

ClassId

public static final short ClassId
See Also:
Constant Field Values
Constructor Detail

ACLUser

public ACLUser()
Default constructor.


ACLUser

public ACLUser(java.lang.String sUserGUID)
        throws java.sql.SQLException

Constructs ACLUser and set GUID

Does not load any fields from database.

Parameters:
sUserGUID - user Unique Identifier (gu_user field at k_users table)
Throws:
java.sql.SQLException

ACLUser

public ACLUser(JDCConnection oConn,
               java.lang.String sUserGUID)
        throws java.sql.SQLException

Constructs ACLUser and load attributes from k_users table

Parameters:
oConn - Database Connection
sUserGUID - user Unique Identifier (gu_user field at k_users table)
Throws:
java.sql.SQLException
Method Detail

getAddresses

public DBSubset getAddresses(JDCConnection oConn)
                      throws java.sql.SQLException

Get Addresses associated with user at k_x_addr_user table.

Parameters:
oConn - Database Connection
Returns:
A DBSubset with a 3 columns containing Address Unique Identifier (gu_address), Address Ordinal Position (ix_address) and Address Location Type (tp_location).
Throws:
java.sql.SQLException
See Also:
{@link Address}

getGroups

public DBSubset getGroups(JDCConnection oConn)
                   throws java.sql.SQLException

Get security role groups to witch this user belongs looking a k_x_group_user table.

Parameters:
oConn - Database Connection
Returns:
A DBSubset with a 1 column containing each group unique identifier (gu_acl_group).
Throws:
java.sql.SQLException

addToACLGroups

public int addToACLGroups(JDCConnection oConn,
                          java.lang.String sGroupList)
                   throws java.sql.SQLException

Add User to Groups.

Insert new registers at k_x_group_user table.

Parameters:
oConn - Database Connection
sGroupList - A string of comma delimited ACLGroup GUIDs to with this ACLUser must be added.
Throws:
java.sql.SQLException - May throw a primary key constraint violation is user already belongs to group.

isDomainAdmin

public boolean isDomainAdmin(JDCConnection oConn)
                      throws java.sql.SQLException,
                             java.lang.IllegalStateException

Find out is this user has administrator.

A user may have administrator priviledges in two ways:
1.- It can belong to the group gu_admins from k_domains table.
2.- Its user identifier may be the one at gu_owner field of k_domains table.

The domain owner is a special kind of administrator user that cannot be deleted from domain.

Parameters:
oConn - Database Connection
Returns:
true is user has adminsitrator priviledges, false otherwise.
Throws:
java.lang.IllegalStateException - if id_domain or gu_user is not set
java.sql.SQLException

store

public boolean store(JDCConnection oConn)
              throws java.sql.SQLException

Store ACLUser

If gu_user is not set then a new GUID is assigned.
If dt_last_update is not set then current system date is assigned.
If len_quota is not set then zero is assigned.
If max_quota is not set then 100Mb assigned.
Syntax for tx_main_email and tx_alt_email is verified if these fields are not null

Overrides:
store in class DBPersist
Parameters:
oConn - Database Connection
Returns:
true is register was stored for the first time, false if register already existed.
Throws:
java.sql.SQLException

delete

public boolean delete(JDCConnection oConn)
               throws java.sql.SQLException
Description copied from class: DBPersist

Delete a register from database

The deleted register will be the one matching this DBPersist primary key, as set at constructor or load() method.

Overrides:
delete in class DBPersist
Parameters:
oConn - Database connection
Returns:
true if register was successfully erased, false if not.
Throws:
java.sql.SQLException

clearACLGroups

public int clearACLGroups(JDCConnection oConn)
                   throws java.sql.SQLException

Remove user from all security role groups

Parameters:
oConn - Database Connection
Returns:
Count of groups from witch user was removed.
Throws:
java.sql.SQLException

removeFromACLGroup

public int removeFromACLGroup(JDCConnection oConn,
                              java.lang.String sIdGroup)
                       throws java.sql.SQLException

Remove User from Group.

remove register from k_x_group_user table.

Parameters:
oConn - Database Connection
sIdGroup - Group Unique Identifier.
Throws:
java.sql.SQLException

getMailRoot

public java.lang.String getMailRoot(JDCConnection oConn)
                             throws java.sql.SQLException

Get GUID of user mail root category

The user mail root category is always named DOMAIN_nickname_mail at nm_category field of k_categories.
If there is no category named DOMAIN_nickname_mail but the user has his gu_category field set at k_users table then this method tries to create a new mail root category.

Parameters:
oConn - Database Connection
Returns:
a gu_category value from k_categories or null if this user does not have a mail root category and a new one could not be created
Throws:
java.sql.SQLException

getMailFolder

public java.lang.String getMailFolder(JDCConnection oConn,
                                      java.lang.String sFolderName)
                               throws java.sql.SQLException

Get GUID of user mail folder category

The Inbox category is where messages downloaded from the mail server are cached by default. The user mail inbox category is always named DOMAIN_nickname_inbox at nm_category field of k_categories.
If there is no category named DOMAIN_nickname_inbox but the user has a mail root category then this method tries to create a new mail inbox category under mail root.

Parameters:
oConn - Database Connection
sFolderName - One of { "inbox", "drafts", "deleted", "sent", "spam" }
Returns:
a gu_category value from k_categories or null if this user does not have a mail inbox category and a new one could not be created
Throws:
java.sql.SQLException
java.lang.NullPointerException - if sFolderName is null or empty string

getRolesForApplication

public int getRolesForApplication(JDCConnection oConn,
                                  int iIdApp,
                                  java.lang.String sGuWorkArea)
                           throws java.sql.SQLException
Get roles of this user for a given application and workarea

Parameters:
oConn - JDCConnection
iIdApp - int Id of application (from k_apps table)
sGuWorkArea - String Guid of WorkArea (from k_workareas table)
Returns:
int Any bitwise OR combination of { ACL.ROLE_ADMIN || ACL.ROLE_POWERUSER || ACL.ROLE_USER || ACL.ROLE_GUEST }
Throws:
java.sql.SQLException
Since:
3.0

isAdminForApplication

public boolean isAdminForApplication(JDCConnection oConn,
                                     int iIdApp,
                                     java.lang.String sGuWorkArea)
                              throws java.sql.SQLException
Find out if this user has administrator role over given application and workarea

Parameters:
oConn - JDCConnection
iIdApp - int Id of application (from k_apps table)
sGuWorkArea - String Guid of WorkArea (from k_workareas table)
Returns:
boolean
Throws:
java.sql.SQLException
Since:
3.0

isPowerUserForApplication

public boolean isPowerUserForApplication(JDCConnection oConn,
                                         int iIdApp,
                                         java.lang.String sGuWorkArea)
                                  throws java.sql.SQLException
Find out if this user has power user role over given application and workarea

Parameters:
oConn - JDCConnection
iIdApp - int Id of application (from k_apps table)
sGuWorkArea - String Guid of WorkArea (from k_workareas table)
Returns:
boolean
Throws:
java.sql.SQLException
Since:
3.0

isUserForApplication

public boolean isUserForApplication(JDCConnection oConn,
                                    int iIdApp,
                                    java.lang.String sGuWorkArea)
                             throws java.sql.SQLException
Find out if this user has plain user role over given application and workarea

Parameters:
oConn - JDCConnection
iIdApp - int Id of application (from k_apps table)
sGuWorkArea - String Guid of WorkArea (from k_workareas table)
Returns:
boolean
Throws:
java.sql.SQLException
Since:
3.0

isAdminForApplication

public boolean isAdminForApplication(JDCConnection oConn,
                                     int iIdApp)
                              throws java.sql.SQLException
Find out if this user has administrator role in his default workarea over given application

Parameters:
oConn - JDCConnection
iIdApp - int Id of application (from k_apps table)
Returns:
boolean
Throws:
java.sql.SQLException
Since:
3.0

isPowerUserForApplication

public boolean isPowerUserForApplication(JDCConnection oConn,
                                         int iIdApp)
                                  throws java.sql.SQLException
Find out if this user has power user role in his default workarea over given application

Parameters:
oConn - JDCConnection
iIdApp - int Id of application (from k_apps table)
Returns:
boolean
Throws:
java.sql.SQLException
Since:
3.0

isUserForApplication

public boolean isUserForApplication(JDCConnection oConn,
                                    int iIdApp)
                             throws java.sql.SQLException
Find out if this user has plain user role in his default workarea over given application

Parameters:
oConn - JDCConnection
iIdApp - int Id of application (from k_apps table)
Returns:
boolean
Throws:
java.sql.SQLException
Since:
3.0

isGuestForApplication

public boolean isGuestForApplication(JDCConnection oConn,
                                     int iIdApp)
                              throws java.sql.SQLException
Find out if this user has guest role in his default workarea over given application

Parameters:
oConn - JDCConnection
iIdApp - int Id of application (from k_apps table)
Returns:
boolean
Throws:
java.sql.SQLException
Since:
3.0

getIdFromEmail

public static java.lang.String getIdFromEmail(JDCConnection oConn,
                                              java.lang.String sUserEMail)
                                       throws java.sql.SQLException

Get User Unique Id. from its main e-mail address.

This method calls k_get_user_from_email stored procedure.

Parameters:
oConn - Database Connection
sUserEMail - User main e-mail (tx_main_email from k_users table)
Returns:
User Unique Id. or null if no user was found with such e-mail.
Throws:
java.sql.SQLException

getEmailFromId

public static java.lang.String getEmailFromId(JDCConnection oConn,
                                              java.lang.String sUserId)
                                       throws java.sql.SQLException

Get User main e-mail from its GUID.

Parameters:
oConn - Database Connection
sUserId - User GUID (gu_user from k_users table)
Returns:
User tx_main_email or null if no user was found with such GUID.
Throws:
java.sql.SQLException

getIdFromNick

public static java.lang.String getIdFromNick(java.sql.Connection oConn,
                                             int iDomainId,
                                             java.lang.String sUserNick)
                                      throws java.sql.SQLException

Get User Unique Id. from its nickname.

This method executes a SQL query with a ResultSet

Parameters:
oConn - Database Connection
Returns:
User Unique Id. or null if no user was found with such e-mail.
Throws:
java.sql.SQLException

getIdFromNick

public static java.lang.String getIdFromNick(JDCConnection oConn,
                                             int iDomainId,
                                             java.lang.String sUserNick)
                                      throws java.sql.SQLException

Get User Unique Id. from its nickname.

This method calls k_get_user_from_nick stored procedure.

Parameters:
oConn - Database Connection
Returns:
User Unique Id. or null if no user was found with such e-mail.
Throws:
java.sql.SQLException
Since:
3.0

delete

public static boolean delete(JDCConnection oConn,
                             java.lang.String sUserGUID)
                      throws java.sql.SQLException,
                             java.io.IOException

Delete User

Categories owned by this user are also deleted, but other data and references for user are not checked.

Parameters:
oConn - Database Connection
sUserGUID - User Unique Identifier
Throws:
java.sql.SQLException
java.io.IOException

create

public static java.lang.String create(JDCConnection oConn,
                                      java.lang.Object[] Values)
                               throws java.sql.SQLException,
                                      java.lang.ClassCastException,
                                      java.lang.NullPointerException
Deprecated. Use standard put/store methods instead.

Shortcut for creating a new user

Parameters:
oConn - Database Connection
Values - User fields, all required, must be in this order { (Integer)id_domain, (String)tx_nickname, (String)tx_pwd, (Short)bo_active, (Short)bo_searchable, (Short)bo_change_pwd, (String)tx_main_email, (String)tx_alt_email, (String)nm_user, (String)tx_surname1, (String)tx_surname2, (String)tx_challenge, (String)tx_reply, (String)nm_company, (String)de_title, (String)gu_workarea }
Values up to and including tx_surname1 must be NOT NULL, values from tx_surname2 are required but may be null.
Returns:
New User Unique Identifier
Throws:
java.sql.SQLException
java.lang.ClassCastException
java.lang.NullPointerException