org.apache.wicket.protocol.http.servlet.ServletWebRequest Java Examples
The following examples show how to use
org.apache.wicket.protocol.http.servlet.ServletWebRequest.
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: OneWebApplication.java From onedev with MIT License | 6 votes |
@Override public WebRequest newWebRequest(HttpServletRequest servletRequest, String filterPath) { return new ServletWebRequest(servletRequest, filterPath) { @Override public boolean shouldPreserveClientUrl() { if (RequestCycle.get().getActiveRequestHandler() instanceof RenderPageRequestHandler) { RenderPageRequestHandler requestHandler = (RenderPageRequestHandler) RequestCycle.get().getActiveRequestHandler(); /* * Add this to make sure that the page url does not change upon errors, so that * user can know which page is actually causing the error. This behavior is common * for main stream applications. */ if (requestHandler.getPage() instanceof GeneralErrorPage) return true; } return super.shouldPreserveClientUrl(); } }; }
Example #2
Source File: LoginPage.java From webanno with Apache License 2.0 | 6 votes |
@Override protected void onSubmit() { AuthenticatedWebSession session = AuthenticatedWebSession.get(); if (session.signIn(username, password)) { log.debug("Login successful"); if (sessionRegistry != null) { // Form-based login isn't detected by SessionManagementFilter. Thus handling // session registration manually here. HttpSession containerSession = ((ServletWebRequest) RequestCycle.get() .getRequest()).getContainerRequest().getSession(false); sessionRegistry.registerNewSession(containerSession.getId(), username); } setDefaultResponsePageIfNecessary(); } else { error("Login failed"); } }
Example #3
Source File: NextServerApplication.java From nextreports-server with Apache License 2.0 | 6 votes |
@Override public void onBeginRequest(RequestCycle cycle) { String username = ""; if (NextServerSession.get().isSignedIn()) { username = NextServerSession.get().getUsername(); } Session session = NextServerSession.get(); String sessionId = NextServerSession.get().getId(); if (sessionId == null) { session.bind(); sessionId = session.getId(); } HttpServletRequest request = ((ServletWebRequest) RequestCycle.get().getRequest()).getContainerRequest(); String ip = request.getHeader("X-Forwarded-For"); if (ip == null) { ip = request.getRemoteHost(); } MDC.put("username", username); MDC.put("session", sessionId); MDC.put("ip", ip); }
Example #4
Source File: IdentificationPopoverPanel.java From artifact-listener with Apache License 2.0 | 6 votes |
@Override protected void onInitialize() { super.onInitialize(); // Vérification des retours d'auth pac4J HttpServletRequest request = ((ServletWebRequest) RequestCycle.get().getRequest()).getContainerRequest(); Exception exception = (Exception) request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); if (exception != null) { if (exception instanceof DisabledException) { getSession().error(getString("home.identification.classic.error.userDisabled")); } else if (exception instanceof AuthenticationServiceException) { LOGGER.error("Authentication failed", exception); getSession().error(getString("home.identification.error.badCredentials") + exception.getMessage()); } else { LOGGER.error("An unknown error occurred during the authentication process", exception); getSession().error(getString("home.identification.error.unknown")); } request.getSession().removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); } }
Example #5
Source File: ResponsiveIdentificationPanel.java From artifact-listener with Apache License 2.0 | 6 votes |
@Override protected void onInitialize() { super.onInitialize(); // Vérification des retours d'auth pac4J HttpServletRequest request = ((ServletWebRequest) RequestCycle.get().getRequest()).getContainerRequest(); Exception exception = (Exception) request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); if (exception != null) { if (exception instanceof DisabledException) { getSession().error(getString("home.identification.classic.error.userDisabled")); } else if (exception instanceof AuthenticationServiceException) { LOGGER.error("Authentication failed", exception); getSession().error(getString("home.identification.error.badCredentials") + exception.getMessage()); } else { LOGGER.error("An unknown error occurred during the authentication process", exception); getSession().error(getString("home.identification.error.unknown")); } request.getSession().removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); } }
Example #6
Source File: ApplicationHelper.java From openmeetings with Apache License 2.0 | 5 votes |
public static IApplication ensureApplication(Long langId) { IApplication a = ensureApplication(); if (ThreadContext.getRequestCycle() == null) { ServletWebRequest req = new ServletWebRequest(new MockHttpServletRequest((Application)a, new MockHttpSession(a.getServletContext()), a.getServletContext()), ""); RequestCycleContext rctx = new RequestCycleContext(req, new MockWebResponse(), a.getRootRequestMapper(), a.getExceptionMapperProvider().get()); ThreadContext.setRequestCycle(new RequestCycle(rctx)); } if (ThreadContext.getSession() == null) { WebSession s = WebSession.get(); if (langId > 0) { ((IWebSession)s).setLanguage(langId); } } return a; }
Example #7
Source File: SpringAuthenticatedWebSession.java From webanno with Apache License 2.0 | 5 votes |
@Override public boolean authenticate(String username, String password) { // If already signed in (in Spring Security), then sign out there first // signOut(); try { // Kill current session and create a new one as part of the authentication ((ServletWebRequest) RequestCycle.get().getRequest()).getContainerRequest().getSession() .invalidate(); Authentication authentication = authenticationManager .authenticate(new UsernamePasswordAuthenticationToken(username, password)); MDC.put(Logging.KEY_USERNAME, username); SecurityContextHolder.getContext().setAuthentication(authentication); log.debug("Stored authentication for user [{}] in security context", authentication.getName()); HttpSession session = ((ServletWebRequest) RequestCycle.get().getRequest()) .getContainerRequest().getSession(); session.setAttribute( HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext()); log.debug("Stored security context in session"); return true; } catch (AuthenticationException e) { log.warn("User [{}] failed to login. Reason: {}", username, e.getMessage()); return false; } }
Example #8
Source File: LogoutPanel.java From webanno with Apache License 2.0 | 5 votes |
/** * Checks if auto-logout is enabled. For Winstone, we get a max session length of 0, so here it * is disabled. */ private int getAutoLogoutTime() { int duration = 0; Request request = RequestCycle.get().getRequest(); if (request instanceof ServletWebRequest) { HttpSession session = ((ServletWebRequest) request).getContainerRequest().getSession(); if (session != null) { duration = session.getMaxInactiveInterval(); } } return duration; }
Example #9
Source File: LoginPage.java From webanno with Apache License 2.0 | 5 votes |
private String getRedirectUrl() { String redirectUrl = null; HttpSession session = ((ServletWebRequest) RequestCycle.get().getRequest()) .getContainerRequest().getSession(false); if (session != null) { SavedRequest savedRequest = (SavedRequest) session .getAttribute("SPRING_SECURITY_SAVED_REQUEST"); if (savedRequest != null) { redirectUrl = savedRequest.getRedirectUrl(); } } // There is some kind of bug that logs the user out again if the redirect page is // the context root and if that does not end in a slash. To avoid this, we add a slash // here. This is rather a hack, but I have no idea why this problem occurs. Figured this // out through trial-and-error rather then by in-depth debugging. String baseUrl = RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse("")); if (baseUrl.equals(redirectUrl)) { redirectUrl += "/"; } // In case there was a URL fragment in the original URL, append it again to the redirect // URL. if (redirectUrl != null && isNotBlank(form.urlfragment)) { redirectUrl += "#" + form.urlfragment; } return redirectUrl; }
Example #10
Source File: OIDCClientSelfReg.java From syncope with Apache License 2.0 | 5 votes |
public OIDCClientSelfReg(final PageParameters parameters) { super(parameters); PageParameters params = new PageParameters(); try { params.add("oidcClientUserAttrs", ((ServletWebRequest) getRequest()).getContainerRequest(). getSession().getAttribute(Constants.OIDCCLIENT_USER_ATTRS)); } catch (Exception e) { LOG.error("While extracting user attributes", e); params.add("errorMessage", OIDC_ACCESS_ERROR); } setResponsePage(Self.class, params); }
Example #11
Source File: SAML2SPSelfReg.java From syncope with Apache License 2.0 | 5 votes |
public SAML2SPSelfReg(final PageParameters parameters) { super(parameters); PageParameters params = new PageParameters(); try { params.add("saml2SPUserAttrs", ((ServletWebRequest) getRequest()).getContainerRequest(). getSession().getAttribute(Constants.SAML2SP_USER_ATTRS)); } catch (Exception e) { LOG.error("While extracting user attributes", e); params.add("errorMessage", SAML_ACCESS_ERROR); } setResponsePage(Self.class, params); }
Example #12
Source File: RegisterPage.java From artifact-listener with Apache License 2.0 | 5 votes |
public RegisterPage(PageParameters parameters) { super(parameters); if (AuthenticatedWebSession.exists() && AuthenticatedWebSession.get().isSignedIn()) { redirect(DashboardPage.class); return; } HttpServletRequest request = ((ServletWebRequest) RequestCycle.get().getRequest()).getContainerRequest(); ClientAuthenticationToken token = (ClientAuthenticationToken) request.getSession().getAttribute(Pac4jAuthenticationUtils.AUTH_TOKEN_ATTRIBUTE); IModel<User> userModel = new GenericEntityModel<Long, User>(new User()); if (token != null && token.getUserProfile() != null) { CommonProfile profile = (CommonProfile) token.getUserProfile(); if (profile.getEmail() != null) { User user = userService.getByUserName(profile.getEmail()); if (user != null) { LOGGER.warn("This email address is already used by another user"); getSession().warn(getString("register.userName.notUnique")); } } userModel.getObject().setEmail(profile.getEmail()); userModel.getObject().setFullName(profile.getDisplayName()); userModel.getObject().setRemoteIdentifier(profile.getId()); } addBreadCrumbElement(new BreadCrumbElement(new ResourceModel("register.pageTitle"), RegisterPage.linkDescriptor())); add(new Label("pageTitle", new ResourceModel("register.pageTitle"))); add(new RegisterFormPanel("registerFormPanel", userModel)); }
Example #13
Source File: BaseLogin.java From syncope with Apache License 2.0 | 4 votes |
LocaleDropDown(final String id) { super(id, getSupportedLocales()); setChoiceRenderer(new LocaleRenderer()); setModel(new IModel<Locale>() { private static final long serialVersionUID = -6985170095629312963L; @Override public Locale getObject() { return getSession().getLocale(); } @Override public void setObject(final Locale object) { getSession().setLocale(object); } @Override public void detach() { // Empty. } }); // set default language selection List<Locale> filtered = List.of(); String acceptLanguage = ((ServletWebRequest) RequestCycle.get().getRequest()). getHeader(HttpHeaders.ACCEPT_LANGUAGE); if (StringUtils.isNotBlank(acceptLanguage)) { try { filtered = Locale.filter(Locale.LanguageRange.parse(acceptLanguage), getSupportedLocales()); } catch (Exception e) { LOG.debug("Could not parse {} HTTP header value '{}'", HttpHeaders.ACCEPT_LANGUAGE, acceptLanguage, e); } } getModel().setObject(filtered.isEmpty() ? Locale.ENGLISH : filtered.get(0)); }
Example #14
Source File: ImageCropperPage.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * See list of constants PARAM_* for supported parameters. * @param parameters */ public ImageCropperPage(final PageParameters parameters) { super(parameters); if (WicketUtils.contains(parameters, PARAM_SHOW_UPLOAD_BUTTON) == true) { setEnableWhiteBoardFilter(WicketUtils.getAsBoolean(parameters, PARAM_SHOW_UPLOAD_BUTTON)); } if (WicketUtils.contains(parameters, PARAM_ENABLE_WHITEBOARD_FILTER) == true) { setEnableWhiteBoardFilter(WicketUtils.getAsBoolean(parameters, PARAM_ENABLE_WHITEBOARD_FILTER)); } if (WicketUtils.contains(parameters, PARAM_LANGUAGE) == true) { setDefaultLanguage(WicketUtils.getAsString(parameters, PARAM_LANGUAGE)); } if (WicketUtils.contains(parameters, PARAM_RATIOLIST) == true) { setRatioList(WicketUtils.getAsString(parameters, PARAM_RATIOLIST)); } if (WicketUtils.contains(parameters, PARAM_DEFAULT_RATIO) == true) { setDefaultRatio(WicketUtils.getAsString(parameters, PARAM_DEFAULT_RATIO)); } if (WicketUtils.contains(parameters, PARAM_FILE_FORMAT) == true) { setFileFormat(WicketUtils.getAsString(parameters, PARAM_FILE_FORMAT)); } final ServletWebRequest req = (ServletWebRequest) this.getRequest(); final HttpServletRequest hreq = req.getContainerRequest(); String domain; if (StringUtils.isNotBlank(ConfigXml.getInstance().getDomain()) == true) { domain = ConfigXml.getInstance().getDomain(); } else { domain = hreq.getScheme() + "://" + hreq.getLocalName() + ":" + hreq.getLocalPort(); } final String url = domain + hreq.getContextPath() + "/secure/"; final StringBuffer buf = new StringBuffer(); appendVar(buf, "serverURL", url); // TODO: Wird wohl nicht mehr gebraucht. appendVar(buf, "uploadImageFileTemporaryServlet", url + "UploadImageFileTemporary"); appendVar(buf, "uploadImageFileTemporaryServletParams", "filedirectory=tempimages;filename=image"); appendVar(buf, "downloadImageFileServlet", url + "DownloadImageFile"); appendVar(buf, "downloadImageFileServletParams", "filedirectory=tempimages;filename=image"); appendVar(buf, "uploadImageFileServlet", url + "UploadImageFile"); appendVar(buf, "uploadImageFileServletParams", "filedirectory=images;filename=image;croppedname=cropped"); appendVar(buf, "upAndDownloadImageFileAsByteArrayServlet", url + "UpAndDownloadImageFileAsByteArray"); appendVar(buf, "upAndDownloadImageFileAsByteArrayServletParams", "filename=image;croppedname=cropped"); final HttpSession httpSession = hreq.getSession(); appendVar(buf, "sessionid", httpSession.getId()); appendVar(buf, "ratioList", ratioList); appendVar(buf, "defaultRatio", defaultRatio); appendVar(buf, "isUploadBtn", showUploadButton); appendVar(buf, "whiteBoardFilter", enableWhiteBoardFilter); appendVar(buf, "language", getDefaultLanguage()); appendVar(buf, "fileFormat", fileFormat); appendVar(buf, "flashFile", WicketUtils.getAbsoluteUrl("/imagecropper/MicromataImageCropper")); add(new Label("javaScriptVars", buf.toString()).setEscapeModelStrings(false)); }