Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Removement of PhaseListener
Removement of PhaseListener [message #1823273] Tue, 24 March 2020 07:54 Go to next message
Michael Grossmann is currently offline Michael GrossmannFriend
Messages: 3
Registered: January 2013
Junior Member
Hi,

i plan to migrate from RAP 2.3 to RAP 3. I read that PhaseListener was removed. I use the PhaseListener in RAP 2.3 to bring the security context from http session to ui thread. I have a servlet filter that sets the security context created with help of the http header to the http session as an session attribute. Then in phase listener i bring the security context to the ui thread. The security context holder used in the example uses a thread local to set a security context for the current thread.
Is there any other way to do this? I use rwt standalone without any OSGI and so on.
Here is my example code:

package my.customer.package.starter.webapp.rwt;

import my.customer.package.ITokenPrincipal;
import javax.servlet.http.HttpSession;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.lifecycle.PhaseEvent;
import org.eclipse.rap.rwt.lifecycle.PhaseId;
import org.eclipse.rap.rwt.lifecycle.PhaseListener;
import org.jowidgets.security.api.SecurityContextHolder;

final class RwtSecurityPhaseListener implements PhaseListener {

@Override
public void beforePhase(final PhaseEvent event) {

final HttpSession httpSession = RWT.getUISession().getHttpSession();

final ITokenPrincipal principal = (ITokenPrincipal) httpSession.getAttribute(RwtTokenAuthenticationFilter.PRINCIPAL_KEY);

if (principal != null) {
//sets the security context of the http session to the ui thread for this session
SecurityContextHolder.setSecurityContext(principal);
}

}

@Override
public void afterPhase(final PhaseEvent event) {
//clears the security context for the ui thread
SecurityContextHolder.clearSecurityContext();
}

@Override
public PhaseId getPhaseId() {
return PhaseId.ANY;
}
}

[Updated on: Tue, 24 March 2020 07:56]

Report message to a moderator

Re: Removement of PhaseListener [message #1824360 is a reply to message #1823273] Tue, 14 April 2020 10:13 Go to previous message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2429
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,

you could try to use still internal MessageFilter attached to ApplicationContextImpl in your application configuration.

private void addMessageFilter( Application application ) {
ApplicationContextImpl applicationContext = ( ( ApplicationImpl )application ).getApplicationContext();
applicationContext.addMessageFilter( new MessageFilter() {
@Override
public ResponseMessage handleMessage( RequestMessage request, MessageFilterChain chain ) {
System.out.println( "-------------------------------" );
// code to run before message processing
ResponseMessage response = chain.handleMessage( request );
// code to run after message processing
return response;
}
} );
}

HTH,
Ivan

[1] https://github.com/eclipse/rap/blob/master/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/remote/MessageFilter.java
Previous Topic:Browser context menu way off from mouse position
Next Topic:rap GC
Goto Forum:
  


Current Time: Thu Dec 26 10:20:54 GMT 2024

Powered by FUDForum. Page generated in 0.03265 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top