*/
public IPerson getPerson(HttpServletRequest request)
throws PortalSecurityException {
// Return the person object if it exists in the user's session
final HttpSession session = request.getSession(false);
IPerson person = null;
if (session != null) {
person = (IPerson) session.getAttribute(PERSON_SESSION_KEY);
if (person != null) {
return person;
}
}
try {
// Create a new instance of a person
person = PersonFactory.createGuestPerson();
// If the user has authenticated with the server which has implemented web authentication,
// the REMOTE_USER environment variable will be set.
String remoteUser = request.getRemoteUser();
// We don't want to ignore the security contexts which are already configured in security.properties, so we
// retrieve the existing security contexts. If one of the existing security contexts is a RemoteUserSecurityContext,
// we set the REMOTE_USER field of the existing RemoteUserSecurityContext context.
//
// If a RemoteUserSecurityContext does not already exist, we create one and populate the REMOTE_USER field.
ISecurityContext context = null;
Enumeration subContexts = null;
boolean remoteUserSecurityContextExists = false;
// Retrieve existing security contexts.
context = person.getSecurityContext( );
if ( context != null )
subContexts = context.getSubContexts( );
if ( subContexts != null ) {
while ( subContexts.hasMoreElements( ) ) {
ISecurityContext ctx = (ISecurityContext)subContexts.nextElement( );
// Check to see if a RemoteUserSecurityContext already exists, and set the REMOTE_USER
if ( ctx instanceof RemoteUserSecurityContext ) {
RemoteUserSecurityContext remoteuserctx = (RemoteUserSecurityContext)ctx;
remoteuserctx.setRemoteUser( remoteUser );
remoteUserSecurityContextExists = true;
}
}
}
// If a RemoteUserSecurityContext doesn't alreay exist, create one.
// This preserves the default behavior of this class.
if ( ! remoteUserSecurityContextExists ) {
RemoteUserSecurityContext remoteuserctx = new RemoteUserSecurityContext(remoteUser);
person.setSecurityContext(remoteuserctx);
}
}
catch (Exception e) {
// Log the exception
log.error("Exception creating person for request " + request, e);