Search in sources :

Example 1 with SqlLobValue

use of org.springframework.jdbc.core.support.SqlLobValue in project spring-security-oauth by spring-projects.

the class JdbcTokenStore method storeAccessToken.

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 });
}
Also used : SqlLobValue(org.springframework.jdbc.core.support.SqlLobValue)

Example 2 with SqlLobValue

use of org.springframework.jdbc.core.support.SqlLobValue in project sakuli by ConSol.

the class DaoTestCaseImplTest method testGetScreenshotAsSqlLobValueTestCase.

@Test
public void testGetScreenshotAsSqlLobValueTestCase() throws Exception {
    Path screenshotPath = Paths.get(this.getClass().getResource("computer.png").toURI());
    TestCase testCase = new TestCaseExampleBuilder().withException(null).withTestCaseSteps(Collections.singletonList(new TestCaseStepExampleBuilder().withException(new SakuliExceptionWithScreenshot("test-exception", screenshotPath)).buildExample())).buildExample();
    SqlLobValue result = testling.getScreenshotAsSqlLobValue(testCase);
    assertNotNull(result);
}
Also used : Path(java.nio.file.Path) SqlLobValue(org.springframework.jdbc.core.support.SqlLobValue) TestCase(org.sakuli.datamodel.TestCase) SakuliExceptionWithScreenshot(org.sakuli.exceptions.SakuliExceptionWithScreenshot) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test)

Example 3 with SqlLobValue

use of org.springframework.jdbc.core.support.SqlLobValue in project sakuli by ConSol.

the class DaoTestCaseImpl method getScreenshotAsSqlLobValue.

/**
     * Determine the first available screenshot inside of the testcase and respectively in the assigned steps.
     * For Details of the transformation, see {@link org.springframework.jdbc.support.lob.LobHandler}.
     *
     * @return a {@link SqlLobValue}
     */
protected SqlLobValue getScreenshotAsSqlLobValue(TestCase testCase) {
    try {
        Path screenShotPath = testCase.getScreenShotPath();
        if (screenShotPath == null) {
            //get first step exception
            for (TestCaseStep step : testCase.getStepsAsSortedSet()) {
                if (step.getScreenShotPath() != null) {
                    screenShotPath = step.getScreenShotPath();
                    break;
                }
            }
        }
        if (screenShotPath != null) {
            final InputStream blobIs = Files.newInputStream(screenShotPath);
            final int length = (int) screenShotPath.toFile().length();
            return new SqlLobValue(blobIs, length, lobHandler);
        }
        return null;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) SqlLobValue(org.springframework.jdbc.core.support.SqlLobValue) InputStream(java.io.InputStream) TestCaseStep(org.sakuli.datamodel.TestCaseStep) IOException(java.io.IOException)

Example 4 with SqlLobValue

use of org.springframework.jdbc.core.support.SqlLobValue in project sakuli by ConSol.

the class DaoTestSuiteImpl method getCompleteParameters.

private MapSqlParameterSource getCompleteParameters() {
    MapSqlParameterSource tcParameters = getInitialDataParameters();
    tcParameters.addValues(getGuidParameter().getValues());
    tcParameters.addValue("stop", testSuite.getStopDateAsUnixTimestamp());
    int warningTime = testSuite.getWarningTime();
    tcParameters.addValue("warning", (warningTime != 0) ? warningTime : null);
    int criticalTime = testSuite.getCriticalTime();
    tcParameters.addValue("critical", (criticalTime != 0) ? criticalTime : null);
    tcParameters.addValue("duration", testSuite.getDuration());
    //try to save the screenshot
    try {
        if (testSuite.getScreenShotPath() != null) {
            final InputStream blobIs = Files.newInputStream(testSuite.getScreenShotPath());
            final int length = (int) testSuite.getScreenShotPath().toFile().length();
            tcParameters.addValue("screenshot", new SqlLobValue(blobIs, length, lobHandler), Types.BLOB);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    tcParameters.addValue("msg", testSuite.getExceptionMessages(false));
    return tcParameters;
}
Also used : SqlLobValue(org.springframework.jdbc.core.support.SqlLobValue) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 5 with SqlLobValue

use of org.springframework.jdbc.core.support.SqlLobValue in project spring-security-oauth by spring-projects.

the class JdbcClientTokenServices method saveAccessToken.

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 });
}
Also used : SqlLobValue(org.springframework.jdbc.core.support.SqlLobValue)

Aggregations

SqlLobValue (org.springframework.jdbc.core.support.SqlLobValue)6 Path (java.nio.file.Path)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)2 TestCase (org.sakuli.datamodel.TestCase)2 SakuliExceptionWithScreenshot (org.sakuli.exceptions.SakuliExceptionWithScreenshot)2 Test (org.testng.annotations.Test)2 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)1 TestCaseStep (org.sakuli.datamodel.TestCaseStep)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1