Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableWebSecurity
- public class SecurityConfig extends WebSecurityConfigurerAdapter {
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http
- .csrf().disable()
- .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
- .and()
- .addFilter(new JwtAuthorizationFilter(authenticationManager()))
- .authorizeRequests()
- .anyRequest().authenticated();
- }}
- @Override
- protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
- String header = request.getHeader("Authorization");
- if (header == null || !header.startsWith("Bearer")) {
- chain.doFilter(request, response);
- return;
- }
- Authentication authentication = getUsernamePasswordAuthentication(request);
- SecurityContextHolder.getContext().setAuthentication(authentication);
- // Continue filter execution
- chain.doFilter(request, response);
- }}
- let headers = new HttpHeaders();
- headers = headers.append('Authorization', 'Bearer '+tokenId);
- return this._http.post<any>(this._url,JSON.stringify(categorySubcategory),
- {
- headers, responseType: 'json'
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement