Wicket 7 Security and JBoss Keycloak
Hi All I am looking at how to integrate JBoss Keycloak with wicket 7. I am not quite sure where to start the configuration the example given is where the jsp pages are secured by configuration in the web.xml file. Wicket is a little different in that you need to create a Authorization Strategy. I am not sure how to secure the pages I want to. Has anybody tried integrating wicket with keycloak before or even picketlink. Thanks David
Re: open connection to async servlet and initiate wicket ajax request, results ComponentNotFoundException
MessagePanelPolling function is called through a wicket page, the wicket page has an active ajax call to the async servlet, public BasePage(PageParameters pageParameters) { super(pageParameters); add(new MessageCheckBehaviour()); } static class MessageCheckBehaviour extends MyJqueryBehaviour{ @Override public void renderHead(Component component, IHeaderResponse response) { super.renderHead(component, response); //response.render(OnLoadHeaderItem.forScript("MessagePanel.longPoll('"+UserContextHolder.getUser().getInfUser().getSysUserId().toString()+"')")); response.render(JavaScriptHeaderItem.forReference(JS_FILE)); } static final PackageResourceReference JS_FILE= new JavaScriptResourceReference(MyJqueryBehaviour.class, "messagePolling.js"); } Async servlet waits on a blocking queue , a new item in queue causes thread to checks all registered AsyncContext's and if match found, write to the aynscontext response. public class MessageNotificationServlet extends HttpServlet { static Logger logger= Logger.getLogger(MessageNotificationServlet.class); private Queue asyncContexts = new ConcurrentLinkedQueue(); static BlockingQueue messages = new LinkedBlockingQueue(); ExecutorService executorService; public static void addMessage(String msg){ try{ messages.add(msg); }catch(Exception e){ throw new RuntimeException(e); } } @Override public void init(ServletConfig config) throws ServletException { super.init(config); executorService=Executors.newSingleThreadExecutor(); executorService.submit(new Runnable() { @Override public void run() { while(true){ try{ String message = messages.take(); for(AsyncContext asyncContext :asyncContexts ){ try{ if(asyncContext.getRequest().getParameter("name").trim().equals(message)){ String paramName=asyncContext.getRequest().getParameter("name").trim(); String timestamp=asyncContext.getRequest().getParameter("timestamp").trim(); try{ PrintWriter printWriter=asyncContext.getResponse().getWriter(); printWriter.println("new_message"); printWriter.flush(); asyncContext.complete(); }catch(Exception e){ logger.debug(" failed writing to async "+paramName +" "+timestamp ); logger.error((" async failed "+paramName +" "+timestamp),e); } } }catch (Exception e) { asyncContexts.remove(asyncContext); logger.debug(" error with asyncontext ",e); } } }catch(Exception e){ logger.debug(" error in msg check thread ",e); } } } }); } @Override public void destroy() { super.destroy(); messages.clear(); asyncContexts.clear(); executorService.shutdownNow(); } @Override protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IO
Re: open connection to async servlet and initiate wicket ajax request, results ComponentNotFoundException
This code doesn't use Wicket.Ajax JavaScript APIs so the Ajax Channels are not involved at all. Please show us the Java code of the servlet. How does it use the page ? Martin Grigorov Wicket Training and Consulting https://twitter.com/mtgrigorov On Thu, Apr 21, 2016 at 10:38 PM, fachhoch wrote: > This is the javascript file rendered by wicket page, this opens a > connection to the async servlet, page has several ajax links, clicking on > ajaxlinks updates dom, and sometimes wicket throws > ComponentNotFoundException. > Initially tried calling MessagePanel.longPoll(data) from wicket page with > OnDomReadyHeaderItem, no success, then try selfinvoking function assuming > will work but the same exception. > > > (function MessagePanelPolling (){ > $.ajax({ > url: "/myapp/app/user/userId", > success: function(data){ > if(data){ > MessagePanel.longPoll(data); > } > }, > type: "GET", > data: {timestamp: new Date().getTime()} > }); > })(); > > var MessagePanel ={ > cancelPolling:null, > newMsg:function(){ > var markup=' You have a new message ' > var my_dialog =$(markup).dialog({ > position:'right top' > ,title:'New Message' > }); > my_dialog.dialog('widget').zIndex(25000); > } > ,longPoll:function(channel){ > $.ajax({ > url: "/myapp/cometmsg", > success: function(data){ > if(data){ > > if('new_message'===data.trim()){ > > MessagePanel.newMsg(); > } > } > }, > error: function(err) { > MessagePanel.cancelPolling='true'; > console.log(" long poll error > "+err); > }, > type: "GET", > data: {name:channel,timestamp: new > Date().getTime()} > ,complete:function(){ > > if(MessagePanel.cancelPolling!='true'){ > > MessagePanel.longPoll(channel) > } > } > }); > } > } > > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674359.html > Sent from the Users forum mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
Re: open connection to async servlet and initiate wicket ajax request, results ComponentNotFoundException
This is the javascript file rendered by wicket page, this opens a connection to the async servlet, page has several ajax links, clicking on ajaxlinks updates dom, and sometimes wicket throws ComponentNotFoundException. Initially tried calling MessagePanel.longPoll(data) from wicket page with OnDomReadyHeaderItem, no success, then try selfinvoking function assuming will work but the same exception. (function MessagePanelPolling (){ $.ajax({ url: "/myapp/app/user/userId", success: function(data){ if(data){ MessagePanel.longPoll(data); } }, type: "GET", data: {timestamp: new Date().getTime()} }); })(); var MessagePanel ={ cancelPolling:null, newMsg:function(){ var markup=' You have a new message ' var my_dialog =$(markup).dialog({ position:'right top' ,title:'New Message' }); my_dialog.dialog('widget').zIndex(25000); } ,longPoll:function(channel){ $.ajax({ url: "/myapp/cometmsg", success: function(data){ if(data){ if('new_message'===data.trim()){ MessagePanel.newMsg(); } } }, error: function(err) { MessagePanel.cancelPolling='true'; console.log(" long poll error "+err); }, type: "GET", data: {name:channel,timestamp: new Date().getTime()} ,complete:function(){ if(MessagePanel.cancelPolling!='true'){ MessagePanel.longPoll(channel) } } }); } } -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674359.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: open connection to async servlet and initiate wicket ajax request, results ComponentNotFoundException
Hi, Show us some code please. It is not very clear what you are doing. Martin Grigorov Wicket Training and Consulting https://twitter.com/mtgrigorov On Thu, Apr 21, 2016 at 10:07 PM, fachhoch wrote: > I am trying to add server push using javascript longpolling and async > servlet, > a self invoking javascript function makes ajax request to this async > servlet , there by keeping the connection open, when this connection is > open and a wicket ajax request is initiated, its sometimes failing with > ComponentNotFoundException? > I assume this is due to wicket ajax channels, how to keep an ajax > connection > open and also run other wicket ajax requests concurrently ? > > > > > > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357.html > Sent from the Users forum mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
open connection to async servlet and initiate wicket ajax request, results ComponentNotFoundException
I am trying to add server push using javascript longpolling and async servlet, a self invoking javascript function makes ajax request to this async servlet , there by keeping the connection open, when this connection is open and a wicket ajax request is initiated, its sometimes failing with ComponentNotFoundException? I assume this is due to wicket ajax channels, how to keep an ajax connection open and also run other wicket ajax requests concurrently ? -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: HTTP ERROR:500
Hey Martin, actually I’m not running in Prod mode, but development. The behavior for the output is different between 7.1 and 7.2 (which is the error message I sent). In 7.1, I don’t see an error message on the page at all, but only in the console. I definitely saw the exception, I guess it wasn’t clear to me what I had done wrong…where a lot of other Wicket errors suggest what the problem might be. -Lon On Wed, Apr 20, 2016 at 11:16 PM, Martin Grigorov wrote: > Hi Lon, > > Welcome to Wicket! > > It seems you run your application in Production mode and that's why it > shows this almost empty page. In Production it is recommended to not show > detailed information about your application problems to your audience. > If you change the configuration type to Development then the exception with > its stacktrace is being shown also in the browser. > I say "also" because in both cases the exception is logged in the server > logs too. Always consult with the server logs because there might be some > hints when you do something that is not optimal! ;-) > > Have fun and let us know if you face any issues! > > Martin Grigorov > Wicket Training and Consulting > https://twitter.com/mtgrigorov > > On Thu, Apr 21, 2016 at 3:22 AM, Lon Varscsak > wrote: > > > Hey all, I’m new to wicket and I got this horrendous error earlier today: > > > > > > I had NO idea what it meant. :P I was able to debug it and see what was > > left in queue, and that reminded me that I hadn’t finished the html for a > > new component I had added in the constructor. My question is, isn’t > there > > a better way to explain to the developer what’s going on? It would be > > super helpful to newbs like me. ;D > > > > Just a thought. > > > > Thanks, > > > > Lon > > >
Re: Adding multiple WebSocketBehavior instances to the same page
Hi, Could you please try this code: public abstract class MyWebSocketBehavior extends WebSocketBehavior { private final static MetaDataKey IS_ALREADY_INSTALLED = new MetaDataKey() {}; @Override public void renderHead(Component component, IHeaderResponse response) { Page page = component.getPage(); if (page.getMetaData(IS_ALREADY_INSTALLED) == null) { super.renderHead(component, response); page.setMetaData(IS_ALREADY_INSTALLED, Boolean.TRUE); } } } And then use MyWebSocketBehavior in your panels instead. This way only the first one will contribute the JS to setup a WebSocket connection but all of them will receive messages. Martin Grigorov Wicket Training and Consulting https://twitter.com/mtgrigorov On Thu, Apr 21, 2016 at 9:12 AM, Martin Grigorov wrote: > > On Thu, Apr 21, 2016 at 8:41 AM, Francesco Chicchiriccò < > ilgro...@apache.org> wrote: > >> On 20/04/2016 17:58, Martin Grigorov wrote: >> >>> Hi, >>> >>> There is no point in having more than one WebSocket connections per page. >>> And actually, Wicket Native WebSockets do not support it out of the box. >>> The registry with the websocket connections at the server side uses a key >>> so there could be just one >>> connection >>> per page. >>> >> >> Thanks for clarifying: this means I need to refactor our code so that a >> single WebSocketBehavior is added to every page, and then moving the logic >> for distinguishing what is actually to be performed inside its onConnect() >> method. >> >> Now the next problem is how to be notified when a message comes from the >>> client, because the behavior is registered somewhere else and not in the >>> current component... >>> You could override component's #onEvent() and do something when the >>> payload >>> is TextMessage but this is not very user friendly :-/ >>> Please create a ticket for improvement! >>> >> >> Sorry, it is not clear to me what kind of improvement can be filed: >> allowing multiple WebSocketBehaviors to a page? >> I will anyway change our logic as outlined above, since I need to have it >> working with Wicket 7.20. >> > > The problem I see is that you will have code like: > > if (getBehaviors(WebSocketBehavior.class).isEmpty()) { > add(new WebSocketBehavior() { > @Override protected void onTextMessage(...) {...} > }); > } > > But the condition will pass for just one of the calls. > All other calls won't execute the body of the 'if' and thus > #onTextMessage() won't be called when there is a new message from the > client. To be notified when a message comes you will have to override > Component#onEvent(). > I'll think on a solution to add the WSBehavior to the component tree but > not create a client side WebSocket. I.e. it will be just a server side > publisher/subscriber. > > >> Regards. >> >> >> On Wed, Apr 20, 2016 at 9:16 AM, Francesco Chicchiriccò < >>> ilgro...@apache.org> wrote: >>> Hi Martin, thanks for your prompt reply. Are you suggesting that the best practice is to add WebSocketBehavior at most once per page - and possibly to the page itself? My current situation is that I have defined three different anonymous WebSocketBehavior instances, added to three different panels [1][2][3]: panel [1] is added to BasePage, panel [2] and [3] are added to Dashboard, extending BasePage. With this configuration, only the onConnect() method from [1] is invoked. If instead I disable [1] (via the if reported below), both [2] and [3] onConnect() methods are invoked. So my actual issue it not really how to asses when to add [1] or not, but to have [1][2][3] all added to Dashboard, and [1] to the remaining pages. Regards. [1] https://github.com/apache/syncope/blob/master/client/console/src/main/java/org/apache/syncope/client/console/widgets/ApprovalsWidget.java#L179-L189 [2] https://github.com/apache/syncope/blob/master/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobWidget.java#L119-L128 [3] https://github.com/apache/syncope/blob/master/client/console/src/main/java/org/apache/syncope/client/console/widgets/ReconciliationWidget.java#L144-L155 On 19/04/2016 18:07, Martin Grigorov wrote: Hi, > > You could use something like: > > if (getBehaviors(WebSocketBehavior.class).isEmpty()) { > add(new WebSocketBehavior() {...}); > } > > This way only one instance will be added to one page instance. > > Martin Grigorov > Wicket Training and Consulting > https://twitter.com/mtgrigorov > > On Tue, Apr 19, 2016 at 5:50 PM, Francesco Chicchiriccò < > ilgro...@apache.org> wrote: > > Hi all, >> in the upcoming Syncope 2.0 we are enjoying WebSocketBehavior for >> making >> our admin console UI more reactive. >> >> It mostly work
Re: Websocket message from Spring bean
Finally was able to test it :) Everything works as expected! Thanks a lot for the hint! On Tue, Oct 7, 2014 at 5:49 PM, Maxim Solodovnik wrote: > Thanks a lot for the tip Martin! > will give it a try and write back :) > > On 7 October 2014 16:39, Martin Grigorov wrote: > >> You use request and session scoped Spring beans in WebSocket request >> because such requests are not processed by Servlet filters and Spring has >> no chance to set its proxy objects as request/session attributes. >> >> But in Spring bean code you can do: >> Application app = Application..get("myFilterName"); >> WebSocketSettings wsSettings = WebSocketSettings.Holder.get(app); >> IWebSocketConnectionRegistry registry = >> wsSettings.getConnectionRegistry(); >> WebSocketPushBroadcaster broadcaster = new >> WebSocketPushBroadcaster(registry); >> broadcaster >> >> Martin Grigorov >> Wicket Training and Consulting >> https://twitter.com/mtgrigorov >> >> On Tue, Oct 7, 2014 at 11:31 AM, Maxim Solodovnik >> wrote: >> >> > To be fair I haven't tried :( >> > I thought I will have "no session/application bound to current thread" >> > exceptions :( >> > I'll test and let you know >> > >> > On 7 October 2014 15:21, Martin Grigorov wrote: >> > >> > > Hi, >> > > >> > > I think it should work. >> > > What kind of problems do you face ? >> > > >> > > Martin Grigorov >> > > Wicket Training and Consulting >> > > https://twitter.com/mtgrigorov >> > > >> > > On Fri, Oct 3, 2014 at 4:55 PM, Maxim Solodovnik < >> solomax...@gmail.com> >> > > wrote: >> > > >> > > > Hello All, >> > > > >> > > > I wonder is it possible to send IWebSocketPushMessage from Spring >> bean? >> > > (I >> > > > can access Spring beans from wicket pages, now I need "backward >> > > > compatibility") >> > > > >> > > > Thanks in advance for your help! >> > > > >> > > > -- >> > > > WBR >> > > > Maxim aka solomax >> > > > >> > > >> > >> > >> > >> > -- >> > WBR >> > Maxim aka solomax >> > >> > > > > -- > WBR > Maxim aka solomax > -- WBR Maxim aka solomax
Re: Adding multiple WebSocketBehavior instances to the same page
On Thu, Apr 21, 2016 at 8:41 AM, Francesco Chicchiriccò wrote: > On 20/04/2016 17:58, Martin Grigorov wrote: > >> Hi, >> >> There is no point in having more than one WebSocket connections per page. >> And actually, Wicket Native WebSockets do not support it out of the box. >> The registry with the websocket connections at the server side uses a key >> so there could be just one connection >> per page. >> > > Thanks for clarifying: this means I need to refactor our code so that a > single WebSocketBehavior is added to every page, and then moving the logic > for distinguishing what is actually to be performed inside its onConnect() > method. > > Now the next problem is how to be notified when a message comes from the >> client, because the behavior is registered somewhere else and not in the >> current component... >> You could override component's #onEvent() and do something when the >> payload >> is TextMessage but this is not very user friendly :-/ >> Please create a ticket for improvement! >> > > Sorry, it is not clear to me what kind of improvement can be filed: > allowing multiple WebSocketBehaviors to a page? > I will anyway change our logic as outlined above, since I need to have it > working with Wicket 7.20. > The problem I see is that you will have code like: if (getBehaviors(WebSocketBehavior.class).isEmpty()) { add(new WebSocketBehavior() { @Override protected void onTextMessage(...) {...} }); } But the condition will pass for just one of the calls. All other calls won't execute the body of the 'if' and thus #onTextMessage() won't be called when there is a new message from the client. To be notified when a message comes you will have to override Component#onEvent(). I'll think on a solution to add the WSBehavior to the component tree but not create a client side WebSocket. I.e. it will be just a server side publisher/subscriber. > Regards. > > > On Wed, Apr 20, 2016 at 9:16 AM, Francesco Chicchiriccò < >> ilgro...@apache.org> wrote: >> >>> Hi Martin, >>> thanks for your prompt reply. >>> >>> Are you suggesting that the best practice is to add WebSocketBehavior at >>> most once per page - and possibly to the page itself? >>> >>> My current situation is that I have defined three different anonymous >>> WebSocketBehavior instances, added to three different panels [1][2][3]: >>> panel [1] is added to BasePage, panel [2] and [3] are added to >>> Dashboard, >>> extending BasePage. >>> >>> With this configuration, only the onConnect() method from [1] is invoked. >>> >>> If instead I disable [1] (via the if reported below), both [2] and [3] >>> onConnect() methods are invoked. >>> >>> So my actual issue it not really how to asses when to add [1] or not, but >>> to have [1][2][3] all added to Dashboard, and [1] to the remaining pages. >>> >>> Regards. >>> >>> [1] >>> >>> https://github.com/apache/syncope/blob/master/client/console/src/main/java/org/apache/syncope/client/console/widgets/ApprovalsWidget.java#L179-L189 >>> [2] >>> >>> https://github.com/apache/syncope/blob/master/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobWidget.java#L119-L128 >>> [3] >>> >>> https://github.com/apache/syncope/blob/master/client/console/src/main/java/org/apache/syncope/client/console/widgets/ReconciliationWidget.java#L144-L155 >>> >>> >>> On 19/04/2016 18:07, Martin Grigorov wrote: >>> >>> Hi, You could use something like: if (getBehaviors(WebSocketBehavior.class).isEmpty()) { add(new WebSocketBehavior() {...}); } This way only one instance will be added to one page instance. Martin Grigorov Wicket Training and Consulting https://twitter.com/mtgrigorov On Tue, Apr 19, 2016 at 5:50 PM, Francesco Chicchiriccò < ilgro...@apache.org> wrote: Hi all, > in the upcoming Syncope 2.0 we are enjoying WebSocketBehavior for > making > our admin console UI more reactive. > > It mostly works - thanks for this! - but we are experiencing some > troubles > lately. > > There is a class BasePage which is extended by all other pages, and > contains a panel which adds WebSocketBehavior. > One of such pages (Dashboard) also contains two panels, each of which > adds > in turn WebSocketBehavior. > > I observe that when the first WebSocketBehavior (in BasePage) is added, > the other two WebSocketBehavior instances' onConnect() method is not > invoked at all. > > If instead, I do something like as following, in BasePage: > > if (!(pageRef.getPage() instanceof Dashboard)) { > add(new WebSocketBehavior() {...}); > } > > everything works as expected (naturally BasePages's WebSocketBehavior > does > not come into play): both on Dashboard and other pages. > > Any hint? > TIA > > Regards. > > -- > Francesco Chicchiriccò > > Tirasa - Open Source Excellence > http://www.tirasa.net