How to use deserialize method of com.testsigma.security.HttpCookieOAuth2AuthorizationRequestRepository class

Best Testsigma code snippet using com.testsigma.security.HttpCookieOAuth2AuthorizationRequestRepository.deserialize

Source:HttpCookieOAuth2AuthorizationRequestRepository.java Github

copy

Full Screen

...45 @Override46 public OAuth2AuthorizationRequest loadAuthorizationRequest(HttpServletRequest request) {47 Assert.notNull(request, "request cannot be null");48 return fetchCookie(request, AUTHORIZATION_REQUEST_COOKIE_NAME)49 .map(this::deserialize)50 .orElse(null);51 }52 @Override53 public void saveAuthorizationRequest(54 OAuth2AuthorizationRequest authorizationRequest, HttpServletRequest request,55 HttpServletResponse response) {56 Assert.notNull(request, "request cannot be null");57 Assert.notNull(response, "response cannot be null");58 if (authorizationRequest == null) {59 deleteCookies(request, response);60 return;61 }62 Cookie cookie = new Cookie(AUTHORIZATION_REQUEST_COOKIE_NAME, serialize(authorizationRequest));63 cookie.setPath("/");64 cookie.setHttpOnly(true);65 cookie.setMaxAge(600);66 response.addCookie(cookie);67 String redirectUri = request.getParameter(REDIRECT_URI_COOKIE_PARAM_NAME);68 if (StringUtils.isNotBlank(redirectUri)) {69 cookie = new Cookie(REDIRECT_URI_COOKIE_PARAM_NAME, redirectUri);70 cookie.setPath("/");71 cookie.setHttpOnly(true);72 cookie.setMaxAge(600);73 response.addCookie(cookie);74 }75 }76 @Override77 public OAuth2AuthorizationRequest removeAuthorizationRequest(HttpServletRequest request) {78 return loadAuthorizationRequest(request);79 }80 private String serialize(OAuth2AuthorizationRequest authorizationRequest) {81 return Base64.getUrlEncoder().encodeToString(82 SerializationUtils.serialize(authorizationRequest));83 }84 private OAuth2AuthorizationRequest deserialize(Cookie cookie) {85 return SerializationUtils.deserialize(86 Base64.getUrlDecoder().decode(cookie.getValue()));87 }88}...

Full Screen

Full Screen

deserialize

Using AI Code Generation

copy

Full Screen

1 public OAuth2AuthorizationRequest deserialize(HttpServletRequest request, String cookieValue) {2 OAuth2AuthorizationRequest authorizationRequest = null;3 try {4 authorizationRequest = objectMapper.readValue(URLDecoder.decode(cookieValue, StandardCharsets.UTF_8.name()), OAuth2AuthorizationRequest.class);5 } catch (UnsupportedEncodingException e) {6 log.error("Failed to deserialize OAuth2AuthorizationRequest from cookie", e);7 } catch (JsonProcessingException e) {8 log.error("Failed to deserialize OAuth2AuthorizationRequest from cookie", e);9 }10 return authorizationRequest;11 }12}

Full Screen

Full Screen

deserialize

Using AI Code Generation

copy

Full Screen

1public class HttpCookieOAuth2AuthorizationRequestRepository implements AuthorizationRequestRepository<OAuth2AuthorizationRequest> {2 private static final String OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME = "oauth2_auth_request";3 private static final String REDIRECT_URI_PARAM_COOKIE_NAME = "redirect_uri";4 private static final int cookieExpireSeconds = 180;5 public OAuth2AuthorizationRequest loadAuthorizationRequest(HttpServletRequest request) {6 return this.deserialize(request, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME);7 }8 public void saveAuthorizationRequest(OAuth2AuthorizationRequest authorizationRequest, HttpServletRequest request, HttpServletResponse response) {9 if (authorizationRequest == null) {10 this.removeAuthorizationRequestCookies(request, response);11 return;12 }13 this.addCookie(response, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME, this.serialize(authorizationRequest), cookieExpireSeconds);14 String redirectUriAfterLogin = request.getParameter(REDIRECT_URI_PARAM_COOKIE_NAME);15 if (redirectUriAfterLogin != null) {16 this.addCookie(response, REDIRECT_URI_PARAM_COOKIE_NAME, redirectUriAfterLogin, cookieExpireSeconds);17 }18 }19 public OAuth2AuthorizationRequest removeAuthorizationRequest(HttpServletRequest request) {20 return this.loadAuthorizationRequest(request);21 }22 public void removeAuthorizationRequestCookies(HttpServletRequest request, HttpServletResponse response) {23 this.removeCookie(request, response, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME);24 this.removeCookie(request, response, REDIRECT_URI_PARAM_COOKIE_NAME);25 }26 private void addCookie(HttpServletResponse response, String cookieName, String cookieValue, int expireSeconds) {27 Cookie cookie = new Cookie(cookieName, cookieValue);28 cookie.setPath("/");29 cookie.setHttpOnly(true);30 cookie.setMaxAge(expireSeconds);31 response.addCookie(cookie);32 }33 private void removeCookie(HttpServletRequest request, HttpServletResponse response, String cookieName) {34 Cookie cookie = new Cookie(cookieName, null);35 cookie.setPath("/");36 cookie.setHttpOnly(true);37 cookie.setMaxAge(0);38 response.addCookie(cookie);39 }40 private String serialize(OAuth2AuthorizationRequest authorizationRequest) {41 try {42 return new ObjectMapper().writeValueAsString(authorizationRequest);43 }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testsigma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful