67 String identityProviderTableName =
database.correctObjectName(
"IDENTITY_PROVIDER", Table.class);
68 String idpConfigTableName =
database.correctObjectName(
"IDENTITY_PROVIDER_CONFIG", Table.class);
70 String realmSocialConfigTable =
getTableName(
"REALM_SOCIAL_CONFIG");
72 PreparedStatement statement =
jdbcConnection.prepareStatement(
"select RSC.NAME, VALUE, REALM_ID, UPDATE_PROFILE_ON_SOC_LOGIN from " + realmSocialConfigTable +
" RSC," + realmTableName +
73 " REALM where RSC.REALM_ID = REALM.ID ORDER BY RSC.REALM_ID, RSC.NAME");
75 ResultSet resultSet = statement.executeQuery();
77 boolean providerInProgress =
false;
78 String socialProviderId = null;
79 String clientId = null;
81 String realmId = null;
82 boolean updateProfileOnSocialLogin =
false;
85 while (resultSet.next()) {
91 if (!providerInProgress) {
92 String key = resultSet.getString(
"NAME");
93 int keyIndex = key.indexOf(
".key");
95 throw new IllegalStateException(
"Can't parse the provider from column: " + key);
98 socialProviderId = key.substring(0, keyIndex);
99 clientId = resultSet.getString(
"VALUE");
100 realmId = resultSet.getString(
"REALM_ID");
101 updateProfileOnSocialLogin = resultSet.getBoolean(
"UPDATE_PROFILE_ON_SOC_LOGIN");
102 providerInProgress =
true;
104 clientSecret = resultSet.getString(
"VALUE");
106 String internalId = KeycloakModelUtils.generateId();
107 InsertStatement idpInsert =
new InsertStatement(null, null, identityProviderTableName)
108 .addColumnValue(
"INTERNAL_ID", internalId)
109 .addColumnValue(
"ENABLED",
true)
110 .addColumnValue(
"PROVIDER_ALIAS", socialProviderId)
111 .addColumnValue(
"PROVIDER_ID", socialProviderId)
112 .addColumnValue(
"UPDATE_PROFILE_FIRST_LOGIN", updateProfileOnSocialLogin)
113 .addColumnValue(
"STORE_TOKEN",
false)
114 .addColumnValue(
"AUTHENTICATE_BY_DEFAULT",
false)
115 .addColumnValue(
"REALM_ID", realmId);
116 InsertStatement clientIdInsert =
new InsertStatement(null, null, idpConfigTableName)
117 .addColumnValue(
"IDENTITY_PROVIDER_ID", internalId)
118 .addColumnValue(
"NAME",
"clientId")
119 .addColumnValue(
"VALUE", clientId);
120 InsertStatement clientSecretInsert =
new InsertStatement(null, null, idpConfigTableName)
121 .addColumnValue(
"IDENTITY_PROVIDER_ID", internalId)
122 .addColumnValue(
"NAME",
"clientSecret")
123 .addColumnValue(
"VALUE", clientSecret);
130 providerInProgress =
false;
JdbcConnection jdbcConnection
Definition: CustomKeycloakTask.java:52
String getTableName(String tableName)
Definition: CustomKeycloakTask.java:132
List< SqlStatement > statements
Definition: CustomKeycloakTask.java:55
String realmTableName
Definition: JpaUpdate1_2_0_Beta1.java:43
Database database
Definition: CustomKeycloakTask.java:51
StringBuilder confirmationMessage
Definition: CustomKeycloakTask.java:54