Java Community | Help. Code. Learn.JC|HCL
Java Community | Help. Code. Learn.โ€ข2y agoโ€ข
21 replies
Danix

Spring Security

I am Not Able to Access Any Of my Endpoints here is the Config File
package com.example.firstSpringBoot.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@Configuration
@EnableWebSecurity(debug = true)
public class MyConfig {

    @Bean
    InMemoryUserDetailsManager inMemoryUserDetailsManager() {
        List<GrantedAuthority> authorities = new ArrayList<>();
        authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
        authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
        
        UserDetails user = User.withUsername("Deepak")
                                .password("Deepak")
                                .authorities(authorities)
                                .build();
        
        return new InMemoryUserDetailsManager(user);
    }

    @Bean
    PasswordEncoder passwordEncoder() {
        return NoOpPasswordEncoder.getInstance();
    }
    
    @Bean
    SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        
        return http.build();
    }

  
}
package com.example.firstSpringBootcom.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Controllers {

    @ResponseBody
    @GetMapping("/hii")
    public String name() {
        return "name";
    }
}
Screenshot_175.png
Was this page helpful?