List of usage examples for org.apache.wicket.request.flow RedirectToUrlException RedirectToUrlException
public RedirectToUrlException(final String redirectUrl)
From source file:ch.tkuhn.nanobrowser.NanopubPage.java
License:Open Source License
public NanopubPage(final PageParameters parameters) { pub = new NanopubElement(parameters.get("uri").toString()); add(new MenuBar("menubar")); WebMarkupContainer icon = new WebMarkupContainer("icon"); if (pub.isValid()) { icon.add(new AttributeModifier("src", new Model<String>("icons/nanopubv.svg"))); }//from w w w.j ava2 s .c o m add(icon); add(new Label("title", pub.getShortName())); add(new Link<Object>("trig") { private static final long serialVersionUID = 4680516569316406945L; @SuppressWarnings("deprecation") public void onClick() { throw new RedirectToUrlException("./trig?uri=" + URLEncoder.encode(pub.getURI())); } }); add(new Link<Object>("xml") { private static final long serialVersionUID = 4680516569316406945L; @SuppressWarnings("deprecation") public void onClick() { throw new RedirectToUrlException("./xml?uri=" + URLEncoder.encode(pub.getURI())); } }); add(new Link<Object>("nq") { private static final long serialVersionUID = 4680516569316406945L; @SuppressWarnings("deprecation") public void onClick() { throw new RedirectToUrlException("./nq?uri=" + URLEncoder.encode(pub.getURI())); } }); add(new ExternalLink("uri", pub.getURI(), pub.getTruncatedURI())); add(new HList("typelist", pub.getTypes(), "Types")); String dateString = pub.getCreateDateString(); if (dateString == null) { add(new Label("dateempty", "(unknown)")); add(new Label("date", "")); } else { add(new Label("dateempty", "")); add(new Label("date", dateString)); } add(new HList("authorlist", pub.getAuthors(), "Authors")); add(new HList("creatorlist", pub.getCreators(), "Creator")); List<SentenceElement> sentass = pub.getSentenceAssertions(); if (sentass.size() > 0) { add(new VList("sentencelist", sentass, "Assertion as sentence")); } else { add(new Label("sentencelist", "")); } List<Triple<?, ?>> ass = pub.getAssertionTriples(); if (ass.size() > 0) { String assUri = pub.getNanopub().getAssertionUri().stringValue(); String note = null; if (!pub.hasCompleteFormalAssertionQuery()) note = "(incomplete)"; add(new VList("asslist", TripleStoreAccess.sortTriples(ass), "Assertion as formula", assUri, note)); } else { add(new Label("asslist", "")); } List<Triple<?, ?>> prov = pub.getProvenanceTriples(); if (prov.size() > 0) { add(new VList("provlist", TripleStoreAccess.sortTriples(prov), "Provenance", pub.getURI())); } else { add(new Label("provlist", "")); } List<Opinion> opinions = pub.getOpinions(true); add(new Label("emptyopinions", opinions.isEmpty() ? "(nothing)" : "")); add(new ListView<Opinion>("opinions", opinions) { private static final long serialVersionUID = 6804591967140101102L; protected void populateItem(ListItem<Opinion> item) { item.add(new AgentItem("opinionagent", item.getModelObject().getAgent())); item.add(new Label("opinion", Opinion.getVerbPhrase(item.getModelObject().getOpinionType(), false) + ".")); item.add(new NanopubItem("opinionpub", item.getModelObject().getNanopub(), ThingElement.TINY_GUI_ITEM)); } }); WebMarkupContainer aa = new WebMarkupContainer("adminactions"); if (NanobrowserApplication.isInDevelopmentMode()) { aa.add(new Link<Object>("delete") { private static final long serialVersionUID = 8608371149183694875L; public void onClick() { pub.delete(); MainPage.resetLists(); setResponsePage(MainPage.class); } }); } else { aa.add(new AttributeModifier("class", new Model<String>("hidden"))); aa.add(new Label("delete", "")); } add(aa); }
From source file:com.evolveum.midpoint.web.component.menu.MainMenuPanel.java
License:Apache License
private void additionalMenuPerformed(MainMenuItem menu) { LOGGER.trace("additionalMenuPerformed: {}", menu); SessionStorage storage = getPageBase().getSessionStorage(); storage.clearBreadcrumbs();/*w ww . j ava 2 s . c om*/ if (menu.getPageClass() != null) { setResponsePage(menu.getPageClass()); } else { throw new RedirectToUrlException(((AdditionalMenuItem) menu).getTargetUrl()); } }
From source file:com.gitblit.wicket.GitBlitWebSession.java
License:Apache License
/** * Continue any cached request. This is used when a request for a protected * resource is aborted/redirected pending proper authentication. Gitblit * no longer uses Wicket's built-in mechanism for this because of Wicket's * failure to properly handle parameters with forward-slashes. This is a * constant source of headaches with Wicket. * * @return false if there is no cached request to process *//*w ww . j a va 2 s . co m*/ public boolean continueRequest() { if (requestUrl != null) { String url = requestUrl; requestUrl = null; throw new RedirectToUrlException(url); } return false; }
From source file:com.gitblit.wicket.pages.BasePage.java
License:Apache License
public void error(String message, Throwable t, Class<? extends Page> toPage, PageParameters params) { if (t == null) { logger().error(message + " for " + GitBlitWebSession.get().getUsername()); } else {/*from w w w . j ava 2 s .c om*/ logger().error(message + " for " + GitBlitWebSession.get().getUsername(), t); } if (toPage != null) { GitBlitWebSession.get().cacheErrorMessage(message); String absoluteUrl = GitBlitRequestUtils.toAbsoluteUrl(toPage, params); throw new RedirectToUrlException(absoluteUrl); } else { super.error(message); } }
From source file:com.olegchir.flussonic_userlinks.page.HomePage.HomePage.java
License:Apache License
public HomePage(PageParameters params) { super(params); //http://stackoverflow.com/questions/3334827/wicket-how-to-redirect-to-another-page throw new RedirectToUrlException("admin_dashboard"); }
From source file:com.tysanclan.site.projectewok.pages.member.FeelingLuckyPage.java
License:Open Source License
/** * // w w w . j av a 2 s. co m */ public FeelingLuckyPage() { super("Feeling lucky"); add(new Label("score", new Model<Integer>(getUser().getLuckyScore()))); add(new Form<User>("luckyForm") { private static final long serialVersionUID = 1L; @SpringBean private MembershipService membershipService; /** * @see org.apache.wicket.markup.html.form.Form#onSubmit() */ @Override protected void onSubmit() { int score = rand.nextInt(90); membershipService.feelLucky(getUser()); if (score < 4) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=h1ZAXYyxd08"); } else if (score < 8) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=WQgLNUq0ktI"); } else if (score < 12) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=3KANI2dpXLw"); } else if (score < 16) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=J_DV9b0x7v4"); } else if (score < 20) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=a-79sbicwTQ"); } else if (score < 24) { setResponsePage(new PastElectionsPage()); } else if (score < 28) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=Mo8Qls0HnWo"); } else if (score < 32) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=nr_CJL1YQRc"); } else if (score < 36) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=uIg9VaMBi9o"); } else if (score < 40) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=QZtfphBDp-w"); } else if (score < 44) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=dcXNXKtu8z4"); } else if (score < 48) { throw new RedirectToUrlException("http://www.youtube.com/watch?v=CIZYqZrdwIM"); } else { setResponsePage(new OverviewPage()); } } }); }
From source file:com.tysanclan.site.projectewok.util.AprilFools.java
License:Open Source License
public static void performRickRoll() { int index = rand.nextInt(videos.length); throw new RedirectToUrlException(videos[index]); }
From source file:guru.mmp.application.web.template.pages.ChangePasswordPage.java
License:Apache License
/** * Constructs a new <code>ChangePasswordPage</code>. * * @param username the username/*from ww w. ja va2s . c om*/ */ ChangePasswordPage(String username) { try { // Setup the page title String title = ((TemplateWebApplication) getApplication()).getDisplayName() + " | Change " + "Password"; Label titleLabel = new Label("pageTitle", title); titleLabel.setRenderBodyOnly(false); add(titleLabel); // Setup the alerts Alerts alerts = new Alerts("alerts"); add(alerts); // Setup the changePasswordForm Form<Void> changePasswordForm = new Form<>("changePasswordForm"); changePasswordForm.setMarkupId("changePasswordForm"); changePasswordForm.setOutputMarkupId(true); add(changePasswordForm); // The "oldPassword" field PasswordTextField oldPasswordField = new PasswordTextFieldWithFeedback("oldPassword", new PropertyModel<>(this, "oldPassword")); oldPasswordField.setRequired(true); oldPasswordField.add(new DefaultFocusBehavior()); changePasswordForm.add(oldPasswordField); // The "newPassword" field PasswordTextField newPasswordField = new PasswordTextFieldWithFeedback("newPassword", new PropertyModel<>(this, "newPassword")); newPasswordField.setRequired(true); newPasswordField.add(StringValidator.minimumLength(6)); newPasswordField.add(new PasswordPolicyValidator()); changePasswordForm.add(newPasswordField); // The "confirmPassword" field PasswordTextField confirmPasswordField = new PasswordTextFieldWithFeedback("confirmPassword", new PropertyModel<>(this, "confirmPassword")); confirmPasswordField.setRequired(true); changePasswordForm.add(confirmPasswordField); changePasswordForm.add(new EqualPasswordInputValidator(newPasswordField, confirmPasswordField)); // The "changePasswordButton" button Button changePasswordButton = new Button("changePasswordButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { try { // Authenticate the user UUID userDirectoryId = securityService.changePassword(username, oldPassword, newPassword); // Retrieve the user details User user = securityService.getUser(userDirectoryId, username); // Initialise the web session for the user WebSession session = getWebApplicationSession(); session.setUserDirectoryId(user.getUserDirectoryId()); session.setUsername(user.getUsername()); session.setUserFullName(user.getFirstName() + " " + user.getLastName()); // Make session permanent after login if (session.isTemporary()) { session.bind(); } else { session.dirty(); // for cluster replication } // Invalidate the cached navigation state if (session instanceof TemplateWebSession) { ((TemplateWebSession) session).getNavigationState().invalidate(); } // Check whether the user is associated with more than 1 organisation List<Organisation> organisations = securityService .getOrganisationsForUserDirectory(userDirectoryId); if (organisations.size() == 0) { error("Authentication Failed."); error(String.format("The user (%s) is not associated with any organisations.", username)); } else if (organisations.size() == 1) { List<String> groupNames = securityService.getGroupNamesForUser(userDirectoryId, username); List<String> functionCodes = securityService.getFunctionCodesForUser(userDirectoryId, username); session.setOrganisation(organisations.get(0)); session.setGroupNames(groupNames); session.setFunctionCodes(functionCodes); if (logger.isDebugEnabled()) { logger.debug(String.format( "Successfully authenticated user (%s) for organisation (%s) with groups (%s) " + "and function codes (%s)", username, organisations.get(0).getId(), StringUtil.delimit(groupNames, ","), StringUtil.delimit(functionCodes, ","))); } // Redirect to the secure home page for the application throw new RedirectToUrlException( urlFor(((TemplateWebApplication) getApplication()).getSecureHomePage(), new PageParameters()).toString()); } else { /* * Redirect to the page allowing the user to select which organisation they wish to * work with. */ throw new RedirectToUrlException( urlFor(SelectOrganisationPage.class, new PageParameters()).toString()); } } catch (RedirectToUrlException e) { throw e; } catch (ExistingPasswordException e) { error("The specified new password has been used recently."); } catch (AuthenticationFailedException | UserNotFoundException e) { error("The specified old password is incorrect."); } catch (UserLockedException e) { error("Your user account has been locked."); } catch (Throwable e) { logger.error( String.format("Failed to authenticate the user (%s): %s", username, e.getMessage()), e); error("The system is currently unavailable."); } } }; changePasswordForm.add(changePasswordButton); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the ChangePasswordPage", e); } }
From source file:guru.mmp.application.web.template.pages.LoginPage.java
License:Apache License
/** * Constructs a new <code>LoginPage</code>. *//* w ww . ja v a 2 s . c om*/ public LoginPage() { try { // Setup the page title String title = ((TemplateWebApplication) getApplication()).getDisplayName() + " | Login"; Label titleLabel = new Label("pageTitle", title); titleLabel.setRenderBodyOnly(false); add(titleLabel); // Setup the alerts Alerts alerts = new Alerts("alerts"); add(alerts); // Setup the loginForm Form<Void> loginForm = new Form<>("loginForm"); loginForm.setMarkupId("loginForm"); loginForm.setOutputMarkupId(true); add(loginForm); // The "username" field TextField<String> usernameField = new TextFieldWithFeedback<>("username", new PropertyModel<>(this, "username")); usernameField.setRequired(true); usernameField.add(new DefaultFocusBehavior()); loginForm.add(usernameField); // The "password" field PasswordTextField passwordField = new PasswordTextFieldWithFeedback("password", new PropertyModel<>(this, "password")); passwordField.setRequired(true); loginForm.add(passwordField); // The "loginButton" button Button loginButton = new Button("loginButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { try { if (Debug.inDebugMode() && ("s".equals(username))) { username = "Administrator"; password = "Password1"; } // Authenticate the user UUID userDirectoryId = securityService.authenticate(username, password); // Retrieve the user details User user = securityService.getUser(userDirectoryId, username); // Initialise the web session for the user WebSession session = getWebApplicationSession(); session.setUserDirectoryId(user.getUserDirectoryId()); session.setUsername(user.getUsername()); session.setUserFullName(user.getFirstName() + " " + user.getLastName()); // Make session permanent after login if (session.isTemporary()) { session.bind(); } else { session.dirty(); // for cluster replication } // Invalidate the cached navigation state if (session instanceof TemplateWebSession) { ((TemplateWebSession) session).getNavigationState().invalidate(); } // Check whether the user is associated with more than 1 organisation List<Organisation> organisations = securityService .getOrganisationsForUserDirectory(userDirectoryId); if (organisations.size() == 0) { error(String.format("The user (%s) is not associated with any organisations.", username)); } else if (organisations.size() == 1) { Organisation organisation = organisations.get(0); if (organisation.getStatus() != OrganisationStatus.ACTIVE) { error("The organisation (" + organisation.getName() + ") is not active."); return; } List<String> groupNames = securityService.getGroupNamesForUser(userDirectoryId, username); List<String> functionCodes = securityService.getFunctionCodesForUser(userDirectoryId, username); logger.info("The user (" + username + ") is a member of the following groups: " + ((groupNames.size() == 0) ? "None" : StringUtil.delimit(groupNames, ","))); logger.info("The user (" + username + ") has access to the following functions: " + ((functionCodes.size() == 0) ? "None" : StringUtil.delimit(functionCodes, ","))); session.setOrganisation(organisation); session.setGroupNames(groupNames); session.setFunctionCodes(functionCodes); if (logger.isDebugEnabled()) { logger.debug(String.format( "Successfully authenticated user (%s) for organisation (%s) with groups (%s) " + "and function codes (%s)", username, organisations.get(0).getId(), StringUtil.delimit(groupNames, ","), StringUtil.delimit(functionCodes, ","))); } // Redirect to the secure home page for the application throw new RedirectToUrlException( urlFor(((TemplateWebApplication) getApplication()).getSecureHomePage(), new PageParameters()).toString()); } else { /* * Redirect to the page allowing the user to select which organisation they wish to * work with. */ throw new RedirectToUrlException( urlFor(SelectOrganisationPage.class, new PageParameters()).toString()); } } catch (RedirectToUrlException e) { throw e; } catch (AuthenticationFailedException | UserNotFoundException e) { error("The specified username or password is incorrect."); } catch (UserLockedException e) { error("Your user account has been locked."); } catch (ExpiredPasswordException e) { getRequestCycle().setResponsePage(new ChangePasswordPage(username)); } catch (Throwable e) { logger.error( String.format("Failed to authenticate the user (%s): %s", username, e.getMessage()), e); error("The system is currently unavailable."); } } }; loginForm.add(loginButton); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the LoginPage", e); } }
From source file:guru.mmp.application.web.template.pages.SelectOrganisationPage.java
License:Apache License
/** * Constructs a new <code>SelectOrganisationPage</code>. *///from w ww . j av a2s.c om public SelectOrganisationPage() throws SecurityException { try { // Setup the page title String title = ((TemplateWebApplication) getApplication()).getDisplayName() + " | Select " + "Organisation"; Label titleLabel = new Label("pageTitle", title); titleLabel.setRenderBodyOnly(false); add(titleLabel); // Setup the alerts add(new Alerts("alerts")); Form<Void> form = new Form<>("selectOrganisationForm"); add(form); // The "organisation" field ChoiceRenderer<StringSelectOption> choiceRenderer = new ChoiceRenderer<>("name", "value"); DropDownChoice<StringSelectOption> organisationField = new DropDownChoiceWithFeedback<>("organisation", new PropertyModel<>(this, "organisation"), getOrganisationOptions(), choiceRenderer); organisationField.setRequired(true); form.add(organisationField); // The "continueButton" button Button continueButton = new Button("continueButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { WebSession session = getWebApplicationSession(); try { Organisation selectedOrganisation = securityService .getOrganisation(UUID.fromString(organisation.getValue())); if (selectedOrganisation.getStatus() != OrganisationStatus.ACTIVE) { error("The organisation (" + selectedOrganisation.getName() + ") is not active."); return; } List<String> groupNames = securityService.getGroupNamesForUser(session.getUserDirectoryId(), session.getUsername()); List<String> functionCodes = securityService .getFunctionCodesForUser(session.getUserDirectoryId(), session.getUsername()); logger.info("The user (" + session.getUsername() + ") is a member of the following groups: " + ((groupNames.size() == 0) ? "None" : StringUtil.delimit(groupNames, ","))); logger.info("The user (" + session.getUsername() + ") has access to the following functions: " + ((functionCodes.size() == 0) ? "None" : StringUtil.delimit(functionCodes, ","))); session.setOrganisation(selectedOrganisation); session.setGroupNames(groupNames); session.setFunctionCodes(functionCodes); if (logger.isDebugEnabled()) { logger.debug(String.format( "Successfully authenticated user (%s) for organisation (%s) with groups (%s) and " + "function codes (%s)", session.getUsername(), organisation.getName(), StringUtil.delimit(groupNames, ","), StringUtil.delimit(functionCodes, ","))); } // Redirect to the secure home page for the application throw new RedirectToUrlException( urlFor(((TemplateWebApplication) getApplication()).getSecureHomePage(), new PageParameters()).toString()); } catch (RedirectToUrlException e) { throw e; } catch (Throwable e) { logger.error(String.format("Failed to select the organisation for the user (%s)", session.getUsername()), e); session.invalidateNow(); throw new RedirectToUrlException( urlFor(((TemplateWebApplication) getApplication()).getHomePage(), new PageParameters()).toString()); } } }; form.add(continueButton); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the SelectOrganisationPage", e); } }