org.apache.wicket.request.flow.RedirectToUrlException Java Examples

The following examples show how to use org.apache.wicket.request.flow.RedirectToUrlException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenIdConnector.java    From onedev with MIT License 6 votes vote down vote up
@Override
public void initiateLogin() {
	try {
		ClientID clientID = new ClientID(clientId);
		
		State state = new State(UUID.randomUUID().toString());
		Session.get().setAttribute(SESSION_ATTR_STATE, state.getValue());
		Session.get().setAttribute(SESSION_ATTR_PROVIDER_METADATA, discoverProviderMetadata());
		
		String scopes = "openid email profile";
		if (groupsClaim != null)
			scopes = scopes + " " + groupsClaim;
		
		AuthenticationRequest request = new AuthenticationRequest(
				new URI(getCachedProviderMetadata().getAuthorizationEndpoint()),
			    new ResponseType("code"), Scope.parse(scopes), clientID, getCallbackUri(),
			    state, new Nonce());
		throw new RedirectToUrlException(request.toURI().toString());
	} catch (URISyntaxException|SerializeException e) {
		throw new RuntimeException(e);
	}		
}
 
Example #2
Source File: DefaultRestorePasswordPage.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Creates container which contains success message about restoring user password
 * @param id component id
 * @return restore success message
 */
protected WebMarkupContainer createRestoreSuccessMessage(String id) {
    return new WebMarkupContainer(id) {
        @Override
        protected void onConfigure() {
            super.onConfigure();
            setVisible(DBClosure.sudo(db -> getModelObject()) == null);
        }

        @Override
        protected void onInitialize() {
            super.onInitialize();
            add(new Link<Void>("loginPage") {
                @Override
                public void onClick() {
                    throw new RedirectToUrlException("/login");
                }
            });
            setOutputMarkupPlaceholderTag(true);
        }
    };
}
 
Example #3
Source File: InvalidBuildPage.java    From onedev with MIT License 6 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	add(new Link<Void>("delete") {

		@Override
		public void onClick() {
			OneDev.getInstance(BuildManager.class).delete(getBuild());
			
			Session.get().success("Build #" + getBuild().getNumber() + " deleted");
			
			String redirectUrlAfterDelete = WebSession.get().getRedirectUrlAfterDelete(Build.class);
			if (redirectUrlAfterDelete != null)
				throw new RedirectToUrlException(redirectUrlAfterDelete);
			else
				setResponsePage(ProjectBuildsPage.class, ProjectBuildsPage.paramsOf(getProject()));
		}

		@Override
		protected void onConfigure() {
			super.onConfigure();
			setVisible(SecurityUtils.canManage(getBuild()));
		}
		
	}.add(new ConfirmClickModifier("Do you really want to delete build #" + getBuild().getNumber() + "?")));
}
 
Example #4
Source File: RoomMenuPanel.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
public void exit(IPartialPageRequestHandler handler) {
	cm.exitRoom(room.getClient());
	if (WebSession.getRights().contains(User.Right.DASHBOARD)) {
		final Room r = room.getRoom();
		if (isMyRoomsEnabled() && r != null && getUserId().equals(r.getOwnerId())) {
			room.getMainPanel().updateContents(ROOMS_MY, handler);
		} else if (r != null && !r.getIspublic()) {
			room.getMainPanel().updateContents(ROOMS_GROUP, handler);
		} else {
			room.getMainPanel().updateContents(ROOMS_PUBLIC, handler);
		}
	} else {
		String url = cfgDao.getString(CONFIG_REDIRECT_URL_FOR_EXTERNAL, "");
		throw new RedirectToUrlException(Strings.isEmpty(url) ? getBaseUrl() : url);
	}
}
 
Example #5
Source File: RedirectMessageDialog.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
private void startTimer(IPartialPageRequestHandler handler) {
	getLabel().add(new OmTimerBehavior(DELAY, labelId) {
		private static final long serialVersionUID = 1L;

		@Override
		protected void onFinish(AjaxRequestTarget target) {
			if (Strings.isEmpty(url)) {
				throw new RestartResponseException(Application.get().getHomePage());
			} else {
				throw new RedirectToUrlException(url);
			}
		}
	}).setOutputMarkupId(true);
	if (handler != null) {
		handler.add(getLabel());
	}
}
 
