// 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;