Search in sources :

Example 11 with Maps

use of org.apache.flink.shaded.guava30.com.google.common.collect.Maps in project cas by apereo.

the class WSFederationClaimsReleasePolicy method getAttributesInternal.

@Override
public Map<String, List<Object>> getAttributesInternal(final RegisteredServiceAttributeReleasePolicyContext context, final Map<String, List<Object>> attrs) {
    val resolvedAttributes = new TreeMap<String, List<Object>>(String.CASE_INSENSITIVE_ORDER);
    resolvedAttributes.putAll(attrs);
    val attributesToRelease = Maps.<String, List<Object>>newHashMapWithExpectedSize(resolvedAttributes.size());
    getAllowedAttributes().entrySet().stream().filter(entry -> WSFederationClaims.contains(entry.getKey().toUpperCase())).forEach(entry -> {
        val claimName = entry.getKey();
        val attributeValue = resolvedAttributes.get(entry.getValue());
        val claim = WSFederationClaims.valueOf(claimName.toUpperCase());
        if (resolvedAttributes.containsKey(claim.getUri())) {
            attributesToRelease.put(claim.getUri(), resolvedAttributes.get(claim.getUri()));
        } else {
            LOGGER.trace("Evaluating claim [{}] mapped to attribute value [{}]", claim.getUri(), attributeValue);
            mapSingleAttributeDefinition(claim.getUri(), entry.getValue(), attributeValue, resolvedAttributes, attributesToRelease);
        }
    });
    return attributesToRelease;
}
Also used : lombok.val(lombok.val) Setter(lombok.Setter) RegisteredServiceAttributeReleasePolicyContext(org.apereo.cas.services.RegisteredServiceAttributeReleasePolicyContext) Getter(lombok.Getter) lombok.val(lombok.val) EqualsAndHashCode(lombok.EqualsAndHashCode) Maps(com.google.common.collect.Maps) WSFederationClaims(org.apereo.cas.ws.idp.WSFederationClaims) ArrayList(java.util.ArrayList) AbstractRegisteredServiceAttributeReleasePolicy(org.apereo.cas.services.AbstractRegisteredServiceAttributeReleasePolicy) LinkedHashMap(java.util.LinkedHashMap) ScriptingUtils(org.apereo.cas.util.scripting.ScriptingUtils) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) ApplicationContextProvider(org.apereo.cas.util.spring.ApplicationContextProvider) ExecutableCompiledGroovyScript(org.apereo.cas.util.scripting.ExecutableCompiledGroovyScript) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap)

Example 12 with Maps

use of org.apache.flink.shaded.guava30.com.google.common.collect.Maps in project cas by apereo.

the class LdapAuthenticationHandler method collectAttributesForLdapEntry.

/**
 * Collect attributes for ldap entry.
 *
 * @param ldapEntry the ldap entry
 * @param username  the username
 * @return the map
 */