Example #6
Source File: WebSession.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
private void redirectHash(Room r, Runnable nullAction) {
	if (r != null) {
		String url = cm.getServerUrl(r, baseUrl -> {
			PageParameters params = new PageParameters();
			IRequestParameters reqParams = RequestCycle.get().getRequest().getQueryParameters();
			reqParams.getParameterNames().forEach(name -> {
				params.add(name, reqParams.getParameterValue(name));
			});
			return Application.urlForPage(HashPage.class
					, params
					, baseUrl);
		});
		if (url == null) {
			nullAction.run();
		} else {
			throw new RedirectToUrlException(url);
		}
	}
}
 
Example #7
Source File: UserDeleteLink.java    From onedev with MIT License 5 votes vote down vote up
@Override
public void onClick() {
	OneDev.getInstance(UserManager.class).delete(getUser());
	WebSession.get().success("User '" + getUser().getDisplayName() + "' deleted");
	
	String redirectUrlAfterDelete = WebSession.get().getRedirectUrlAfterDelete(User.class);
	if (redirectUrlAfterDelete != null)
		throw new RedirectToUrlException(redirectUrlAfterDelete);
	else
		setResponsePage(UserListPage.class);
}
 
Example #8
Source File: HomePage.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public HomePage()
{
	ODocument perspective = getPerspective();
	String homeUrl = perspective!=null?perspective.field("homeUrl"):null;
	if(Strings.isEmpty(homeUrl)) homeUrl="/schema";
	if(!OrienteerWebSession.get().isSignedIn()) {
		if(homeUrl.indexOf('?')>=0) homeUrl+='&';
		else homeUrl+='?';
		homeUrl+=FROM_HOME_PARAM+"=true";
	}
	throw new RedirectToUrlException(homeUrl);
}
 
Example #9
Source File: DefaultRestorePasswordPage.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * Create model which contains user
 * with restore id from params with key {@link RestorePasswordResource#PARAMETER_ID} or redirect user to home page
 * @param params params which contains user restore id
 * @return model if restore id present and user with given restore id exists in database
 * @throws RedirectToUrlException if user with given restore id doesn't exists in database or restore id is null or empty
 */
@Override
protected IModel<OrienteerUser> resolveByPageParameters(PageParameters params) {
    final String id = params.get(RestorePasswordResource.PARAMETER_ID).toOptionalString();
    if (Strings.isNullOrEmpty(id)) {
        throw new RedirectToUrlException("/home");
    }

    return OrienteerUserRepository.getUserByRestoreId(id)
            .map(ODocumentWrapperModel::new)
            .orElseThrow(() -> new RedirectToUrlException("/home"));
}
 
Example #10
Source File: WishListItemAddPage.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void onBeforeRender() {

    final PageParameters params = getPageParameters();

    final String skuCode = params.get(ShoppingCartCommand.CMD_ADDTOWISHLIST).toString();
    final String wlType = params.get(ShoppingCartCommand.CMD_ADDTOWISHLIST_P_TYPE).toString();
    final String pageType = params.get(WebParametersKeys.PAGE_TYPE).toString();

    executeHttpPostedCommands();
    super.onBeforeRender();
    persistCartIfNecessary();


    if ("cart".equals(pageType)) {
        if (StringUtils.isNotBlank(skuCode)) {
            throw new RedirectToUrlException("/cart/" + WebParametersKeys.WISHLIST_ITEM_ADDED + "/" + skuCode + "/" + WebParametersKeys.WISHLIST_ITEM_TYPE + "/" + wlType);
        }
        throw new RedirectToUrlException("/cart");
    } else if ("wishlist".equals(pageType)) {
        if (StringUtils.isNotBlank(skuCode)) {
            throw new RedirectToUrlException("/wishlist?" + WebParametersKeys.WISHLIST_ITEM_ADDED + "=" + skuCode);
        }
        throw new RedirectToUrlException("/wishlist");
    }

    final PageParameters targetParams = getWicketUtil().getFilteredRequestParameters(params);
    if (StringUtils.isNotBlank(skuCode)) {

        final ProductSku sku = productServiceFacade.getProductSkuBySkuCode(skuCode);
        targetParams.set(WebParametersKeys.SKU_ID, sku.getSkuId());
        targetParams.set(WebParametersKeys.WISHLIST_ITEM_ADDED, skuCode);
        targetParams.set(WebParametersKeys.WISHLIST_ITEM_TYPE, wlType);

    }
    throw new RestartResponseException(Application.get().getHomePage(), targetParams);

}
 
Example #11
Source File: InvalidCodeCommentPage.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	add(new Link<Void>("delete") {

		@Override
		public void onClick() {
			OneDev.getInstance(CodeCommentManager.class).delete(getCodeComment());
			
			Session.get().success("Code comment #" + getCodeComment().getId() + " deleted");
			
			String redirectUrlAfterDelete = WebSession.get().getRedirectUrlAfterDelete(CodeComment.class);
			if (redirectUrlAfterDelete != null)
				throw new RedirectToUrlException(redirectUrlAfterDelete);
			else
				setResponsePage(ProjectCodeCommentsPage.class, ProjectCodeCommentsPage.paramsOf(getProject()));
			
		}

		@Override
		protected void onConfigure() {
			super.onConfigure();
			setVisible(SecurityUtils.canManageCodeComments(getCodeComment().getProject()));
		}
		
	}.add(new ConfirmClickModifier("Really want to delete this code comment?")));
}
 
Example #12
Source File: PullRequestDetailPage.java    From onedev with MIT License 5 votes vote down vote up
private WebMarkupContainer newManageContainer() {
	WebMarkupContainer container = new WebMarkupContainer("manage");
	container.setVisible(SecurityUtils.canManage(getPullRequest().getTargetProject()));
	container.add(new Link<Void>("synchronize") {

		@Override
		protected void onConfigure() {
			super.onConfigure();
			setVisible(getPullRequest().isOpen());
		}

		@Override
		public void onClick() {
			getPullRequestManager().check(getPullRequest());
			if (getPullRequest().getCheckError() == null) 
				Session.get().success("Pull request is synchronized");
		}
		
	});
	container.add(new Link<Void>("delete") {

		@Override
		public void onClick() {
			PullRequest request = getPullRequest();
			getPullRequestManager().delete(request);
			Session.get().success("Pull request #" + request.getNumber() + " deleted");
			
			String redirectUrlAfterDelete = WebSession.get().getRedirectUrlAfterDelete(PullRequest.class);
			if (redirectUrlAfterDelete != null)
				throw new RedirectToUrlException(redirectUrlAfterDelete);
			else
				setResponsePage(ProjectPullRequestsPage.class, ProjectPullRequestsPage.paramsOf(getProject()));
		}
		
	}.add(new ConfirmClickModifier("Do you really want to delete this pull request?")));
	return container;
}
 
Example #13
Source File: InvalidPullRequestPage.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	add(new Link<Void>("delete") {

		@Override
		public void onClick() {
			PullRequest request = requestModel.getObject();
			OneDev.getInstance(PullRequestManager.class).delete(request);
			
			Session.get().success("Pull request #" + request.getNumber() + " deleted");
			
			String redirectUrlAfterDelete = WebSession.get().getRedirectUrlAfterDelete(PullRequest.class);
			if (redirectUrlAfterDelete != null)
				throw new RedirectToUrlException(redirectUrlAfterDelete);
			else
				setResponsePage(ProjectPullRequestsPage.class, ProjectPullRequestsPage.paramsOf(getProject()));
		}

		@Override
		protected void onConfigure() {
			super.onConfigure();
			setVisible(SecurityUtils.canManage(requestModel.getObject().getTargetProject()));
		}
		
	}.add(new ConfirmClickModifier("Do you really want to delete pull request #" + requestModel.getObject().getNumber() + "?")));
}
 
Example #14
Source File: SignInPage.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
public static void showAuth(final OAuthServer s) {
	String authUrl = prepareUrl(s.getRequestKeyUrl(), getInitParams(s));
	log.debug("redirectUrl={}", authUrl);
	throw new RedirectToUrlException(authUrl);
}
 
Example #15
Source File: GroupProfilePage.java    From onedev with MIT License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();

	editor = BeanContext.editModel("editor", new IModel<Serializable>() {

		@Override
		public void detach() {
		}

		@Override
		public Serializable getObject() {
			return getGroup();
		}

		@Override
		public void setObject(Serializable object) {
			// check contract of GroupManager.save on why we assign oldName here
			oldName = getGroup().getName();
			editor.getDescriptor().copyProperties(object, getGroup());
		}
		
	});

	Form<?> form = new Form<Void>("form") {

		@Override
		protected void onSubmit() {
			super.onSubmit();
			
			Group group = getGroup();
			GroupManager groupManager = OneDev.getInstance(GroupManager.class);
			Group groupWithSameName = groupManager.find(group.getName());
			if (groupWithSameName != null && !groupWithSameName.equals(group)) {
				editor.error(new Path(new PathNode.Named("name")),
						"This name has already been used by another group.");
			} 
			if (editor.isValid()) {
				groupManager.save(group, oldName);
				setResponsePage(GroupProfilePage.class, GroupProfilePage.paramsOf(group));
				Session.get().success("Profile updated");
			}
		}
		
	};	
	form.add(editor);
	form.add(new FencedFeedbackPanel("feedback", form).setEscapeModelStrings(false));
	
	form.add(new Link<Void>("delete") {

		@Override
		public void onClick() {
			OneDev.getInstance(GroupManager.class).delete(getGroup());
			Session.get().success("Group '" + getGroup().getName() + "' deleted");
			
			String redirectUrlAfterDelete = WebSession.get().getRedirectUrlAfterDelete(Group.class);
			if (redirectUrlAfterDelete != null)
				throw new RedirectToUrlException(redirectUrlAfterDelete);
			else
				setResponsePage(GroupListPage.class);
		}
		
	}.add(new ConfirmClickModifier("Do you really want to delete group '" + getGroup().getName() + "'?")));
	
	add(form);
}
 
Example #16
Source File: RoleDetailPage.java    From onedev with MIT License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	if (getRole().isOwner()) {
		add(new Fragment("content", "ownerFrag", this));
	} else {
		Fragment fragment = new Fragment("content", "nonOwnerFrag", this);
		editor = BeanContext.editModel("editor", new IModel<Serializable>() {

			@Override
			public void detach() {
			}

			@Override
			public Serializable getObject() {
				return getRole();
			}

			@Override
			public void setObject(Serializable object) {
				oldName = getRole().getName();
				editor.getDescriptor().copyProperties(object, getRole());
			}
			
		});
		
		Form<?> form = new Form<Void>("form") {

			@Override
			protected void onSubmit() {
				super.onSubmit();
				
				Role role = getRole();
				RoleManager roleManager = OneDev.getInstance(RoleManager.class);
				Role roleWithSameName = roleManager.find(role.getName());
				if (roleWithSameName != null && !roleWithSameName.equals(role)) {
					editor.error(new Path(new PathNode.Named("name")),
							"This name has already been used by another role.");
				} 
				if (editor.isValid()) {
					roleManager.save(role, oldName);
					setResponsePage(RoleDetailPage.class, RoleDetailPage.paramsOf(role));
					Session.get().success("Role updated");
				}
			}
			
		};	
		
		form.add(editor);
		form.add(new FencedFeedbackPanel("feedback", form).setEscapeModelStrings(false));
		
		form.add(new Link<Void>("delete") {

			@Override
			public void onClick() {
				OneDev.getInstance(RoleManager.class).delete(getRole());
				Session.get().success("Role '" + getRole().getName() + "' deleted");
				
				String redirectUrlAfterDelete = WebSession.get().getRedirectUrlAfterDelete(Role.class);
				if (redirectUrlAfterDelete != null)
					throw new RedirectToUrlException(redirectUrlAfterDelete);
				else
					setResponsePage(RoleListPage.class);
			}

			@Override
			protected void onConfigure() {
				super.onConfigure();
				setVisible(!getRole().isOwner());
			}
			
		}.add(new ConfirmClickModifier("Do you really want to delete role '" + getRole().getName() + "'?")));
		
		fragment.add(form);
		add(fragment);
	}
}
 
Example #17
Source File: OmUrlFragment.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
private static void moveToServer(Room r) {
	String url = Application.get().getBean(ClientManager.class).getServerUrl(r, null);
	if (url != null) {
		throw new RedirectToUrlException(url);
	}
}
 
Example #18
Source File: DefaultRestorePasswordPage.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public DefaultRestorePasswordPage() {
    throw new RedirectToUrlException("/home");
}
 
Example #19
Source File: NewPollPage.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
public static void redirectToNewPollPage(final PageParameters parameters) {
  throw new RedirectToUrlException(RequestCycle.get().urlFor(NewPollPage.class, parameters).toString());
}
 
Example #20
Source File: SocialNetworkPanel.java    From Orienteer with Apache License 2.0 3 votes vote down vote up
/**
 * Calls when user clicks on social image for login user.
 * Redirects user to social network authorization url
 * See {@link IOAuth2Service#requestAuthorizationUrl(OAuth2Service, String)}
 * @param target {@link AjaxRequestTarget}
 * @param model model with {@link OAuth2Service} for login
 */
protected void onSocialImageClick(AjaxRequestTarget target, IModel<OAuth2Service> model) {
    OAuth2Service service = model.getObject();
    OAuth2ServiceContext ctx = createOAuth2ServiceContext(service);
    DBClosure.sudoConsumer(db -> ctx.save());
    throw new RedirectToUrlException(ctx.getAuthorizationUrl());
}