16
16
******************************************************************************/
17
17
package org .mitre .oauth2 .service .impl ;
18
18
19
+ import java .math .BigInteger ;
20
+ import java .security .SecureRandom ;
19
21
import java .util .ArrayList ;
20
22
import java .util .Collection ;
21
23
24
+ import org .mitre .oauth2 .model .ClientDetailsEntity ;
25
+ import org .mitre .oauth2 .model .ClientDetailsEntity .AuthMethod ;
26
+ import org .mitre .oauth2 .service .ClientDetailsEntityService ;
22
27
import org .springframework .beans .factory .annotation .Autowired ;
23
28
import org .springframework .security .core .GrantedAuthority ;
24
29
import org .springframework .security .core .authority .SimpleGrantedAuthority ;
25
30
import org .springframework .security .core .userdetails .User ;
26
31
import org .springframework .security .core .userdetails .UserDetails ;
27
32
import org .springframework .security .core .userdetails .UserDetailsService ;
28
33
import org .springframework .security .core .userdetails .UsernameNotFoundException ;
29
- import org .springframework .security .oauth2 .provider .ClientDetails ;
30
- import org .springframework .security .oauth2 .provider .ClientDetailsService ;
31
34
import org .springframework .stereotype .Service ;
32
35
33
36
import com .google .common .base .Strings ;
42
45
public class DefaultClientUserDetailsService implements UserDetailsService {
43
46
44
47
@ Autowired
45
- private ClientDetailsService clientDetailsService ;
48
+ private ClientDetailsEntityService clientDetailsService ;
46
49
47
50
@ Override
48
51
public UserDetails loadUserByUsername (String clientId ) throws UsernameNotFoundException {
49
52
50
- ClientDetails client = clientDetailsService .loadClientByClientId (clientId );
53
+ ClientDetailsEntity client = clientDetailsService .loadClientByClientId (clientId );
51
54
52
55
if (client != null ) {
53
56
54
57
String password = Strings .nullToEmpty (client .getClientSecret ());
58
+
59
+ if (client .getTokenEndpointAuthMethod () != null &&
60
+ (client .getTokenEndpointAuthMethod ().equals (AuthMethod .PRIVATE_KEY ) ||
61
+ client .getTokenEndpointAuthMethod ().equals (AuthMethod .SECRET_JWT ))) {
62
+
63
+ // Issue a random password each time to prevent password auth from being used (or skipped)
64
+ // for private key or shared key clients, see #715
65
+
66
+ password = new BigInteger (512 , new SecureRandom ()).toString (16 );
67
+ }
68
+
55
69
boolean enabled = true ;
56
70
boolean accountNonExpired = true ;
57
71
boolean credentialsNonExpired = true ;
@@ -72,11 +86,11 @@ public UserDetails loadUserByUsername(String clientId) throws UsernameNotFoundE
72
86
73
87
}
74
88
75
- public ClientDetailsService getClientDetailsService () {
89
+ public ClientDetailsEntityService getClientDetailsService () {
76
90
return clientDetailsService ;
77
91
}
78
92
79
- public void setClientDetailsService (ClientDetailsService clientDetailsService ) {
93
+ public void setClientDetailsService (ClientDetailsEntityService clientDetailsService ) {
80
94
this .clientDetailsService = clientDetailsService ;
81
95
}
82
96
0 commit comments