Monday, May 19, 2014

Re: extend UiBinder engine

Yeah thanks, I was too tired yesterday (after midnight), I didn't realize I don't need to use initializer but rather add my code so that I can dynamically decide whether I want the field to be created or not. I have my answer thanks. I just thought more poeple had to deal with this authorization issue and someone surely tried to solve it centrally. Obviously it's not that common. When I'll have some time for fun I'll do yet another open source for this purpose :)

As already said, it is far better do solve that problem without "hacking" GWT. In fact UiBinder is pretty strict and not really designed to be extendable because GWT does not want to stick itself to an API that is maybe not fully thought out. Thats why I said you probably have to replace the whole UiBinderGenerator class.

Personally I would use the setVisible() approach and generate code that handles that centrally for a given view, e.g. you could do:

@RequiresRole("superAdmin")
@UiField
CheckBox makeAdmin 

Then you generate a class MyView_Security next to your MyView UiBinder java file. That MyView_Security would have a method like

void secureView(MyView view, UserRolesRegistry userRoles) {
  if(! userRoles.hasRole("superAdmin") {
     view.makeAdmin.setVisible(false);
     // additional UiFields that require superAdmin role.
  }
}

Then MyView can call that method to "secure" itself based on user roles. That way you only need to add annotations to your @UiFields and the code needed will be generated either by a GWT generator or by using Java annotation processing.

-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment