20
20
21
21
import org .apache .commons .lang .ArrayUtils ;
22
22
import org .apache .commons .lang .StringUtils ;
23
+ import org .wso2 .carbon .identity .api .server .common .ContextLoader ;
23
24
import org .wso2 .carbon .identity .api .server .idp .common .Constants ;
24
25
import org .wso2 .carbon .identity .api .server .idp .common .IdentityProviderServiceHolder ;
25
26
import org .wso2 .carbon .identity .api .server .idp .v1 .model .AuthenticationType ;
26
27
import org .wso2 .carbon .identity .api .server .idp .v1 .model .Endpoint ;
27
28
import org .wso2 .carbon .identity .api .server .idp .v1 .model .FederatedAuthenticator ;
29
+ import org .wso2 .carbon .identity .api .server .idp .v1 .model .FederatedAuthenticatorListItem ;
28
30
import org .wso2 .carbon .identity .api .server .idp .v1 .model .FederatedAuthenticatorPUTRequest ;
29
31
import org .wso2 .carbon .identity .application .common .ApplicationAuthenticatorService ;
30
32
import org .wso2 .carbon .identity .application .common .model .FederatedAuthenticatorConfig ;
38
40
import org .wso2 .carbon .idp .mgt .IdentityProviderManagementServerException ;
39
41
40
42
import java .nio .charset .StandardCharsets ;
43
+ import java .util .ArrayList ;
41
44
import java .util .Arrays ;
42
45
import java .util .Base64 ;
43
46
import java .util .List ;
47
50
import java .util .function .Function ;
48
51
import java .util .stream .Collectors ;
49
52
53
+ import static org .wso2 .carbon .identity .api .server .common .Constants .V1_API_PATH_COMPONENT ;
54
+ import static org .wso2 .carbon .identity .api .server .common .Util .base64URLEncode ;
50
55
import static org .wso2 .carbon .identity .api .server .idp .common .Constants .GOOGLE_PRIVATE_KEY ;
56
+ import static org .wso2 .carbon .identity .api .server .idp .common .Constants .IDP_PATH_COMPONENT ;
51
57
52
58
/**
53
59
* The factory class for building federated authenticator configuration related models.
@@ -118,17 +124,10 @@ public static FederatedAuthenticator build(FederatedAuthenticatorConfig config)
118
124
119
125
federatedAuthenticator .setName (config .getName ());
120
126
federatedAuthenticator .setIsEnabled (config .isEnabled ());
121
-
122
- FederatedAuthenticatorConfig federatedAuthenticatorConfig =
123
- ApplicationAuthenticatorService .getInstance ().getFederatedAuthenticatorByName (
124
- config .getName ());
125
- if (federatedAuthenticatorConfig != null ) {
126
- String [] tags = federatedAuthenticatorConfig .getTags ();
127
- if (ArrayUtils .isNotEmpty (tags )) {
128
- federatedAuthenticator .setTags (Arrays .asList (tags ));
129
- }
127
+ String [] tags = resolveAuthenticatorTags (config );
128
+ if (ArrayUtils .isNotEmpty (tags )) {
129
+ federatedAuthenticator .setTags (Arrays .asList (tags ));
130
130
}
131
-
132
131
if (DefinedByType .SYSTEM == config .getDefinedByType ()) {
133
132
federatedAuthenticator .setDefinedBy (FederatedAuthenticator .DefinedByEnum .SYSTEM );
134
133
List <org .wso2 .carbon .identity .api .server .idp .v1 .model .Property > properties =
@@ -141,6 +140,37 @@ public static FederatedAuthenticator build(FederatedAuthenticatorConfig config)
141
140
142
141
return federatedAuthenticator ;
143
142
}
143
+
144
+ /**
145
+ * Builds a list of FederatedAuthenticatorListItem instances based on the given array of
146
+ * FederatedAuthenticatorConfig.
147
+ *
148
+ * @param fedAuthConfigs Array of FederatedAuthenticatorConfig instances.
149
+ * @return List of FederatedAuthenticatorListItem instances.
150
+ */
151
+ public static List <FederatedAuthenticatorListItem > build (FederatedAuthenticatorConfig [] fedAuthConfigs ,
152
+ String idpResourceId ) {
153
+
154
+ List <FederatedAuthenticatorListItem > authenticators = new ArrayList <>();
155
+ for (FederatedAuthenticatorConfig config : fedAuthConfigs ) {
156
+ FederatedAuthenticatorListItem authenticatorListItem = new FederatedAuthenticatorListItem ();
157
+ authenticatorListItem .setAuthenticatorId (base64URLEncode (config .getName ()));
158
+ authenticatorListItem .setName (config .getName ());
159
+ authenticatorListItem .setIsEnabled (config .isEnabled ());
160
+ authenticatorListItem .definedBy (FederatedAuthenticatorListItem .DefinedByEnum .valueOf (
161
+ config .getDefinedByType ().toString ()));
162
+ String [] tags = resolveAuthenticatorTags (config );
163
+ if (ArrayUtils .isNotEmpty (tags )) {
164
+ authenticatorListItem .setTags (Arrays .asList (tags ));
165
+ }
166
+ authenticatorListItem .setSelf (ContextLoader .buildURIForBody (String .format (V1_API_PATH_COMPONENT +
167
+ IDP_PATH_COMPONENT + "/%s/federated-authenticators/%s" , idpResourceId ,
168
+ base64URLEncode (config .getName ()))).toString ());
169
+ authenticators .add (authenticatorListItem );
170
+ }
171
+
172
+ return authenticators ;
173
+ }
144
174
145
175
private static FederatedAuthenticatorConfig createFederatedAuthenticatorConfig (Config config )
146
176
throws IdentityProviderManagementClientException {
@@ -435,6 +465,23 @@ private static void resolveEndpointConfiguration(FederatedAuthenticator authenti
435
465
}
436
466
}
437
467
468
+ private static String [] resolveAuthenticatorTags (FederatedAuthenticatorConfig config ) {
469
+
470
+ /* If the authenticator is defined by the user, return the tags of the authenticator config. Otherwise, return
471
+ the tags of the system registered federated template.
472
+ */
473
+ if (DefinedByType .USER == config .getDefinedByType ()) {
474
+ return config .getTags ();
475
+
476
+ }
477
+ FederatedAuthenticatorConfig federatedAuthenticatorConfig =
478
+ ApplicationAuthenticatorService .getInstance ().getFederatedAuthenticatorByName (config .getName ());
479
+ if (federatedAuthenticatorConfig != null ) {
480
+ return federatedAuthenticatorConfig .getTags ();
481
+ }
482
+ return new String [0 ];
483
+ }
484
+
438
485
/**
439
486
* Config class to build FederatedAuthenticatorConfig.
440
487
*/
0 commit comments