Best Testsigma code snippet using com.testsigma.security.JWTAuthenticationFilter.isSessionRequest
Source:JWTAuthenticationFilter.java
...75 if((authUser != null)76 && ObjectUtils.defaultIfNull(tokenService.getServerUuid(), "").equals(authUser.getServerUuid())) {77 auth = new UsernamePasswordAuthenticationToken(authUser, null, authUser.getAuthorities());78 }79 } else if (isSessionRequest(request)) {80 log.info("Identifying sessions request.");81 auth = new UsernamePasswordAuthenticationToken(null, null, null);82 }83 if ((jwtCookie == null) && (AuthenticationType.NO_AUTH == authenticationConfig.getAuthenticationType())) {84 log.info("Identified authentication config to be NO_AUTH and cookie is absent. Setting JWT Cookie");85 AuthUser authUser = new AuthUser();86 authUser.setUuid(UUID.randomUUID().toString());87 auth = new UsernamePasswordAuthenticationToken(authUser, null, authUser.getAuthorities());88 response.setStatus(HttpServletResponse.SC_OK);89 response.setContentType("application/json;charset=UTF-8");90 response.setHeader("Cache-Control", "no-cache");91 String token = JWTTokenService.generateAuthToken(authUser);92 Cookie cookie = new Cookie(JWTTokenService.JWT_COOKIE_NAME, token);93 cookie.setSecure(this.secure);94 cookie.setHttpOnly(this.httpOnly);95 cookie.setPath("/");96 response.addCookie(cookie);97 }98 if (auth == null && !isSessionRequest(request)) {99 throw new BadCredentialsException("AUTH TOKEN MISSING");100 }101 if ((auth != null)) {102 AuthUser authUser = (AuthUser) auth.getPrincipal();103 if (authUser != null) {104 CurrentUserService.setCurrentUser(authUser);105 setPreferencesEntries(authUser);106 }107 }108 return auth;109 }110 private void setPreferencesEntries(AuthUser authUser) throws IOException {111 if (AuthenticationType.NO_AUTH != authenticationConfig.getAuthenticationType()) {112 try {113 userPreferenceService.insertDefaultUserPreferences(authUser);114 } catch (Exception e) {115 log.error(e.getMessage(), e);116 throw new IOException(e.getMessage(), e);117 }118 }119 }120 @Override121 protected boolean requiresAuthentication(HttpServletRequest request, HttpServletResponse response) {122 return super.requiresAuthentication(request, response) && !isLoginRequest(request)123 && !isAPIRequest(request) && !isAgentAPIRequest(request)124 && !isOAuth2LoginRequest(request) && !isAgentCertificateRequest(request)125 && !isPresignedStorageRequest(request) && !isAuthConfigRequest(request) && !isServerRequest(request) &&126 !isOnboardingRequest(request) && !isLocalAgentRequest(request);127 }128 private boolean isOnboardingRequest(HttpServletRequest request) {129 return onboardingMatcher.matches(request);130 }131 private boolean isLocalAgentRequest(HttpServletRequest request) {132 return localAgentMatcher.matches(request);133 }134 private boolean isPresignedStorageRequest(HttpServletRequest request) {135 return presignedStorageRequestMatcher.matches(request);136 }137 private boolean isSessionRequest(HttpServletRequest request) {138 return sessionRequestMatcher.matches(request);139 }140 private boolean isLoginRequest(HttpServletRequest request) {141 return loginRequestMatcher.matches(request);142 }143 private boolean isAPIRequest(HttpServletRequest request) {144 return apiRequestMatcher.matches(request);145 }146 private boolean isAgentAPIRequest(HttpServletRequest request) {147 return agentApiRequestMatcher.matches(request);148 }149 private boolean isOAuth2LoginRequest(HttpServletRequest request) {150 return oauthRequestMatcher.matches(request);151 }...
isSessionRequest
Using AI Code Generation
1import java.util.regex.Matcher;2import java.util.regex.Pattern;3import javax.servlet.http.HttpServletRequest;4public class JWTAuthenticationFilter {5public boolean isSessionRequest(HttpServletRequest request) {6String url = request.getRequestURI();7Pattern pattern = Pattern.compile("/session");8Matcher matcher = pattern.matcher(url);9return matcher.find();10}11}12import org.springframework.beans.factory.annotation.Autowired;13import org.springframework.security.core.Authentication;14import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;15import org.springframework.stereotype.Component;16import org.springframework.web.context.request.RequestContextHolder;17import org.springframework.web.context.request.ServletRequestAttributes;18import com.testsigma.security.JWTAuthenticationFilter;19import com.testsigma.service.SessionService;20import com.testsigma.service.UserService;21import java.io.IOException;22import javax.servlet.ServletException;23import javax.servlet.http.HttpServletRequest;24import javax.servlet.http.HttpServletResponse;25public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler {26private UserService userService;27private SessionService sessionService;28private JWTAuthenticationFilter jwtAuthenticationFilter;29public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)30throws IOException, ServletException {31if(authentication != null && authentication.getDetails() != null) {32try {33request.getSession().invalidate();34String token = request.getHeader("Authorization").split(" ")[1];35if(!jwtAuthenticationFilter.isSessionRequest(request)) {36sessionService.deleteSessionByToken(token);37}38} catch (Exception e) {39e.printStackTrace();40}41}42response.setStatus(HttpServletResponse.SC_OK);43response.sendRedirect(request.getContextPath() + "/login");44}45}46import org.springframework.beans.factory.annotation.Autowired;47import org.springframework.context.annotation.Bean;48import org.springframework.context.annotation.Configuration;49import org.springframework.security.authentication.AuthenticationManager;50import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;51import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;52import org.springframework.security.config.annotation.web.builders.HttpSecurity;53import org.springframework.security.config.annotation.web.builders.WebSecurity;54import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;55import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
isSessionRequest
Using AI Code Generation
1if (request.getRequestURI().contains("/session") && com.testsigma.security.JWTAuthenticationFilter.isSessionRequest(request)) {2 return true;3}4if (request.getRequestURI().contains("/token") && com.testsigma.security.JWTAuthenticationFilter.isTokenRequest(request)) {5 return true;6}7if (request.getRequestURI().contains("/token") && com.testsigma.security.JWTAuthenticationFilter.isTokenRequest(request)) {8 return true;9}10if (request.getRequestURI().contains("/token") && com.testsigma.security.JWTAuthenticationFilter.isTokenRequest(request)) {11 return true;12}13if (request.getRequestURI().contains("/token") && com.testsigma.security.JWTAuthenticationFilter.isTokenRequest(request)) {14 return true;15}16if (request.getRequestURI
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!