29
29
*/
30
30
public abstract class AuthProviderConfig {
31
31
32
- @ Key ( "name" )
32
+ // Lazily initialized from 'resourceName'.
33
33
private String providerId ;
34
34
35
+ @ Key ("name" )
36
+ private String resourceName ;
37
+
35
38
@ Key ("displayName" )
36
39
private String displayName ;
37
40
38
41
@ Key ("enabled" )
39
42
private boolean enabled ;
40
43
44
+ // TODO(micahstairs): Add unit test for this.
45
+ // Example: projects/388188666963/oauthIdpConfigs/oidc.config-id
41
46
public String getProviderId () {
47
+ if (providerId == null ) {
48
+ providerId = resourceName .substring (resourceName .lastIndexOf ("/" ) + 1 );
49
+ }
42
50
return providerId ;
43
51
}
44
52
@@ -56,45 +64,53 @@ public boolean isEnabled() {
56
64
* <p>Set the initial attributes of the new provider by calling various setter methods available
57
65
* in this class.
58
66
*/
59
- public abstract static class CreateRequest {
67
+ public abstract static class CreateRequest < T extends CreateRequest < T >> {
60
68
61
69
final Map <String ,Object > properties = new HashMap <>();
70
+ String providerId ;
62
71
63
72
/**
64
- * Sets the ID for the new provider.
73
+ * Sets the display name for the new provider.
65
74
*
66
75
* @param providerId a non-null, non-empty provider ID string.
67
76
*/
68
- public CreateRequest setProviderId (String providerId ) {
77
+ public T setProviderId (String providerId ) {
69
78
checkArgument (
70
79
!Strings .isNullOrEmpty (providerId ), "provider ID name must not be null or empty" );
71
- properties .put ("name" , providerId );
72
- return this ;
80
+ this .providerId = providerId ;
81
+ return getThis ();
82
+ }
83
+
84
+ // TODO(micahstairs): Add a unit test for this method.
85
+ String getProviderId () {
86
+ return providerId ;
73
87
}
74
88
75
89
/**
76
90
* Sets the display name for the new provider.
77
91
*
78
92
* @param displayName a non-null, non-empty display name string.
79
93
*/
80
- public CreateRequest setDisplayName (String displayName ) {
94
+ public T setDisplayName (String displayName ) {
81
95
checkArgument (!Strings .isNullOrEmpty (displayName ), "display name must not be null or empty" );
82
96
properties .put ("displayName" , displayName );
83
- return this ;
97
+ return getThis () ;
84
98
}
85
99
86
100
/**
87
- * Sets whether to allow the user to sign in with the provider..
101
+ * Sets whether to allow the user to sign in with the provider.
88
102
*
89
103
* @param enabled a boolean indicating whether the user can sign in with the provider
90
104
*/
91
- public CreateRequest setEnabled (boolean enabled ) {
105
+ public T setEnabled (boolean enabled ) {
92
106
properties .put ("enabled" , enabled );
93
- return this ;
107
+ return getThis () ;
94
108
}
95
109
96
110
Map <String , Object > getProperties () {
97
111
return ImmutableMap .copyOf (properties );
98
112
}
113
+
114
+ abstract T getThis ();
99
115
}
100
116
}
0 commit comments