File tree Expand file tree Collapse file tree
spring-security-modules/spring-security-web-rest-basic-auth
src/main/java/com/baeldung/postman/basic Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ {
2+ "variables": [],
3+ "info": {
4+ "name": "Baeldung - Basic Auth",
5+ "_postman_id": "a1e733bc-15ca-3c5d-7fdb-d119518ed3eb",
6+ "description": "",
7+ "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
8+ },
9+ "item": [
10+ {
11+ "name": "using authorization tab",
12+ "request": {
13+ "url": "http://localhost:8080/postman-test",
14+ "method": "GET",
15+ "header": [
16+ {
17+ "key": "admin",
18+ "value": "baeldung",
19+ "description": "",
20+ "disabled": true
21+ },
22+ {
23+ "key": "Authorization",
24+ "value": "Basic YWRtaW46YmFlbGR1bmc=",
25+ "description": ""
26+ }
27+ ],
28+ "body": {},
29+ "description": ""
30+ },
31+ "response": []
32+ },
33+ {
34+ "name": "using header tab",
35+ "request": {
36+ "url": "http://localhost:8080/postman-test",
37+ "method": "GET",
38+ "header": [
39+ {
40+ "key": "Authorization",
41+ "value": "Basic YWRtaW46YmFlbGR1bmc=",
42+ "description": ""
43+ }
44+ ],
45+ "body": {},
46+ "description": ""
47+ },
48+ "response": []
49+ },
50+ {
51+ "name": "using interceptor",
52+ "request": {
53+ "url": "http://localhost:8080/postman-test",
54+ "method": "GET",
55+ "header": [],
56+ "body": {},
57+ "description": ""
58+ },
59+ "response": []
60+ }
61+ ]
62+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .postman .basic ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+
6+ @ SpringBootApplication
7+ public class PostmanBasicAuthApplication {
8+
9+ public static void main (String [] args ) {
10+ SpringApplication .run (PostmanBasicAuthApplication .class , args );
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .postman .basic ;
2+
3+ import org .springframework .beans .factory .annotation .Autowired ;
4+ import org .springframework .context .annotation .Configuration ;
5+ import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
6+ import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
7+ import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
8+
9+ @ Configuration
10+ public class PostmanBasicAuthConfig extends WebSecurityConfigurerAdapter {
11+
12+ @ Override
13+ protected void configure (HttpSecurity http ) throws Exception {
14+ http .csrf ()
15+ .disable ()
16+ .authorizeRequests ()
17+ .anyRequest ()
18+ .authenticated ()
19+ .and ()
20+ .httpBasic ();
21+ }
22+
23+ @ Autowired
24+ public void configureGlobal (AuthenticationManagerBuilder auth ) throws Exception {
25+ auth .inMemoryAuthentication ()
26+ .withUser ("admin" )
27+ .password ("{noop}baeldung2" )
28+ .roles ("USER" );
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .postman .basic ;
2+
3+ import org .springframework .web .bind .annotation .GetMapping ;
4+ import org .springframework .web .bind .annotation .RestController ;
5+
6+ @ RestController
7+ public class PostmanBasicAuthController {
8+
9+ @ GetMapping ("postman-test" )
10+ public String test () {
11+ return "request was authorized!" ;
12+ }
13+
14+ }
You can’t perform that action at this time.
0 commit comments