Search in sources :

Example 1 with SecretType

use of org.wso2.carbon.identity.secret.mgt.core.model.SecretType in project carbon-identity-framework by wso2.

the class SecretDAOImpl method getSecretTypeByName.

@Override
public SecretType getSecretTypeByName(String secretTypeName) throws SecretManagementException {
    NamedJdbcTemplate jdbcTemplate = getNewTemplate();
    SecretType secretTypeResponse;
    try {
        secretTypeResponse = jdbcTemplate.fetchSingleRecord(GET_SECRET_TYPE_BY_NAME, (resultSet, rowNumber) -> {
            SecretType secretType = new SecretType();
            secretType.setId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID));
            secretType.setName(resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME));
            secretType.setDescription(resultSet.getString(DB_SCHEMA_COLUMN_NAME_DESCRIPTION));
            return secretType;
        }, preparedStatement -> preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_NAME, secretTypeName));
        return secretTypeResponse;
    } catch (DataAccessException e) {
        throw handleServerException(ERROR_CODE_RETRIEVE_SECRET_TYPE, secretTypeName, e);
    }
}
Also used : DB_SCHEMA_COLUMN_NAME_CREATED_TIME(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_CREATED_TIME) DB_SCHEMA_COLUMN_NAME_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_TYPE) StringUtils(org.apache.commons.lang.StringUtils) GET_SECRET_BY_ID(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRET_BY_ID) IdentityDatabaseUtil(org.wso2.carbon.identity.core.util.IdentityDatabaseUtil) UPDATE_SECRET_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.UPDATE_SECRET_TYPE) Date(java.util.Date) GET_SECRET_BY_NAME(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRET_BY_NAME) DB_SCHEMA_COLUMN_NAME_SECRET_NAME(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_SECRET_NAME) SecretUtils.handleServerException(org.wso2.carbon.identity.secret.mgt.core.util.SecretUtils.handleServerException) ERROR_CODE_ADD_SECRET_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_ADD_SECRET_TYPE) UPDATE_SECRET_DESCRIPTION(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.UPDATE_SECRET_DESCRIPTION) ERROR_CODE_UPDATE_SECRET_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_UPDATE_SECRET_TYPE) ERROR_CODE_SECRETS_DOES_NOT_EXISTS(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_SECRETS_DOES_NOT_EXISTS) ERROR_CODE_DELETE_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_DELETE_SECRET) SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType) LambdaExceptionUtils(org.wso2.carbon.identity.core.util.LambdaExceptionUtils) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) GET_SECRET_NAME_BY_ID(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRET_NAME_BY_ID) UPDATE_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.UPDATE_SECRET) Secret(org.wso2.carbon.identity.secret.mgt.core.model.Secret) DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED) List(java.util.List) ERROR_CODE_UPDATE_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_UPDATE_SECRET) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException) UTC(java.time.ZoneOffset.UTC) LogFactory(org.apache.commons.logging.LogFactory) ERROR_CODE_GET_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_GET_SECRET) SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException) INSERT_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.INSERT_SECRET) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) NamedJdbcTemplate(org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate) DB_SCHEMA_COLUMN_NAME_SECRET_VALUE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_SECRET_VALUE) GET_SECRET_TYPE_BY_NAME(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRET_TYPE_BY_NAME) Calendar(java.util.Calendar) DB_SCHEMA_COLUMN_NAME_NAME(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_NAME) SQLConstants(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants) SecretDAO(org.wso2.carbon.identity.secret.mgt.core.dao.SecretDAO) GET_SECRETS(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRETS) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) ERROR_CODE_ADD_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_ADD_SECRET) CryptoException(org.wso2.carbon.core.util.CryptoException) ERROR_CODE_SECRET_ALREADY_EXISTS(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_SECRET_ALREADY_EXISTS) ERROR_CODE_REPLACE_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_REPLACE_SECRET) GET_SECRET_CREATED_TIME_BY_NAME(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRET_CREATED_TIME_BY_NAME) NamedTemplate(org.wso2.carbon.database.utils.jdbc.NamedTemplate) UPDATE_SECRET_VALUE(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.UPDATE_SECRET_VALUE) ERROR_CODE_DELETE_SECRET_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_DELETE_SECRET_TYPE) SecretUtils.handleClientException(org.wso2.carbon.identity.secret.mgt.core.util.SecretUtils.handleClientException) DB_SCHEMA_COLUMN_NAME_ID(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_ID) DB_SCHEMA_COLUMN_NAME_TENANT_ID(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_TENANT_ID) Log(org.apache.commons.logging.Log) DB_SCHEMA_COLUMN_NAME_DESCRIPTION(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_DESCRIPTION) ERROR_CODE_RETRIEVE_SECRET_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_RETRIEVE_SECRET_TYPE) SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType) NamedJdbcTemplate(org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Example 2 with SecretType

use of org.wso2.carbon.identity.secret.mgt.core.model.SecretType in project carbon-identity-framework by wso2.

the class SecretDAOImpl method addSecretType.

@Override
public void addSecretType(SecretType secretType) throws SecretManagementException {
    NamedJdbcTemplate jdbcTemplate = getNewTemplate();
    try {
        jdbcTemplate.executeInsert(SQLConstants.INSERT_SECRET_TYPE, preparedStatement -> {
            preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_ID, secretType.getId());
            preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_NAME, secretType.getName());
            preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_DESCRIPTION, secretType.getDescription());
        }, secretType, false);
    } catch (DataAccessException e) {
        throw handleServerException(ERROR_CODE_ADD_SECRET_TYPE, secretType.getName(), e);
    }
}
Also used : NamedJdbcTemplate(org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Example 3 with SecretType

use of org.wso2.carbon.identity.secret.mgt.core.model.SecretType in project carbon-identity-framework by wso2.

the class SecretManagerTest method testAddDuplicateSecret.

@Test(priority = 10, expectedExceptions = SecretManagementClientException.class)
public void testAddDuplicateSecret() throws Exception {
    SecretType secretType = secretManager.addSecretType(getSampleSecretTypeAdd(SAMPLE_SECRET_TYPE_NAME1, SAMPLE_SECRET_TYPE_DESCRIPTION1));
    Secret secretAdd = getSampleSecretAdd(SAMPLE_SECRET_NAME1, SAMPLE_SECRET_VALUE1);
    encryptSecret(secretAdd.getSecretValue());
    secretManager.addSecret(secretType.getName(), secretAdd);
    secretManager.addSecret(secretType.getName(), secretAdd);
    fail("Expected: " + SecretManagementClientException.class.getName());
}
Also used : ResolvedSecret(org.wso2.carbon.identity.secret.mgt.core.model.ResolvedSecret) Secret(org.wso2.carbon.identity.secret.mgt.core.model.Secret) SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with SecretType

use of org.wso2.carbon.identity.secret.mgt.core.model.SecretType in project carbon-identity-framework by wso2.

the class SecretManagerTest method testAddSecret.

@Test(priority = 9)
public void testAddSecret() throws Exception {
    SecretType secretType = secretManager.addSecretType(getSampleSecretTypeAdd(SAMPLE_SECRET_TYPE_NAME1, SAMPLE_SECRET_TYPE_DESCRIPTION1));
    Secret secretAdd = getSampleSecretAdd(SAMPLE_SECRET_NAME1, SAMPLE_SECRET_VALUE1);
    encryptSecret(secretAdd.getSecretValue());
    Secret secret = secretManager.addSecret(secretType.getName(), secretAdd);
    assertNotNull(secret.getSecretId(), "Created secret type id cannot be null");
    assertEquals(secretAdd.getSecretName(), secret.getSecretName());
}
Also used : ResolvedSecret(org.wso2.carbon.identity.secret.mgt.core.model.ResolvedSecret) Secret(org.wso2.carbon.identity.secret.mgt.core.model.Secret) SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with SecretType

use of org.wso2.carbon.identity.secret.mgt.core.model.SecretType in project carbon-identity-framework by wso2.

the class SecretManagerTest method testAddDuplicateResourceType.

@Test(priority = 2, expectedExceptions = SecretManagementClientException.class)
public void testAddDuplicateResourceType() throws Exception {
    SecretType secretTypeAdd = getSampleSecretTypeAdd(SAMPLE_SECRET_TYPE_NAME1, SAMPLE_SECRET_TYPE_DESCRIPTION1);
    secretManager.addSecretType(secretTypeAdd);
    secretManager.addSecretType(secretTypeAdd);
    fail("Expected: " + SecretManagementClientException.class.getName());
}
Also used : SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SecretType (org.wso2.carbon.identity.secret.mgt.core.model.SecretType)35 Secret (org.wso2.carbon.identity.secret.mgt.core.model.Secret)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 Test (org.testng.annotations.Test)22 ResolvedSecret (org.wso2.carbon.identity.secret.mgt.core.model.ResolvedSecret)14 SecretManagementException (org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException)11 NamedJdbcTemplate (org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate)7 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)5 Timestamp (java.sql.Timestamp)4 Date (java.util.Date)4 List (java.util.List)4 CryptoException (org.wso2.carbon.core.util.CryptoException)4 TransactionException (org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException)4 StringUtils (org.apache.commons.lang.StringUtils)3 Log (org.apache.commons.logging.Log)3 LogFactory (org.apache.commons.logging.LogFactory)3 SecretResponse (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse)3 SecretTypeResponse (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretTypeResponse)3 Secrets (org.wso2.carbon.identity.secret.mgt.core.model.Secrets)3 URI (java.net.URI)2