Principal p = null;
if ( info.getAction() == ACTION_SET ) {
SerializablePrincipal sp = (SerializablePrincipal)info.getValue();
- p = sp.getPrincipal(session.getManager().getContainer().getRealm());
+ p = sp.getPrincipal();
}
session.setPrincipal(p,false);
break;
boolean hasPrincipal = stream.readBoolean();
principal = null;
if (hasPrincipal) {
- principal = SerializablePrincipal.readPrincipal(stream,getManager().getContainer().getRealm());
+ principal = SerializablePrincipal.readPrincipal(stream);
}
// setId((String) stream.readObject());
* Construct a new Principal, associated with the specified Realm, for the
* specified username and password.
*
- * @param realm The Realm that owns this Principal
* @param name The username of the user represented by this Principal
* @param password Credentials used to authenticate this user
*/
- public SerializablePrincipal(Realm realm, String name, String password) {
+ public SerializablePrincipal(String name, String password) {
- this(realm, name, password, null);
+ this(name, password, null);
}
* specified username and password, with the specified role names
* (as Strings).
*
- * @param realm The Realm that owns this principal
* @param name The username of the user represented by this Principal
* @param password Credentials used to authenticate this user
* @param roles List of roles (must be Strings) possessed by this user
*/
- public SerializablePrincipal(Realm realm, String name, String password,
+ public SerializablePrincipal(String name, String password,
List<String> roles) {
- this(realm, name, password, roles, null);
+ this(name, password, roles, null);
}
* specified username and password, with the specified role names
* (as Strings).
*
- * @param realm The Realm that owns this principal
* @param name The username of the user represented by this Principal
* @param password Credentials used to authenticate this user
* @param roles List of roles (must be Strings) possessed by this user
* @param userPrincipal The user principal to be exposed to applications
*/
- public SerializablePrincipal(Realm realm, String name, String password,
+ public SerializablePrincipal(String name, String password,
List<String> roles, Principal userPrincipal) {
super();
- this.realm = realm;
this.name = name;
this.password = password;
if (roles != null) {
public static SerializablePrincipal createPrincipal(GenericPrincipal principal)
{
if ( principal==null) return null;
- return new SerializablePrincipal(principal.getRealm(),
- principal.getName(),
+ return new SerializablePrincipal(principal.getName(),
principal.getPassword(),
principal.getRoles()!=null?Arrays.asList(principal.getRoles()):null,
principal.getUserPrincipal()!=principal?principal.getUserPrincipal():null);
}
- public GenericPrincipal getPrincipal( Realm realm )
+ public GenericPrincipal getPrincipal()
{
- return new GenericPrincipal(realm, name, password,
+ return new GenericPrincipal(name, password,
getRoles()!=null?Arrays.asList(getRoles()):null,
userPrincipal);
}
- public static GenericPrincipal readPrincipal(ObjectInput in, Realm realm)
+ public static GenericPrincipal readPrincipal(ObjectInput in)
throws IOException, ClassNotFoundException {
String name = in.readUTF();
boolean hasPwd = in.readBoolean();
throw e;
}
}
- return new GenericPrincipal(realm,name,pwd,Arrays.asList(roles),
+ return new GenericPrincipal(name,pwd,Arrays.asList(roles),
userPrincipal);
}
p = (SerializablePrincipal)session_in.readObject();
((ReplicatedSession)session).readObjectData(session_in);
if ( hasPrincipal )
- session.setPrincipal(p.getPrincipal(getContainer().getRealm()));
+ session.setPrincipal(p.getPrincipal());
((ReplicatedSession)session).setId(sessionId,isNew);
ReplicatedSession rsession = (ReplicatedSession)session;
rsession.setAccessCount(1);
ArrayList<String> list = getRoles(dbConnection, username);
// Create and return a suitable Principal for this user
- return (new GenericPrincipal(this, username, credentials, list));
+ return (new GenericPrincipal(username, credentials, list));
}
protected Principal getPrincipal(String username) {
Connection dbConnection = open();
if (dbConnection == null) {
- return new GenericPrincipal(this,username, null, null);
+ return new GenericPrincipal(username, null, null);
}
try {
- return (new GenericPrincipal(this,
- username,
+ return (new GenericPrincipal(username,
getPassword(dbConnection, username),
getRoles(dbConnection, username)));
} finally {
import javax.security.auth.login.LoginContext;
-import org.apache.catalina.Realm;
-
/**
* Generic implementation of <strong>java.security.Principal</strong> that
* Construct a new Principal, associated with the specified Realm, for the
* specified username and password.
*
- * @param realm The Realm that owns this Principal
* @param name The username of the user represented by this Principal
* @param password Credentials used to authenticate this user
*/
- public GenericPrincipal(Realm realm, String name, String password) {
+ public GenericPrincipal(String name, String password) {
- this(realm, name, password, null);
+ this(name, password, null);
}
* specified username and password, with the specified role names
* (as Strings).
*
- * @param realm The Realm that owns this principal
* @param name The username of the user represented by this Principal
* @param password Credentials used to authenticate this user
* @param roles List of roles (must be Strings) possessed by this user
*/
- public GenericPrincipal(Realm realm, String name, String password,
- List<String> roles) {
- this(realm, name, password, roles, null);
+ public GenericPrincipal(String name, String password, List<String> roles) {
+ this(name, password, roles, null);
}
/**
* specified username and password, with the specified role names
* (as Strings).
*
- * @param realm The Realm that owns this principal
* @param name The username of the user represented by this Principal
* @param password Credentials used to authenticate this user
* @param roles List of roles (must be Strings) possessed by this user
* @param userPrincipal - the principal to be returned from the request
* getUserPrincipal call if not null; if null, this will be returned
*/
- public GenericPrincipal(Realm realm, String name, String password,
- List<String> roles, Principal userPrincipal) {
- this(realm, name, password, roles, userPrincipal, null);
+ public GenericPrincipal(String name, String password, List<String> roles,
+ Principal userPrincipal) {
+ this(name, password, roles, userPrincipal, null);
}
/**
* specified username and password, with the specified role names
* (as Strings).
*
- * @param realm The Realm that owns this principal
* @param name The username of the user represented by this Principal
* @param password Credentials used to authenticate this user
* @param roles List of roles (must be Strings) possessed by this user
* @param loginContext - If provided, this will be used to log out the user
* at the appropriate time
*/
- public GenericPrincipal(Realm realm, String name, String password,
- List<String> roles, Principal userPrincipal,
- LoginContext loginContext) {
+ public GenericPrincipal(String name, String password, List<String> roles,
+ Principal userPrincipal, LoginContext loginContext) {
super();
- this.realm = realm;
this.name = name;
this.password = password;
this.userPrincipal = userPrincipal;
/**
- * The Realm with which this Principal is associated.
- */
- protected Realm realm = null;
-
- public Realm getRealm() {
- return (this.realm);
- }
-
- void setRealm( Realm realm ) {
- this.realm=realm;
- }
-
-
- /**
* The set of roles associated with this user.
*/
protected String roles[] = new String[0];
}
// Return the resulting Principal for our authenticated user
- return new GenericPrincipal(this, username, null, roles, userPrincipal,
+ return new GenericPrincipal(username, null, roles, userPrincipal,
loginContext);
}
ArrayList<String> roles = getRoles(username);
// Create and return a suitable Principal for this user
- return (new GenericPrincipal(this, username, credentials, roles));
+ return (new GenericPrincipal(username, credentials, roles));
}
*/
protected synchronized Principal getPrincipal(String username) {
- return (new GenericPrincipal(this,
- username,
+ return (new GenericPrincipal(username,
getPassword(username),
getRoles(username)));
containerLog.debug("Found role: " + it.next());
}
}
- return (new GenericPrincipal(this,
- username,
+ return (new GenericPrincipal(username,
credentials,
roles));
}
}
// Create and return a suitable Principal for this user
- return (new GenericPrincipal(this, username, credentials, roles));
+ return (new GenericPrincipal(username, credentials, roles));
}
}
User user = getUser(context, username);
- return new GenericPrincipal(this, user.username, user.password ,
+ return new GenericPrincipal(user.username, user.password ,
getRoles(context, user));
}
// Construct and cache the Principal for this user
GenericPrincipal principal =
- new GenericPrincipal(this, username, password, list);
+ new GenericPrincipal(username, password, list);
principals.put(username, principal);
}
return (false);
GenericPrincipal gp = (GenericPrincipal) principal;
- if (!(gp.getRealm() == this)) {
- if(log.isDebugEnabled())
- log.debug("Different realm " + this + " " + gp.getRealm());// return (false);
- }
boolean result = gp.hasRole(role);
if (log.isDebugEnabled()) {
String name = principal.getName();
roles.add(role.getName());
}
}
- return new GenericPrincipal(this, username, user.getPassword(), roles, user);
+ return new GenericPrincipal(username, user.getPassword(), roles, user);
}
if (p == null) {
String pass = userPass.get(username);
if (pass != null) {
- p = new GenericPrincipal(this, username, pass,
+ p = new GenericPrincipal(username, pass,
userRoles.get(username));
userPrincipals.put(username, p);
}
roles.add("RoleB");
TesterPrincipal tpOriginal = new TesterPrincipal("inner");
GenericPrincipal gpOriginal =
- new GenericPrincipal(null, "usr", "pwd", roles, tpOriginal);
+ new GenericPrincipal("usr", "pwd", roles, tpOriginal);
// Do the serialization
try {
try {
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
- gpNew = SerializablePrincipal.readPrincipal(ois, null);
+ gpNew = SerializablePrincipal.readPrincipal(ois);
} catch (FileNotFoundException e) {
e.printStackTrace();
fail("fnfe reading object output stream");