Hello, Nice and very well programmed plugin! I'm using it with vaddin 7

Hello,

Nice and very well programmed plugin!

I’m using it with vaddin 7.6+ but since yesterday I’m having a problem with some code that used to work. I’m getting:

java.lang.IllegalStateException: Authorization.bindComponent() or Authorization.bindComponents() has been called without calling to() on the returned Restrict-object
	at org.ilay.Check.noUnclosedRestrict(Check.java:76)
	at org.ilay.RestrictImpl.<init>(RestrictImpl.java:37)
	at org.ilay.ComponentRestrict.<init>(ComponentRestrict.java:20)
	at org.ilay.Authorization.restrictComponent(Authorization.java:119)
	at com.vaadin.demo.dashboard.view.keys.EmKeysView.buildKeysVL(EmKeysView.java:872)
	at com.vaadin.demo.dashboard.view.keys.EmKeysView.<init>(EmKeysView.java:130)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at com.vaadin.navigator.Navigator$ClassBasedViewProvider.getView(Navigator.java:341)

any ideas? I cannot remember changing anything :(

Hi Dimitris, I have not looked at the v7 code for a long time and I’m pretty busy at the moment. Could you debug into this maybe? If you find what broke it and come up with a patch for it ( assuming the bug is on ilay side ), I will review and probably pull. Ilay for V7 is kinda unmaintained, as Vaadin 7 is rarely used anymore these days.

Hello,

Thanks for replying.

It seems that this line

final Optional<CurrentRestrict> currentRestrictOptional = VaadinAbstraction.getFromSessionStore(CurrentRestrict.class);

returns something that should be empty for avoiding the exception. Does this mean that the view authorization is leftover in the session?

Regards,

Jim

what is the object in the currentRestrictOptional? Have you called bind() on this object?

Hello Bernd,

I am initializing the view providers and I’m Authorizing a view:

private void initViewProviders() {
		// A dedicated view provider is added for each separate view type
		for (final DashboardViewType viewType : DashboardViewType.values()) {
			ViewProvider viewProvider = new ClassBasedViewProvider(viewType.getViewName(), viewType.getViewClass()) {

				// This field caches an already initialized view instance if the
				// view should be cached (stateful views).
				private View cachedInstance;

				@Override
				public View getView(final String viewName) {
					View result = null;
					if (viewType.getViewName().equals(viewName)) {
						if (viewType.isStateful()) {
							// Stateful views get lazily instantiated
							if (cachedInstance == null) {
								cachedInstance = super.getView(viewType.getViewName());
							}
							result = cachedInstance;
						} else {
							// Non-stateful views get instantiated every time
							// they're navigated to
							result = super.getView(viewType.getViewName());
						}
						/* authorize the views, also look at DashboardMenu.java */
						if (viewType.equals(DashboardViewType.EMKEYS) || viewType.equals(DashboardViewType.PERSONS)
								|| viewType.equals(DashboardViewType.VISITS)) {
							Authorization.restrictView(result).to(AccessControl.USERGROUP_ADMIN);
						}
					}
					return result;
				}
			};

			if (viewType == ERROR_VIEW) {
				errorViewProvider = viewProvider;
			}

			addProvider(viewProvider);
		}

		setErrorProvider(new ViewProvider() {
			@Override
			public String getViewName(final String viewAndParameters) {
				return ERROR_VIEW.getViewName();
			}

			@Override
			public View getView(final String viewName) {
				return errorViewProvider.getView(ERROR_VIEW.getViewName());
			}
		});
	}

the line that causes the trouble is:

Authorization.restrictView(result).to(AccessControl.USERGROUP_ADMIN);

the stacktrace you posted in the first post had restrictComponent in it, but this last code says restrictView

This is true.

Earlier in the code, when the menu is built I restrict (authorize) the button that opens the view. But the exception occurs when the code that Authorizes the view runs.