List of usage examples for com.vaadin.server Page getUriFragment
public String getUriFragment()
From source file:com.hack23.cia.web.impl.ui.application.web.listener.AuthorizationFailureEventListener.java
License:Apache License
@Override public void onApplicationEvent(final AuthorizationFailureEvent authorizationFailureEvent) { final String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId(); final CreateApplicationEventRequest serviceRequest = new CreateApplicationEventRequest(); serviceRequest.setSessionId(sessionId); serviceRequest.setEventGroup(ApplicationEventGroup.APPLICATION); serviceRequest.setApplicationOperation(ApplicationOperationType.AUTHORIZATION); serviceRequest.setUserId(UserContextUtil.getUserIdFromSecurityContext()); final Page currentPageIfAny = Page.getCurrent(); final String requestUrl = UserContextUtil.getRequestUrl(currentPageIfAny); final UI currentUiIfAny = UI.getCurrent(); String methodInfo = ""; if (currentPageIfAny != null && currentUiIfAny != null && currentUiIfAny.getNavigator() != null && currentUiIfAny.getNavigator().getCurrentView() != null) { serviceRequest.setPage(currentUiIfAny.getNavigator().getCurrentView().getClass().getSimpleName()); serviceRequest.setPageMode(currentPageIfAny.getUriFragment()); }//from w ww .java 2s. c o m if (authorizationFailureEvent.getSource() instanceof ReflectiveMethodInvocation) { final ReflectiveMethodInvocation methodInvocation = (ReflectiveMethodInvocation) authorizationFailureEvent .getSource(); if (methodInvocation.getMethod() != null && methodInvocation.getThis() != null) { methodInfo = methodInvocation.getThis().getClass().getSimpleName() + "." + methodInvocation.getMethod().getName(); } } serviceRequest.setErrorMessage("Url:" + requestUrl + " , Method" + methodInfo + " ," + AUTHORITIES + authorizationFailureEvent.getAuthentication().getAuthorities() + REQUIRED_AUTHORITIES + authorizationFailureEvent.getConfigAttributes() + " source:" + authorizationFailureEvent.getSource()); serviceRequest.setApplicationMessage(ACCESS_DENIED); applicationManager.service(serviceRequest); LOGGER.info(LOG_MSG_AUTHORIZATION_FAILURE_SESSION_ID_AUTHORITIES_REQUIRED_AUTHORITIES, requestUrl, methodInfo, sessionId, authorizationFailureEvent.getAuthentication().getAuthorities().toString(), authorizationFailureEvent.getConfigAttributes().toString()); }
From source file:info.magnolia.ui.vaadin.magnoliashell.MagnoliaShell.java
License:Open Source License
public String getUriFragment() { Page current = Page.getCurrent(); if (current != null) { return current.getUriFragment(); }// w w w .j av a2 s.co m return null; }
From source file:org.jdal.vaadin.VaadinUtils.java
License:Apache License
/** * Exit application/* w w w . java 2s. com*/ */ public static void exit() { UI.getCurrent().close(); VaadinSession.getCurrent().close(); Page page = Page.getCurrent(); String location = StringUtils.substringBeforeLast(page.getLocation().toString(), page.getUriFragment()); location = StringUtils.substringAfterLast(location, "#"); page.setLocation(location); }
From source file:uk.q3c.krail.core.navigate.DefaultNavigator.java
License:Apache License
/** * Navigates to a the location represented by {@code navigationState}. If the {@link Sitemap} holds a redirect for * the URI represented by {@code navigationState}, navigation will be directed to the redirect target. An * unrecognised URI will throw a {@link SitemapException}. If the view for the URI is found, the user's * authorisation is checked. If the user is not authorised, a {@link AuthorizationException} is thrown. This would * be caught by the the implementation bound to {@link UnauthorizedExceptionHandler}. If the user is authorised, * the/*from w ww . j a va 2 s . c om*/ * View is instantiated, and made the current view in the UI via {@link ScopedUI#changeView(KrailView)}.<br> * <br> * Messages are published to the {{@link #eventBus}} before and after the view change. Message handlers have the * option to block the view change by returning false (see {@link #publishBeforeViewChange(BeforeViewChangeBusMessage)} * <p> * * @param navigationState * The navigationState to navigate to. May not be null. */ @Override public void navigateTo(NavigationState navigationState) { checkNotNull(navigationState); //computer says no if (!viewChangeRule.changeIsAllowed(this, currentView)) { return; } //makes sure the navigation state is up to date, removes the need to do this externally uriHandler.updateFragment(navigationState); redirectIfNeeded(navigationState); // stop unnecessary changes, but also to prevent navigation aware // components from causing a loop by responding to a change of URI (they should suppress events when they do, // but may not) if (navigationState == currentNavigationState) { log.debug("fragment unchanged, no navigation required"); return; } // https://sites.google.com/site/q3cjava/sitemap#emptyURI if (navigationState.getVirtualPage().isEmpty()) { navigationState.setVirtualPage(userSitemap.standardPageURI(StandardPageKey.Public_Home)); uriHandler.updateFragment(navigationState); } log.debug("obtaining view for '{}'", navigationState.getVirtualPage()); UserSitemapNode node = userSitemap.nodeFor(navigationState); if (node == null) { InvalidURIException exception = new InvalidURIException("URI not found"); exception.setTargetURI(navigationState.getVirtualPage()); throw exception; } Subject subject = subjectProvider.get(); boolean authorised = pageAccessController.isAuthorised(subject, node); if (authorised) { // need this in case the change is blocked by a listener NavigationState previousPreviousNavigationState = previousNavigationState; previousNavigationState = currentNavigationState; currentNavigationState = navigationState; BeforeViewChangeBusMessage beforeMessage = new BeforeViewChangeBusMessage(previousNavigationState, navigationState); // if change is blocked revert to previous state if (!publishBeforeViewChange(beforeMessage)) { currentNavigationState = previousNavigationState; previousNavigationState = previousPreviousNavigationState; return; } // make sure the page uri is updated if necessary, but do not fire any change events // as we have already responded to the change ScopedUI ui = uiProvider.get(); Page page = ui.getPage(); if (!navigationState.getFragment().equals(page.getUriFragment())) { page.setUriFragment(navigationState.getFragment(), false); } // now change the view KrailView view = viewFactory.get(node.getViewClass()); AfterViewChangeBusMessage afterMessage = new AfterViewChangeBusMessage(beforeMessage); changeView(view, afterMessage); // and tell listeners its changed publishAfterViewChange(afterMessage); } else { throw new UnauthorizedException(navigationState.getVirtualPage()); } }