Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KEYCLOAK-1187 First round: Combined ApplicationModel and OAuthClientM…
…odel into ClientModel. Removed OAuth Clients from Admin console and renamed Applications to Clients.
- Loading branch information
Showing
196 changed files
with
6,069 additions
and
9,521 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
...g/keycloak/connections/jpa/updater/liquibase/custom/SetConsentRequiredOnOAuthClients.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,84 @@ | |||
package org.keycloak.connections.jpa.updater.liquibase.custom; | |||
|
|||
import liquibase.change.custom.CustomSqlChange; | |||
import liquibase.database.Database; | |||
import liquibase.database.jvm.JdbcConnection; | |||
import liquibase.exception.CustomChangeException; | |||
import liquibase.exception.SetupException; | |||
import liquibase.exception.ValidationErrors; | |||
import liquibase.resource.ResourceAccessor; | |||
import liquibase.snapshot.SnapshotGeneratorFactory; | |||
import liquibase.statement.SqlStatement; | |||
import liquibase.statement.core.UpdateStatement; | |||
import liquibase.structure.core.Table; | |||
import org.keycloak.models.utils.KeycloakModelUtils; | |||
|
|||
import java.sql.Connection; | |||
import java.sql.ResultSet; | |||
import java.util.ArrayList; | |||
|
|||
/** | |||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a> | |||
*/ | |||
public class SetConsentRequiredOnOAuthClients implements CustomSqlChange { | |||
|
|||
private String confirmationMessage; | |||
|
|||
@Override | |||
public SqlStatement[] generateStatements(Database database) throws CustomChangeException { | |||
try { | |||
StringBuilder sb = new StringBuilder(); | |||
sb.append("Set consent required for: "); | |||
|
|||
Connection connection = ((JdbcConnection) (database.getConnection())).getWrappedConnection(); | |||
ArrayList<SqlStatement> statements = new ArrayList<SqlStatement>(); | |||
|
|||
String correctedTableName = database.correctObjectName("CLIENT", Table.class); | |||
if (SnapshotGeneratorFactory.getInstance().has(new Table().setName(correctedTableName), database)) { | |||
ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM CLIENT"); | |||
while (resultSet.next()) { | |||
String id = resultSet.getString(1); | |||
|
|||
UpdateStatement statement = new UpdateStatement(null, null, correctedTableName) | |||
.addNewColumnValue("CONSENT_REQUIRED", true) | |||
.setWhereClause("ID='" + id + "'"); | |||
statements.add(statement); | |||
|
|||
if (!resultSet.isFirst()) { | |||
sb.append(", "); | |||
} | |||
sb.append(id); | |||
} | |||
|
|||
if (!statements.isEmpty()) { | |||
confirmationMessage = sb.toString(); | |||
} | |||
} | |||
|
|||
return statements.toArray(new SqlStatement[statements.size()]); | |||
} catch (Exception e) { | |||
throw new CustomChangeException("Failed to add realm code secret", e); | |||
} | |||
} | |||
|
|||
@Override | |||
public String getConfirmationMessage() { | |||
return confirmationMessage; | |||
} | |||
|
|||
@Override | |||
public void setUp() throws SetupException { | |||
|
|||
} | |||
|
|||
@Override | |||
public void setFileOpener(ResourceAccessor resourceAccessor) { | |||
|
|||
} | |||
|
|||
@Override | |||
public ValidationErrors validate(Database database) { | |||
return null; | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.