All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apereo.cas.jdbc.SingleRowJdbcPersonAttributeDao Maven / Gradle / Ivy

The newest version!
package org.apereo.cas.jdbc;

import org.apereo.cas.authentication.attribute.SimplePersonAttributes;
import org.apereo.cas.authentication.principal.attribute.PersonAttributeDao;
import org.apereo.cas.authentication.principal.attribute.PersonAttributes;
import lombok.val;
import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.jdbc.core.RowMapper;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * An {@link PersonAttributeDao}
 * implementation that maps from column names in the result of a SQL query
 * to attribute names. 
* You must set a Map from column names to attribute names and only column names * appearing as keys in that map will be used. * * @author [email protected] * @author Eric Dalquist * @since 7.1.0 */ public class SingleRowJdbcPersonAttributeDao extends AbstractJdbcPersonAttributeDao> { private static final RowMapper> MAPPER = new ColumnMapRowMapper(); public SingleRowJdbcPersonAttributeDao(final DataSource ds, final String sql) { super(ds, sql); } @Override protected RowMapper> getRowMapper() { return MAPPER; } @Override protected List parseAttributeMapFromResults(final List> queryResults, final String queryUserName) { val peopleAttributes = new ArrayList(queryResults.size()); for (val queryResult : queryResults) { val multivaluedQueryResult = toMultivaluedMap(queryResult); val userNameAttribute = getConfiguredUserNameAttribute(); if (isUserNameAttributeConfigured() && queryResult.containsKey(userNameAttribute)) { peopleAttributes.add(SimplePersonAttributes.fromAttribute(userNameAttribute, multivaluedQueryResult)); } else if (queryUserName != null) { peopleAttributes.add(new SimplePersonAttributes(queryUserName, multivaluedQueryResult)); } else { peopleAttributes.add(SimplePersonAttributes.fromAttribute(userNameAttribute, multivaluedQueryResult)); } } return peopleAttributes; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy