Skip to content

Commit 2091ee7

Browse files
authored
updated how we update idps (#161)
Signed-off-by: Garth <244253+xgp@users.noreply.github.com>
1 parent 716e65c commit 2091ee7

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/java/io/phasetwo/service/resource/IdentityProvidersResource.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import lombok.extern.jbosslog.JBossLog;
1919
import org.keycloak.models.IdentityProviderModel;
2020
import org.keycloak.models.utils.ModelToRepresentation;
21+
import org.keycloak.models.utils.RepresentationToModel;
2122
import org.keycloak.models.utils.StripSecretsUtils;
2223
import org.keycloak.representations.idm.ComponentRepresentation;
2324
import org.keycloak.representations.idm.IdentityProviderRepresentation;
@@ -119,10 +120,10 @@ public Response createIdentityProvider(IdentityProviderRepresentation representa
119120
}
120121

121122
idpDefaults(representation, Optional.empty());
122-
deactivateOtherIdps(representation);
123123

124124
Response resp = getIdpResource().create(representation);
125125
if (resp.getStatus() == Response.Status.CREATED.getStatusCode()) {
126+
deactivateOtherIdps(representation);
126127
return createdResponse(representation);
127128
} else {
128129
return resp;
@@ -164,13 +165,15 @@ public Response linkIdp(LinkIdp linkIdp) {
164165
if (!Strings.isNullOrEmpty(linkIdp.getPostBrokerFlow())) {
165166
representation.setPostBrokerLoginFlowAlias(linkIdp.getPostBrokerFlow());
166167
}
167-
deactivateOtherIdps(representation);
168168

169-
Response resp = getIdpResource().getIdentityProvider(linkIdp.getAlias()).update(representation);
170-
if (resp.getStatus() == Response.Status.NO_CONTENT.getStatusCode()) {
169+
try {
170+
IdentityProviderModel updated = RepresentationToModel.toModel(realm, representation, session);
171+
realm.updateIdentityProvider(updated);
172+
deactivateOtherIdps(representation);
171173
return createdResponse(representation);
172-
} else {
173-
return resp;
174+
} catch (Exception e) {
175+
throw new InternalServerErrorException(
176+
String.format("Error updating IdP %s", representation.getAlias()), e);
174177
}
175178
}
176179

0 commit comments

Comments
 (0)