Best Testsigma code snippet using com.testsigma.config.WebSecurityConfig.clientRegistrationRepository
Source: WebSecurityConfig.java
...105 public AuthorizationRequestRepository<OAuth2AuthorizationRequest> cookieAuthorizationRequestRepository() {106 return new com.testsigma.security.HttpCookieOAuth2AuthorizationRequestRepository();107 }108 @Bean109 public ClientRegistrationRepository clientRegistrationRepository() {110 return new InMemoryClientRegistrationRepository(this.googleClientRegistration());111 }112 private ClientRegistration googleClientRegistration() {113 String googleClientId = StringUtils.defaultIfEmpty(additionalPropertiesConfig.getGoogleClientId(),114 authenticationConfigProperties.getGoogleOAuthClientID());115 String googleClientSecret = StringUtils.defaultIfEmpty(additionalPropertiesConfig.getGoogleClientSecret(),116 authenticationConfigProperties.getGoogleOAuthClientSecret());117 return CommonOAuth2Provider.GOOGLE.getBuilder("google")118 .clientId(googleClientId)119 .clientSecret(googleClientSecret)120 .build();121 }122 @Override123 public void configure(WebSecurity web) {124 web.ignoring()125 .antMatchers(HttpMethod.GET, URLConstants.SESSION_RESOURCE_URL)126 .antMatchers((URLConstants.AGENT_CERTIFICATE_URL + URLConstants.ALL_SUB_URLS))127 .antMatchers(URLConstants.ASSETS_URL)128 .antMatchers("/servers")129 .antMatchers("/auth_config")130 .antMatchers("/onboarding/**")131 .antMatchers("/local/agents/**");132 }133 @Override134 protected void configure(HttpSecurity http) throws Exception {135 configureOauth2LoginHandlers(136 configureFilters(137 configureLoginHandlers(138 configureLogoutHandlers(139 configureExceptionHandling(140 configureUrlAuthorizations(141 configureCsrf(142 configureCors(143 basicConfig(http)144 )145 )146 )147 )148 )149 )150 )151 );152 }153 private HttpSecurity basicConfig(HttpSecurity http) throws Exception {154 return http.headers().frameOptions().disable().and()155 .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and();156 }157 private HttpSecurity configureCors(HttpSecurity http) throws Exception {158 return http.cors().and();159 }160 private HttpSecurity configureCsrf(HttpSecurity http) throws Exception {161 return http.csrf().disable();162 }163 private HttpSecurity configureUrlAuthorizations(HttpSecurity http) throws Exception {164 return http.authorizeRequests().antMatchers(URLConstants.ASSETS_URL).permitAll()165 .antMatchers(URLConstants.AGENT_CERTIFICATE_URL + URLConstants.ALL_SUB_URLS).permitAll()166 .antMatchers(HttpMethod.POST, URLConstants.LOGIN_URL).permitAll()167 .antMatchers(HttpMethod.GET, URLConstants.SESSION_RESOURCE_URL).permitAll()168 .antMatchers(URLConstants.ALL_URLS).access("isFullyAuthenticated()")169 .antMatchers(URLConstants.ALL_URLS).authenticated().and();170 }171 private HttpSecurity configureExceptionHandling(HttpSecurity http) throws Exception {172 return http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint()).and();173 }174 private HttpSecurity configureLogoutHandlers(HttpSecurity http) throws Exception {175 return http.logout()176 .logoutRequestMatcher(new AntPathRequestMatcher(URLConstants.LOGOUT_URL, HttpMethod.GET.name()))177 .logoutSuccessHandler((new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)))178 .deleteCookies(JSESSIONID_COOKIE)179 .deleteCookies(JWTTokenService.JWT_COOKIE_NAME).invalidateHttpSession(true).and();180 }181 private HttpSecurity configureLoginHandlers(HttpSecurity http) throws Exception {182 return http.anonymous().disable().apply(ajaxLogin()).loginPage(URLConstants.LOGIN_URL)183 .successHandler(ajaxLoginSuccessHandler()).failureHandler(ajaxLoginFailureHandler()).and();184 }185 private HttpSecurity configureFilters(HttpSecurity http) throws Exception {186 return http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)187 .addFilterAfter(apiJwtAuthenticationFilter(), JWTAuthenticationFilter.class)188 .addFilterAfter(agentJwtAuthorizationFilter(), JWTAuthenticationFilter.class)189 .addFilterBefore(presignedJwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);190 }191 private HttpSecurity configureOauth2LoginHandlers(HttpSecurity http) throws Exception {192 return http.oauth2Login().redirectionEndpoint()193 .and().authorizationEndpoint()194 .authorizationRequestRepository(cookieAuthorizationRequestRepository()).and()195 .userInfoEndpoint()196 .oidcUserService(authUserService).and()197 .clientRegistrationRepository(clientRegistrationRepository())198 .successHandler(ajaxLoginSuccessHandler())199 .failureHandler(ajaxLoginFailureHandler()).and();200 }201}...
clientRegistrationRepository
Using AI Code Generation
1 public ClientRegistrationRepository clientRegistrationRepository() {2 return new InMemoryClientRegistrationRepository(this.googleClientRegistration());3 }4 private ClientRegistration googleClientRegistration() {5 return CommonOAuth2Provider.GOOGLE.getBuilder("google")6 .clientId("google-client-id")7 .clientSecret("google-client-secret")8 .build();9 }10}11src/main/java/com/testsigma/config/CustomOAuth2UserService.java package com.testsigma.config; import java.util.Collections; import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest; import org.springframework.security.oauth2.client.userinfo.OAuth2UserService; import org.springframework.security.oauth2.core.OAuth2AuthenticationException; import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.security.oauth2.core.user.OAuth2UserAuthority; import org.springframework.stereotype.Service; import com.testsigma.model.User; import com.testsigma.repository.UserRepository; @Service public class CustomOAuth2UserService implements OAuth2UserService<OAuth2UserRequest, OAuth2User> { @Autowired private UserRepository userRepository; @Override public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException { OAuth2UserService delegate = new DefaultOAuth2UserService(); OAuth2User oAuth2User = delegate.loadUser(userRequest); String registrationId = userRequest.getClientRegistration().getRegistrationId(); String userNameAttributeName = userRequest.getClientRegistration().getProviderDetails().getUserInfoEndpoint().getUserNameAttributeName(); OAuthAttributes attributes = OAuthAttributes.of(registrationId, userNameAttributeName, oAuth2User.getAttributes()); User user = saveOrUpdate(attributes); return UserPrincipal.create(user, oAuth2User.getAttributes()); } private User saveOrUpdate(OAuthAttributes attributes) { User user = userRepository.findByEmail(attributes.getEmail()).map(entity -> entity.update(attributes.getName(), attributes.getPicture()))
clientRegistrationRepository
Using AI Code Generation
1import org.springframework.beans.factory.annotation.Autowired;2import org.springframework.context.annotation.Configuration;3import org.springframework.security.config.annotation.web.builders.HttpSecurity;4import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;5import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;6import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;7import org.springframework.security.oauth2.client.web.AuthorizationRequestRepository;8import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;9public class WebSecurityConfig extends WebSecurityConfigurerAdapter {10 private ClientRegistrationRepository clientRegistrationRepository;11 private AuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository;12 protected void configure(HttpSecurity http) throws Exception {13 .authorizeRequests()14 .antMatchers("/login**", "/error**").permitAll()15 .anyRequest().authenticated()16 .and()17 .oauth2Login()18 .loginPage("/login")19 .authorizationEndpoint()20 .baseUri("/oauth2/authorize-client")21 .authorizationRequestRepository(authorizationRequestRepository)22 .and()23 .redirectionEndpoint()24 .baseUri("/login/oauth2/code/*")25 .and()26 .userInfoEndpoint()27 .userService(customOAuth2UserService)28 .and()29 .successHandler(oAuth2AuthenticationSuccessHandler)30 .failureHandler(oAuth2AuthenticationFailureHandler)31 .and()32 .logout()33 .logoutUrl("/logout")34 .logoutSuccessHandler(oidcLogoutSuccessHandler)35 .deleteCookies("JSESSIONID")36 .invalidateHttpSession(true);37 }38}39import org.springframework.context.annotation.Bean;40import org.springframework.context.annotation.Configuration;41import org.springframework.security.config.annotation.web.builders.HttpSecurity;42import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;43import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;44import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;45import org.springframework.security.oauth2.client.web.AuthorizationRequestRepository;46import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;47public class OAuth2LoginConfig extends WebSecurityConfigurerAdapter {48 private ClientRegistrationRepository clientRegistrationRepository;
clientRegistrationRepository
Using AI Code Generation
1 private ClientRegistrationRepository clientRegistrationRepository;2 public ClientRegistrationRepository clientRegistrationRepository() {3 return new InMemoryClientRegistrationRepository(this.clientRegistrationRepository.findByRegistrationId("github"));4 }5 public OAuth2AuthorizedClientService authorizedClientService() {6 return new InMemoryOAuth2AuthorizedClientService(clientRegistrationRepository());7 }8 protected void configure(HttpSecurity http) throws Exception {9 .authorizeRequests(a -> a10 .antMatchers("/", "/error", "/webjars/**").permitAll()11 .anyRequest().authenticated()12 .exceptionHandling(e -> e13 .authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))14 .logout(l -> l15 .logoutSuccessUrl("/").permitAll()16 .oauth2Login()17 .and()18 .csrf().disable();19 }20}
clientRegistrationRepository
Using AI Code Generation
1package com.testsigma.config;2import org.springframework.beans.factory.annotation.Autowired;3import org.springframework.security.oauth2.client.registration.ClientRegistration;4import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;5import org.springframework.stereotype.Component;6public class RegistrationDetails {7 private ClientRegistrationRepository clientRegistrationRepository;8 public ClientRegistration getClientRegistration(String clientRegistrationId) {9 return clientRegistrationRepository.findByRegistrationId(clientRegistrationId);10 }11}12package com.testsigma.config;13import org.springframework.beans.factory.annotation.Autowired;14import org.springframework.context.annotation.Bean;15import org.springframework.context.annotation.Configuration;16import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;17public class WebSecurityConfig {18 private ClientRegistrationRepository clientRegistrationRepository;19 public ClientRegistrationRepository clientRegistrationRepository() {20 return clientRegistrationRepository;21 }22}23package com.testsigma.config;24import org.springframework.beans.factory.annotation.Autowired;25import org.springframework.context.annotation.Bean;26import org.springframework.context.annotation.Configuration;27import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;28public class WebSecurityConfig {29 private ClientRegistrationRepository clientRegistrationRepository;30 public ClientRegistrationRepository clientRegistrationRepository() {31 return clientRegistrationRepository;32 }33}34package com.testsigma.controller;35import java.util.List;36import org.springframework.beans.factory.annotation.Autowired;37import org.springframework.security.oauth2.client.registration.ClientRegistration;38import org.springframework.web.bind.annotation.RequestMapping;39import org.springframework.web.bind.annotation.RestController;40import com.testsigma.config.RegistrationDetails;41public class ClientRegistrationController {42 private RegistrationDetails registrationDetails;43 @RequestMapping("/clients")
Check out the latest blogs from LambdaTest on this topic:
The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.
The QA testing profession requires both educational and long-term or experience-based learning. One can learn the basics from certification courses and exams, boot camp courses, and college-level courses where available. However, developing instinctive and practical skills works best when built with work experience.
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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!!