@Override protected void store(String code, OAuth2Authentication authentication) { jdbcTemplate.update(insertAuthenticationSql, new Object[] { code, new SqlLobValue(SerializationUtils.serialize(authentication)) }, new int[] { Types.VARCHAR, Types.BLOB }); }
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) { jdbcTemplate.update(insertRefreshTokenSql, new Object[] { extractTokenKey(refreshToken.getValue()), new SqlLobValue(serializeRefreshToken(refreshToken)), new SqlLobValue(serializeAuthentication(authentication)) }, new int[] { Types.VARCHAR, Types.BLOB, Types.BLOB }); }
@Test public void test3() throws SQLException { SqlLobValue lob = new SqlLobValue(new InputStreamReader(new ByteArrayInputStream("Bla".getBytes())), 12); thrown.expect(IllegalArgumentException.class); lob.setTypeValue(preparedStatement, 1, Types.BLOB, "test"); }
public void saveAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication, OAuth2AccessToken accessToken) { removeAccessToken(resource, authentication); String name = authentication==null ? null : authentication.getName(); jdbcTemplate.update( insertAccessTokenSql, new Object[] { accessToken.getValue(), new SqlLobValue(SerializationUtils.serialize(accessToken)), keyGenerator.extractKey(resource, authentication), name, resource.getClientId() }, new int[] { Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); }
SqlLobValue lob = new SqlLobValue("bla"); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); lob = new SqlLobValue("bla".getBytes()); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); fail("IllegalArgumentException should have been thrown"); lob = new SqlLobValue(new ByteArrayInputStream("bla".getBytes()), 3); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); lob = new SqlLobValue(new InputStreamReader(new ByteArrayInputStream( "bla".getBytes())), 3); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); lob = new SqlLobValue("bla"); lob.setTypeValue(preparedStatement, 1, Types.BLOB, "test"); lob = new SqlLobValue("bla".getBytes()); lob.setTypeValue(preparedStatement, 1, Types.BLOB, "test"); lob = new SqlLobValue(new ByteArrayInputStream("bla".getBytes()), 3); lob.setTypeValue(preparedStatement, 1, Types.BLOB, "test"); lob = new SqlLobValue(new InputStreamReader(new ByteArrayInputStream( "bla".getBytes())), 3);
@Test public void test7() throws SQLException { SqlLobValue lob = new SqlLobValue("bla".getBytes()); thrown.expect(IllegalArgumentException.class); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); }
@Test public void test5() throws Exception { byte[] testContent = "Bla".getBytes(); SqlLobValue lob = new SqlLobValue(new ByteArrayInputStream(testContent), 3, handler); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); verify(creator).setClobAsAsciiStream(eq(preparedStatement), eq(1), inputStreamCaptor.capture(), eq(3)); byte[] bytes = new byte[3]; inputStreamCaptor.getValue().read(bytes); assertThat(bytes, equalTo(testContent)); }
@Test public void test1() throws SQLException { byte[] testBytes = "Bla".getBytes(); SqlLobValue lob = new SqlLobValue(testBytes, handler); lob.setTypeValue(preparedStatement, 1, Types.BLOB, "test"); verify(creator).setBlobAsBytes(preparedStatement, 1, testBytes); }
@Test public void testOtherSqlType() throws SQLException { SqlLobValue lob = new SqlLobValue("Bla", handler); thrown.expect(IllegalArgumentException.class); lob.setTypeValue(preparedStatement, 1, Types.SMALLINT, "test"); }
@Test public void test2() throws SQLException { String testString = "Bla"; SqlLobValue lob = new SqlLobValue(testString, handler); lob.setTypeValue(preparedStatement, 1, Types.BLOB, "test"); verify(creator).setBlobAsBytes(preparedStatement, 1, testString.getBytes()); }
@Test public void test6() throws SQLException { byte[] testContent = "Bla".getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(testContent); InputStreamReader reader = new InputStreamReader(bais); SqlLobValue lob = new SqlLobValue(reader, 3, handler); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); verify(creator).setClobAsCharacterStream(eq(preparedStatement), eq(1), eq(reader), eq(3)); }
@Test public void test4() throws SQLException { String testContent = "Bla"; SqlLobValue lob = new SqlLobValue(testContent, handler); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); verify(creator).setClobAsString(preparedStatement, 1, testContent); }
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { String refreshToken = null; if (token.getRefreshToken() != null) { refreshToken = token.getRefreshToken().getValue(); } if (readAccessToken(token.getValue())!=null) { removeAccessToken(token.getValue()); } jdbcTemplate.update(insertAccessTokenSql, new Object[] { extractTokenKey(token.getValue()), new SqlLobValue(serializeAccessToken(token)), authenticationKeyGenerator.extractKey(authentication), authentication.isClientOnly() ? null : authentication.getName(), authentication.getOAuth2Request().getClientId(), new SqlLobValue(serializeAuthentication(authentication)), extractTokenKey(refreshToken) }, new int[] { Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR }); }
@Override public String createAuthorizationCode(OAuth2Authentication authentication) { final int max_tries = 3; performExpirationClean(); JdbcTemplate template = new JdbcTemplate(dataSource); int tries = 0; while ((tries++)<=max_tries) { try { String code = generator.generate(); long expiresAt = System.currentTimeMillis()+getExpirationTime(); String userId = authentication.getUserAuthentication()==null ? null : ((UaaPrincipal)authentication.getUserAuthentication().getPrincipal()).getId(); String clientId = authentication.getOAuth2Request().getClientId(); SqlLobValue data = new SqlLobValue(serializeOauth2Authentication(authentication)); int updated = template.update( SQL_INSERT_STATEMENT, new Object[] {code, userId, clientId, expiresAt, data, IdentityZoneHolder.get().getId()}, new int[] {Types.VARCHAR,Types.VARCHAR, Types.VARCHAR, Types.NUMERIC, Types.BLOB, Types.VARCHAR} ); if (updated==0) { throw new DataIntegrityViolationException("[oauth_code] Failed to insert code. Result was 0"); } return code; } catch (DataIntegrityViolationException exists) { if (tries>=max_tries) throw exists; } } return null; }
@Test public void testCorrectCleanup() throws SQLException { SqlLobValue lob = new SqlLobValue("Bla", handler); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); lob.cleanup(); verify(creator).setClobAsString(preparedStatement, 1, "Bla"); verify(creator).close(); }
@Override protected void store(String code, OAuth2Authentication authentication) { jdbcTemplate.update(insertAuthenticationSql, new Object[] { code, new SqlLobValue(SerializationUtils.serialize(authentication)) }, new int[] { Types.VARCHAR, Types.BLOB }); }
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) { jdbcTemplate.update(insertRefreshTokenSql, new Object[] { extractTokenKey(refreshToken.getValue()), new SqlLobValue(serializeRefreshToken(refreshToken)), new SqlLobValue(serializeAuthentication(authentication)) }, new int[] { Types.VARCHAR, Types.BLOB, Types.BLOB }); }
InputStream inputStream = httpServletRequest.getInputStream(); int contentLength = -1; // fake, will be ignored anyway SqlLobValue sqlLobValue = new SqlLobValue( inputStream, contentLength, new DefaultLobHandler() { public LobCreator getLobCreator() { return new DefaultLobHandler.DefaultLobCreator() { public void setBlobAsBinaryStream(PreparedStatement ps, int paramIndex, InputStream binaryStream, int contentLength) throws SQLException { // The contentLength parameter should be the -1 we provided earlier. // You now have direct access to the PreparedStatement. // Simply avoid calling setBinaryStream(int, InputStream, int) // in favor of setBinaryStream(int, InputStream). ps.setBinaryStream(paramIndex, binaryStream); } }; } } ); jdbcTemplate.update( "INSERT INTO foo (bar) VALUES (?)", new Object[]{ sqlLobValue } );
public void saveAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication, OAuth2AccessToken accessToken) { removeAccessToken(resource, authentication); String name = authentication==null ? null : authentication.getName(); jdbcTemplate.update( insertAccessTokenSql, new Object[] { accessToken.getValue(), new SqlLobValue(SerializationUtils.serialize(accessToken)), keyGenerator.extractKey(resource, authentication), name, resource.getClientId() }, new int[] { Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); }
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { String refreshToken = null; if (token.getRefreshToken() != null) { refreshToken = token.getRefreshToken().getValue(); } if (readAccessToken(token.getValue())!=null) { removeAccessToken(token.getValue()); } jdbcTemplate.update(insertAccessTokenSql, new Object[] { extractTokenKey(token.getValue()), new SqlLobValue(serializeAccessToken(token)), authenticationKeyGenerator.extractKey(authentication), authentication.isClientOnly() ? null : authentication.getName(), authentication.getOAuth2Request().getClientId(), new SqlLobValue(serializeAuthentication(authentication)), extractTokenKey(refreshToken) }, new int[] { Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR }); }