protected Map<String, List<Object>> collectAttributesForLdapEntry(final LdapEntry ldapEntry, final String username) {
    val attributeMap = Maps.<String, List<Object>>newHashMapWithExpectedSize(this.principalAttributeMap.size());
    LOGGER.debug("The following attributes are requested to be retrieved and mapped: [{}]", attributeMap.keySet());
    principalAttributeMap.forEach((key, names) -> {
        val attributeNames = CollectionUtils.toCollection(names, ArrayList.class);
        if (attributeNames.size() == 1 && attributeNames.stream().allMatch(s -> s.toString().endsWith(";"))) {
            val attrs = ldapEntry.getAttributes().stream().filter(attr -> attr.getName().startsWith(key.concat(";"))).collect(Collectors.toList());
            attrs.forEach(attr -> attributeMap.putAll(collectAttributeValueForEntry(ldapEntry, attr.getName(), List.of())));
        } else {
            attributeMap.putAll(collectAttributeValueForEntry(ldapEntry, key, attributeNames));
        }
    });
    if (this.collectDnAttribute) {
        LOGGER.debug("Recording principal DN attribute as [{}]", this.principalDnAttributeName);
        attributeMap.put(this.principalDnAttributeName, CollectionUtils.wrapList(ldapEntry.getDn()));
    }
    return attributeMap;
}
Also used : lombok.val(lombok.val) LoginException(javax.security.auth.login.LoginException) Setter(lombok.Setter) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Getter(lombok.Getter) AuthenticationRequest(org.ldaptive.auth.AuthenticationRequest) ReturnAttributes(org.ldaptive.ReturnAttributes) AuthenticationResponse(org.ldaptive.auth.AuthenticationResponse) AuthenticationResultCode(org.ldaptive.auth.AuthenticationResultCode) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PrincipalFactory(org.apereo.cas.authentication.principal.PrincipalFactory) GeneralSecurityException(java.security.GeneralSecurityException) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) FailedLoginException(javax.security.auth.login.FailedLoginException) ServicesManager(org.apereo.cas.services.ServicesManager) AbstractUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler) Collection(java.util.Collection) lombok.val(lombok.val) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) List(java.util.List) Authenticator(org.ldaptive.auth.Authenticator) Credential(org.ldaptive.Credential) DisposableBean(org.springframework.beans.factory.DisposableBean) LdapEntry(org.ldaptive.LdapEntry) Principal(org.apereo.cas.authentication.principal.Principal) LdapException(org.ldaptive.LdapException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with Maps

use of org.apache.flink.shaded.guava30.com.google.common.collect.Maps in project SpinalTap by airbnb.

the class MysqlSchemaStore method getAll.

@Override
public Table<String, String, TreeMap<Integer, MysqlTableSchema>> getAll() {
    Table<String, String, TreeMap<Integer, MysqlTableSchema>> allSchemaTable = Tables.newCustomTable(Maps.newHashMap(), Maps::newHashMap);
    List<String> allSchemaInfo;
    try (Handle handle = jdbi.open()) {
        allSchemaInfo = MysqlSchemaUtil.LIST_STRING_RETRYER.call(() -> handle.createQuery(String.format(GET_ALL_SCHEMA_QUERY, source)).map(StringColumnMapper.INSTANCE).list());
    } catch (Exception ex) {
        log.error(String.format("Failed to get all schema for source: %s", source), ex);
        Throwables.throwIfUnchecked(ex);
        throw new RuntimeException(ex);
    }
    allSchemaInfo.stream().map(MysqlSchemaStore::deserializeSchemaInfo).forEach(schemaInfo -> {
        String database = schemaInfo.getDatabase();
        String table = schemaInfo.getTable();
        int version = schemaInfo.getVersion();
        if (!allSchemaTable.contains(database, table)) {
            allSchemaTable.put(database, table, Maps.newTreeMap());
        }
        allSchemaTable.get(database, table).put(version, schemaInfo);
    });
    return allSchemaTable;
}
Also used : Maps(com.google.common.collect.Maps) TreeMap(java.util.TreeMap) Handle(org.skife.jdbi.v2.Handle)

Example 14 with Maps

use of org.apache.flink.shaded.guava30.com.google.common.collect.Maps in project SpinalTap by airbnb.

the class MysqlSchemaTracker method processDDLStatement.

public void processDDLStatement(@NotNull final QueryEvent event) {
    BinlogFilePos binlogFilePos = event.getBinlogFilePos();
    String ddl = event.getSql();
    if (schemaStore.get(binlogFilePos) != null) {
        log.info(String.format("DDL Statement (%s) has already been processed. (BinlogFilePos: %s)", ddl, binlogFilePos));
        return;
    }
    // It could be a new database which has not been created in schema store database, so don't
    // switch to any database before applying database DDL.
    schemaDatabase.applyDDLStatement(DATABASE_DDL_SQL_PATTERN.matcher(ddl).find() ? "" : event.getDatabase(), ddl);
    // Get schemas for active tables in schema store
    Table<String, String, MysqlTableSchema> activeTableSchemasInStore = Tables.newCustomTable(Maps.newHashMap(), Maps::newHashMap);
    schemaStore.getAll().values().stream().map(treeMap -> treeMap.lastEntry().getValue()).filter(schema -> !schema.getColumnInfo().isEmpty()).forEach(schema -> activeTableSchemasInStore.put(schema.getDatabase(), schema.getTable(), schema));
    Set<String> activeDatabasesInStore = activeTableSchemasInStore.rowKeySet();
    Set<String> databasesInSchemaDatabase = schemaDatabase.listDatabases();
    // Handle new databases
    Sets.difference(databasesInSchemaDatabase, activeDatabasesInStore).forEach(newDatabase -> updateSchemaStore(newDatabase, event, Maps.newHashMap(), schemaDatabase.fetchTableSchema(newDatabase)));
    // Handle existing databases
    activeDatabasesInStore.forEach(database -> updateSchemaStore(database, event, activeTableSchemasInStore.row(database), schemaDatabase.fetchTableSchema(database)));
}
Also used : QueryEvent(com.airbnb.spinaltap.mysql.event.QueryEvent) BinlogFilePos(com.airbnb.spinaltap.mysql.BinlogFilePos) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) Tables(com.google.common.collect.Tables) Slf4j(lombok.extern.slf4j.Slf4j) Lists(com.google.common.collect.Lists) Map(java.util.Map) Pattern(java.util.regex.Pattern) Table(com.google.common.collect.Table) Maps(com.google.common.collect.Maps) BinlogFilePos(com.airbnb.spinaltap.mysql.BinlogFilePos)

