Search in sources :

Example 1 with PreparedStatementSetter

use of org.springframework.jdbc.core.PreparedStatementSetter in project spring-security by spring-projects.

the class JdbcUserDetailsManager method updateUser.

public void updateUser(final UserDetails user) {
    validateUserDetails(user);
    getJdbcTemplate().update(updateUserSql, new PreparedStatementSetter() {

        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setString(1, user.getPassword());
            ps.setBoolean(2, user.isEnabled());
            ps.setString(3, user.getUsername());
        }
    });
    if (getEnableAuthorities()) {
        deleteUserAuthorities(user.getUsername());
        insertUserAuthorities(user);
    }
    userCache.removeUserFromCache(user.getUsername());
}
Also used : SQLException(java.sql.SQLException) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement)

Example 2 with PreparedStatementSetter

use of org.springframework.jdbc.core.PreparedStatementSetter in project spring-security by spring-projects.

the class JdbcUserDetailsManager method addUserToGroup.

public void addUserToGroup(final String username, final String groupName) {
    logger.debug("Adding user '" + username + "' to group '" + groupName + "'");
    Assert.hasText(username, "username should have text");
    ;
    Assert.hasText(groupName, "groupName should have text");
    ;
    final int id = findGroupId(groupName);
    getJdbcTemplate().update(insertGroupMemberSql, new PreparedStatementSetter() {

        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setInt(1, id);
            ps.setString(2, username);
        }
    });
    userCache.removeUserFromCache(username);
}
Also used : SQLException(java.sql.SQLException) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement)

Example 3 with PreparedStatementSetter

use of org.springframework.jdbc.core.PreparedStatementSetter in project spring-security by spring-projects.

the class JdbcUserDetailsManager method removeGroupAuthority.

public void removeGroupAuthority(String groupName, final GrantedAuthority authority) {
    logger.debug("Removing authority '" + authority + "' from group '" + groupName + "'");
    Assert.hasText(groupName, "groupName should have text");
    Assert.notNull(authority, "authority cannot be null");
    final int id = findGroupId(groupName);
    getJdbcTemplate().update(deleteGroupAuthoritySql, new PreparedStatementSetter() {

        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setInt(1, id);
            ps.setString(2, authority.getAuthority());
        }
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement)

Example 4 with PreparedStatementSetter

use of org.springframework.jdbc.core.PreparedStatementSetter in project spring-security by spring-projects.

the class JdbcUserDetailsManager method addGroupAuthority.

public void addGroupAuthority(final String groupName, final GrantedAuthority authority) {
    logger.debug("Adding authority '" + authority + "' to group '" + groupName + "'");
    Assert.hasText(groupName, "groupName should have text");
    ;
    Assert.notNull(authority, "authority cannot be null");
    final int id = findGroupId(groupName);
    getJdbcTemplate().update(insertGroupAuthoritySql, new PreparedStatementSetter() {

        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setInt(1, id);
            ps.setString(2, authority.getAuthority());
        }
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement)

Example 5 with PreparedStatementSetter

use of org.springframework.jdbc.core.PreparedStatementSetter in project spring-security by spring-projects.

the class BasicLookupStrategy method lookupPrimaryKeys.

/**
	 * Locates the primary key IDs specified in "findNow", adding AclImpl instances with
	 * StubAclParents to the "acls" Map.
	 *
	 * @param acls the AclImpls (with StubAclParents)
	 * @param findNow Long-based primary keys to retrieve
	 * @param sids
	 */
private void lookupPrimaryKeys(final Map<Serializable, Acl> acls, final Set<Long> findNow, final List<Sid> sids) {
    Assert.notNull(acls, "ACLs are required");
    Assert.notEmpty(findNow, "Items to find now required");
    String sql = computeRepeatingSql(lookupPrimaryKeysWhereClause, findNow.size());
    Set<Long> parentsToLookup = jdbcTemplate.query(sql, new PreparedStatementSetter() {

        public void setValues(PreparedStatement ps) throws SQLException {
            int i = 0;
            for (Long toFind : findNow) {
                i++;
                ps.setLong(i, toFind);
            }
        }
    }, new ProcessResultSet(acls, sids));
    // connection (SEC-547)
    if (parentsToLookup.size() > 0) {
        lookupPrimaryKeys(acls, parentsToLookup, sids);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement)

Aggregations

PreparedStatementSetter (org.springframework.jdbc.core.PreparedStatementSetter)22 SQLException (java.sql.SQLException)13 PreparedStatement (java.sql.PreparedStatement)12 List (java.util.List)5 Timestamp (java.sql.Timestamp)4 Date (java.util.Date)4 ArgumentPreparedStatementSetter (org.springframework.jdbc.core.ArgumentPreparedStatementSetter)4 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)3 Map (java.util.Map)3 SqlParameterValue (org.springframework.jdbc.core.SqlParameterValue)3 Lists (com.google.common.collect.Lists)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 DataSource (javax.sql.DataSource)2 SessionFactory (org.hibernate.SessionFactory)2 SortOrder (org.hisp.dhis.analytics.SortOrder)2 DataStatisticsEvent (org.hisp.dhis.datastatistics.DataStatisticsEvent)2