All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.cloudfoundry.identity.uaa.db.BootstrapIdentityZones Maven / Gradle / Ivy
package org.cloudfoundry.identity.uaa.db;
import org.cloudfoundry.identity.uaa.constants.OriginKeys;
import org.cloudfoundry.identity.uaa.zone.IdentityZone;
import org.flywaydb.core.api.migration.spring.SpringJdbcMigration;
import org.springframework.jdbc.core.JdbcTemplate;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public class BootstrapIdentityZones implements SpringJdbcMigration {
@Override
public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
IdentityZone uaa = IdentityZone.getUaa();
Timestamp t = new Timestamp(uaa.getCreated().getTime());
jdbcTemplate.update("insert into identity_zone VALUES (?,?,?,?,?,?,?)", uaa.getId(),t,t,uaa.getVersion(),uaa.getSubdomain(),uaa.getName(),uaa.getDescription());
Map originMap = new HashMap();
Set origins = new LinkedHashSet();
origins.addAll(Arrays.asList(new String[] {OriginKeys.UAA, OriginKeys.LOGIN_SERVER, OriginKeys.LDAP, OriginKeys.KEYSTONE}));
origins.addAll(jdbcTemplate.queryForList("SELECT DISTINCT origin from users", String.class));
for (String origin : origins) {
String identityProviderId = UUID.randomUUID().toString();
originMap.put(origin, identityProviderId);
jdbcTemplate.update("insert into identity_provider VALUES (?,?,?,0,?,?,?,?,null)",identityProviderId, t, t, uaa.getId(),origin,origin,origin);
}
jdbcTemplate.update("update oauth_client_details set identity_zone_id = ?",uaa.getId());
List clientIds = jdbcTemplate.queryForList("SELECT client_id from oauth_client_details", String.class);
for (String clientId : clientIds) {
jdbcTemplate.update("insert into client_idp values (?,?) ",clientId,originMap.get(OriginKeys.UAA));
}
jdbcTemplate.update("update users set identity_provider_id = (select id from identity_provider where identity_provider.origin_key = users.origin), identity_zone_id = (select identity_zone_id from identity_provider where identity_provider.origin_key = users.origin);");
jdbcTemplate.update("update group_membership set identity_provider_id = (select id from identity_provider where identity_provider.origin_key = group_membership.origin);");
}
}