Example 15 with Maps

use of org.apache.flink.shaded.guava30.com.google.common.collect.Maps in project SpinalTap by airbnb.

the class MysqlSchemaTrackerTest method testDropDatabase.

@Test
public void testDropDatabase() throws Exception {
    Table<String, String, TreeMap<Integer, MysqlTableSchema>> allTableSchemaInStore = Tables.newCustomTable(Maps.newHashMap(), Maps::newHashMap);
    allTableSchemaInStore.put(DATABASE_NAME, "table1", new TreeMap<Integer, MysqlTableSchema>() {

        {
            put(1, TABLE1_SCHEMA);
        }
    });
    allTableSchemaInStore.put(DATABASE_NAME, "table2", new TreeMap<Integer, MysqlTableSchema>() {

        {
            put(1, TABLE2_SCHEMA);
        }
    });
    allTableSchemaInStore.put(DATABASE2_NAME, "table1", new TreeMap<Integer, MysqlTableSchema>() {

        {
            put(1, DATABASE2_TABLE1_SCHEMA);
        }
    });
    when(schemaDatabase.listDatabases()).thenReturn(Sets.newHashSet(DATABASE2_NAME));
    when(schemaStore.getAll()).thenReturn(allTableSchemaInStore);
    when(schemaDatabase.fetchTableSchema(DATABASE_NAME)).thenReturn(ImmutableMap.of());
    when(schemaDatabase.fetchTableSchema(DATABASE2_NAME)).thenReturn(ImmutableMap.of("table1", DATABASE2_TABLE1_SCHEMA));
    QueryEvent queryEvent = new QueryEvent(0, 0, binlogFilePos, DATABASE2_NAME, "DROP DATABASE `database1`");
    SchemaTracker schemaTracker = new MysqlSchemaTracker(schemaStore, schemaDatabase);
    schemaTracker.processDDLStatement(queryEvent);
    verify(schemaStore).put(DATABASE_NAME, "table1", queryEvent.getBinlogFilePos(), queryEvent.getTimestamp(), queryEvent.getSql(), Lists.newArrayList());
    verify(schemaStore).put(DATABASE_NAME, "table2", queryEvent.getBinlogFilePos(), queryEvent.getTimestamp(), queryEvent.getSql(), Lists.newArrayList());
}
Also used : Maps(com.google.common.collect.Maps) TreeMap(java.util.TreeMap) QueryEvent(com.airbnb.spinaltap.mysql.event.QueryEvent) Test(org.junit.Test)

Aggregations

Maps (com.google.common.collect.Maps)15 Map (java.util.Map)10 Slf4j (lombok.extern.slf4j.Slf4j)9 List (java.util.List)8 lombok.val (lombok.val)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)5 Collectors.toSet (java.util.stream.Collectors.toSet)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 RandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator)5 RandomGenerator.createRandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator)5 SequencingReadAnalysis (org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis)5 Sample (org.icgc.dcc.song.server.model.entity.Sample)5 CompositeEntity (org.icgc.dcc.song.server.model.entity.composites.CompositeEntity)5 AnalysisGenerator.createAnalysisGenerator (org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator)5 StudyGenerator.createStudyGenerator (org.icgc.dcc.song.server.utils.StudyGenerator.createStudyGenerator)5 Before (org.junit.Before)5 RunWith (org.junit.runner.RunWith)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5