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.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";
}
}
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";
}
}
No description
12 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @Danix! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Danix
DanixOP6mo ago
@dan1st | Daniel Can u please look on it
dan1st
dan1st6mo ago
Can you show your beans.xml?
Danix
DanixOP6mo ago
i didnot created any beans.xml i am now using spring boot .
dan1st
dan1st6mo ago
oh ok I didn't realize that Can you show your main class?
Danix
DanixOP6mo ago
yehh sure
package com.example.firstSpringBoot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FirstSpringBootApplication {

public static void main(String[] args) {
SpringApplication.run(FirstSpringBootApplication.class, args);
}

}
package com.example.firstSpringBoot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FirstSpringBootApplication {

public static void main(String[] args) {
SpringApplication.run(FirstSpringBootApplication.class, args);
}

}
dan1st
dan1st6mo ago
You called the package in your controller com.example.firstSpringBootcom.controllers
Danix
DanixOP6mo ago
yehh
dan1st
dan1st6mo ago
this is not a subpackage of com.example.firstSpringBoot com.example.firstSpringBoot.controllers would work or com.example.firstSpringBoot.com.controllers or something like that
Danix
DanixOP6mo ago
let me try ok now its accessible thanks For the help @dan1st | Daniel
JavaBot
JavaBot6mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot6mo ago
Post Closed
This post has been closed by <@1115219012759072928>.
Want results from more Discord servers?
Add your server