Custom
User Manager
The
following is an example of a Java class named MyUserManager.java:
//*************************************************************************
//
// SL-GMS Graphical
Modeling Application, RTView Package
// MyUserManager.java
// Copyright (c) 1998-2006
Sherrill-Lubinski Corporation. All Rights Reserved.
// May 2005
//
//*************************************************************************
import java.util.*;
import com.sl.gmsjrtview.*;
/** The MyUserManager
class implements a custom user login.
* <P>
*/
public class MyUserManager
extends GmsCustomUserManager
{
//******************************************************************
// Constructor methods
public MyUserManager
()
{
}
//******************************************************************
// Instance methods
/** This method is called
after the constructor. Subclasses should
* overwrite
this method to initialize any data needed to validate the
* userName
and password. This method should return true if the initialization
* was successful,
otherwise return false. If this method returns false,
* the login
will be considered invalid and RTView will exit.
* <P>
*/
public boolean activate
()
{
return true;
}
//******************************************************************
// Get substitutions
method
/** This method should
return substitutions to set on the RTView
* application
when the specified user is logged in. If this user does not
* have any
associated substitutions, this method should return null.
* Otherwise,
return a pair of Vectors. Both Vectors must be the same length,
* with the
first Vector containing the substutition strings and the second
* Vector
containing the corresponding substitution values.
* <P>
*/
public Vector[] getSubstitutions
(String userName)
{
if (userName.equals("admin")) {
Vector subStrs = new Vector();
Vector subVals = new Vector();
subStrs.addElement("sub1");
subVals.addElement("value1");
subStrs.addElement("sub2");
subVals.addElement("value2");
return new Vector[] {subStrs, subVals};
} else if (userName.equals("user2")) {
Vector subStrs = new Vector();
Vector subVals = new Vector();
subStrs.addElement("user2sub1");
subVals.addElement("user2value1");
subStrs.addElement("user2sub2");
subVals.addElement("user2value2");
return new Vector[] {subStrs, subVals};
} else
return null;
}
//******************************************************************
// methods called from
the login dialog
/** This method is called
from the login dialog to validate the userName
* and password.
Subclasses should overwrite this method to return true
* if the
userName and password are valid, otherwise return false.
* If there
are no roles defined for the specified user, the login will
* fail,
even if this method returns true.
* <P>
*/
public boolean validateLogin
(String userName, String password)
{
if (userName ==
null || password == null)
return false;
if (!userName.equals("admin")
&& !userName.equals("user1") &&
!userName.equals("user2")
&& !userName.equals("user3"))
return false;
if (!userName.equals(password))
return false;
return true;
}
/** This method is called
if the user presses Reset in the login
* dialog.
The Reset button clears the fields so the user can set
* a new
user name and password. If subclasses stored the userName
* or password
from validateLogin() or the status of whether they
* were valid
these values should be cleared.
* <P>
*/
public void invalidateLogin
()
{
}
/** This method must
return true if the specified user has multiple role,
* otherwise
false.
* <P>
*/
public boolean userHasMultipleRoles
(String userName)
{
if (userName ==
null)
return false;
if (userName.equals("user2")
|| userName.equals("user3"))
return true;
return false;
}
/** This method must
return a Vector containing the role names for the
* specified
user. Each user is required to have at least one role.
* <P>
*/
public Vector getRoleNamesForUser
(String userName)
{
if (userName == null)
return null;
Vector v = new Vector();
if (userName.equals("admin")) {
v.addElement("admin");
return v;
}
if (userName.equals("user1")) {
v.addElement("role1");
return v;
}
if (userName.equals("user2")) {
v.addElement("role2");
v.addElement("role3");
return v;
}
if (userName.equals("user3")) {
v.addElement("role2");
v.addElement("role3");
v.addElement("role4");
return v;
}
return null;
}
//******************************************************************
// methods called for
pass client credentials
/** This method must
return the password for the specified user, or null if
* if the
user is not recognized. This method is called for the sql and olap
* data sources
to use if databases are defined that have Use Client
* Credentials
selected. If the Use Client Credentials feature is not used in
* your application,
this method can return null for all users.
*/
public String getPassword
(String userName)
{
return null;
}
}
|