File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed
src/main/java/com/reuben/store Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 1
1
package com .reuben .store .config ;
2
2
3
3
import com .reuben .store .model .Customer ;
4
+ import com .reuben .store .repository .CustomerRepository ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .security .core .userdetails .User ;
4
7
import org .springframework .security .core .userdetails .UserDetails ;
5
8
import org .springframework .security .core .userdetails .UserDetailsService ;
6
9
import org .springframework .security .core .userdetails .UsernameNotFoundException ;
9
12
@ Service
10
13
public class AuthService implements UserDetailsService {
11
14
15
+ @ Autowired
16
+ private CustomerRepository customerRepository ;
17
+
12
18
@ Override
13
19
public UserDetails loadUserByUsername (String username ) throws UsernameNotFoundException {
14
- System .out .println (username );
15
- return null ;
20
+ Customer customer = customerRepository .fetchCustomerByEmail (username );
21
+ if (customer == null ) {
22
+ throw new UsernameNotFoundException ("Invalid Email ID" );
23
+ }
24
+ return new org .springframework .security .core .userdetails .User (customer .getEmail_id (), customer .getPassword (),customer .getAuthorities ());
16
25
}
17
26
}
Original file line number Diff line number Diff line change @@ -46,11 +46,12 @@ private AuthenticationProvider authenticationProvider() {
46
46
@ Override
47
47
protected void configure (HttpSecurity http ) throws Exception {
48
48
http .authorizeRequests ()
49
+ .antMatchers ("/**" ).permitAll ()
49
50
.antMatchers ("/customer" ).permitAll ()
50
51
.antMatchers ("/vendor" ).permitAll ()
52
+ .antMatchers ("/customer/{customer_id}" ).authenticated ()
51
53
52
- .antMatchers ("/api/private/user/test" ).authenticated ()
53
- .antMatchers ("/api/private/admin/test" ).hasAuthority ("ADMIN" )// hasAnyAuthority("ADMIN","USER")
54
+ .antMatchers ("/product/purchase/{vendor_id}" ).hasAuthority ("ADMIN" )// hasAnyAuthority("ADMIN","USER")
54
55
.and ()
55
56
.httpBasic ();
56
57
http .csrf ().disable ();
Original file line number Diff line number Diff line change 1
1
package com .reuben .store .model ;
2
2
3
3
import org .springframework .security .core .GrantedAuthority ;
4
+ import org .springframework .security .core .authority .SimpleGrantedAuthority ;
4
5
import org .springframework .security .core .userdetails .UserDetails ;
5
6
6
7
import javax .persistence .*;
8
+ import java .util .ArrayList ;
7
9
import java .util .Collection ;
8
10
import java .util .List ;
9
11
@@ -68,7 +70,10 @@ public void setPassword(String password) {
68
70
69
71
@ Override
70
72
public Collection <? extends GrantedAuthority > getAuthorities () {
71
- return null ;
73
+ List <GrantedAuthority > list = new ArrayList <>();
74
+ SimpleGrantedAuthority sga = new SimpleGrantedAuthority (role );
75
+ list .add (sga );
76
+ return list ;
72
77
}
73
78
74
79
You can’t perform that action at this time.
0 commit comments