List of usage examples for org.springframework.dao IncorrectResultSizeDataAccessException IncorrectResultSizeDataAccessException
public IncorrectResultSizeDataAccessException(String msg, int expectedSize)
From source file:net.noday.core.security.SecurityDao.java
private User safeQueryForObject(String sql, RowMapper<User> rowMapper, Object... args) { List<User> results = jdbcTemplate.query(sql, args, new RowMapperResultSetExtractor<User>(rowMapper, 1)); int size = (results != null ? results.size() : 0); if (results.size() > 1) { throw new IncorrectResultSizeDataAccessException(1, size); }/*from w ww .j av a 2 s .com*/ return results.iterator().next(); }
From source file:org.cloudfoundry.identity.uaa.ldap.extension.SpringSecurityLdapTemplate.java
/** * Internal method extracted to avoid code duplication in AD search. */// w ww . j a v a2 s .co m public static DirContextOperations searchForSingleEntryInternal(DirContext ctx, SearchControls searchControls, String base, String filter, Object[] params) throws NamingException { final DistinguishedName ctxBaseDn = new DistinguishedName(ctx.getNameInNamespace()); final DistinguishedName searchBaseDn = new DistinguishedName(base); final NamingEnumeration<SearchResult> resultsEnum = ctx.search(searchBaseDn, filter, params, buildControls(searchControls)); if (logger.isDebugEnabled()) { logger.debug("Searching for entry under DN '" + ctxBaseDn + "', base = '" + searchBaseDn + "', filter = '" + filter + "'"); } Set<DirContextOperations> results = new HashSet<DirContextOperations>(); try { while (resultsEnum.hasMore()) { SearchResult searchResult = resultsEnum.next(); DirContextAdapter dca = (DirContextAdapter) searchResult.getObject(); Assert.notNull(dca, "No object returned by search, DirContext is not correctly configured"); if (logger.isDebugEnabled()) { logger.debug("Found DN: " + dca.getDn()); } results.add(dca); } } catch (PartialResultException e) { LdapUtils.closeEnumeration(resultsEnum); logger.info("Ignoring PartialResultException"); } if (results.size() == 0) { throw new IncorrectResultSizeDataAccessException(1, 0); } if (results.size() > 1) { throw new IncorrectResultSizeDataAccessException(1, results.size()); } return results.iterator().next(); }
From source file:org.cloudfoundry.identity.uaa.provider.oauth.XOAuthProviderConfigurator.java
public IdentityProvider retrieveByIssuer(String issuer, String zoneId) throws IncorrectResultSizeDataAccessException { List<IdentityProvider> providers = retrieveAll(true, zoneId).stream() .filter(p -> OIDC10.equals(p.getType()) && issuer.equals(((OIDCIdentityProviderDefinition) p.getConfig()).getIssuer())) .collect(Collectors.toList()); if (providers.isEmpty()) { throw new IncorrectResultSizeDataAccessException( String.format("Active provider with issuer[%s] not found", issuer), 1); } else if (providers.size() > 1) { throw new IncorrectResultSizeDataAccessException( String.format("Duplicate providers with issuer[%s] not found", issuer), 1); }//from w w w . j av a2 s . c om return providers.get(0); }
From source file:org.cloudfoundry.identity.uaa.scim.dao.standard.JdbcScimGroupProvisioning.java
@Override public ScimGroupInterface update(final String id, final ScimGroupInterface group) throws InvalidScimResourceException, ScimResourceNotFoundException { try {//w ww .ja v a 2 s . c o m int updated = jdbcTemplate.update(UPDATE_GROUP_SQL, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, group.getVersion() + 1); ps.setString(2, group.getDisplayName()); ps.setTimestamp(3, new Timestamp(new Date().getTime())); ps.setString(4, id); ps.setInt(5, group.getVersion()); } }); if (updated != 1) { throw new IncorrectResultSizeDataAccessException(1, updated); } return retrieve(id); } catch (DuplicateKeyException ex) { throw new InvalidScimResourceException( "A group with displayName: " + group.getDisplayName() + " already exists"); } }
From source file:org.cloudfoundry.identity.uaa.scim.dao.standard.JdbcScimGroupProvisioning.java
@Override public ScimGroupInterface delete(String id, int version) throws ScimResourceNotFoundException { ScimGroupInterface group = retrieve(id); int deleted;//from w ww . ja va 2 s . c o m if (version > 0) { deleted = jdbcTemplate.update(DELETE_GROUP_SQL + " and version=?;", id, version); } else { deleted = jdbcTemplate.update(DELETE_GROUP_SQL, id); } if (deleted != 1) { throw new IncorrectResultSizeDataAccessException(1, deleted); } return group; }
From source file:org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupProvisioning.java
public ScimGroup update(final String id, final ScimGroup group, final String zoneId) throws InvalidScimResourceException, ScimResourceNotFoundException { try {/*from www. j av a 2s.co m*/ validateGroup(group); int updated = jdbcTemplate.update(UPDATE_GROUP_SQL, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { int pos = 1; ps.setInt(pos++, group.getVersion() + 1); ps.setString(pos++, group.getDisplayName()); ps.setString(pos++, group.getDescription()); ps.setTimestamp(pos++, new Timestamp(new Date().getTime())); ps.setString(pos++, id); ps.setInt(pos++, group.getVersion()); ps.setString(pos++, zoneId); } }); if (updated != 1) { throw new IncorrectResultSizeDataAccessException(1, updated); } return retrieve(id, zoneId); } catch (DuplicateKeyException ex) { throw new InvalidScimResourceException( "A group with displayName: " + group.getDisplayName() + " already exists"); } }
From source file:org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupProvisioning.java
@Override public ScimGroup delete(String id, int version) throws ScimResourceNotFoundException { ScimGroup group = retrieve(id);//from w w w . j ava 2 s .co m membershipManager.removeMembersByGroupId(id); externalGroupMappingManager.unmapAll(id); int deleted; if (version > 0) { deleted = jdbcTemplate.update(DELETE_GROUP_SQL + " and version=?;", id, IdentityZoneHolder.get().getId(), version); } else { deleted = jdbcTemplate.update(DELETE_GROUP_SQL, id, IdentityZoneHolder.get().getId()); } if (deleted != 1) { throw new IncorrectResultSizeDataAccessException(1, deleted); } return group; }
From source file:org.springframework.ldap.core.LdapTemplate.java
public Object searchForObject(Name base, String filter, ContextMapper mapper) { List result = search(base, filter, mapper); if (result.size() == 0) { throw new EmptyResultDataAccessException(1); } else if (result.size() != 1) { throw new IncorrectResultSizeDataAccessException(1, result.size()); }//from w ww . j ava 2 s . co m return result.get(0); }
From source file:org.springframework.security.ldap.SpringSecurityLdapTemplate.java
/** * Internal method extracted to avoid code duplication in AD search. */// ww w. ja v a 2s. co m public static DirContextOperations searchForSingleEntryInternal(DirContext ctx, SearchControls searchControls, String base, String filter, Object[] params) throws NamingException { final DistinguishedName ctxBaseDn = new DistinguishedName(ctx.getNameInNamespace()); final DistinguishedName searchBaseDn = new DistinguishedName(base); final NamingEnumeration<SearchResult> resultsEnum = ctx.search(searchBaseDn, filter, params, buildControls(searchControls)); if (logger.isDebugEnabled()) { logger.debug("Searching for entry under DN '" + ctxBaseDn + "', base = '" + searchBaseDn + "', filter = '" + filter + "'"); } Set<DirContextOperations> results = new HashSet<>(); try { while (resultsEnum.hasMore()) { SearchResult searchResult = resultsEnum.next(); DirContextAdapter dca = (DirContextAdapter) searchResult.getObject(); Assert.notNull(dca, "No object returned by search, DirContext is not correctly configured"); if (logger.isDebugEnabled()) { logger.debug("Found DN: " + dca.getDn()); } results.add(dca); } } catch (PartialResultException e) { LdapUtils.closeEnumeration(resultsEnum); logger.info("Ignoring PartialResultException"); } if (results.size() == 0) { throw new IncorrectResultSizeDataAccessException(1, 0); } if (results.size() > 1) { throw new IncorrectResultSizeDataAccessException(1, results.size()); } return results.iterator().next(); }
From source file:org.springframework.security.provisioning.JdbcUserDetailsManager.java
public boolean userExists(String username) { List<String> users = getJdbcTemplate().queryForList(userExistsSql, new String[] { username }, String.class); if (users.size() > 1) { throw new IncorrectResultSizeDataAccessException( "More than one user found with name '" + username + "'", 1); }/*from ww w .j a v a 2 s. c o m*/ return users.size() == 1; }