use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class SecretDAOImpl method deleteSecretById.
@Override
public void deleteSecretById(String secretId, int tenantId) throws SecretManagementException {
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
try {
jdbcTemplate.executeUpdate(SQLConstants.DELETE_SECRET_BY_ID, preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_ID, secretId);
preparedStatement.setInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID, tenantId);
});
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_DELETE_SECRET, secretId, e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class SecretDAOImpl method deleteSecretByName.
@Override
public void deleteSecretByName(String name, String secretTypeId, int tenantId) throws SecretManagementException {
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
try {
jdbcTemplate.executeUpdate(SQLConstants.DELETE_SECRET, preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SECRET_NAME, name);
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_TYPE, secretTypeId);
preparedStatement.setInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID, tenantId);
});
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_DELETE_SECRET, e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project identity-inbound-auth-oauth by wso2-extensions.
the class AccessTokenDAOImpl method getAccessTokensByBindingRef.
@Override
public Set<AccessTokenDO> getAccessTokensByBindingRef(String bindingRef) throws IdentityOAuth2Exception {
if (log.isDebugEnabled()) {
log.debug("Retrieving active access tokens issued with binding reference : " + bindingRef);
}
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
String sqlQuery = GET_ACCESS_TOKENS_BY_BINDING_REFERENCE;
Map<String, AccessTokenDO> tokenMap = new HashMap<>();
jdbcTemplate.executeQuery(sqlQuery, rethrowRowMapper((resultSet, i) -> {
String token = getPersistenceProcessor().getPreprocessedAccessTokenIdentifier(resultSet.getString("ACCESS_TOKEN"));
AccessTokenDO accessTokenDO = new AccessTokenDO();
if (tokenMap.containsKey(token)) {
AccessTokenDO tokenObj = tokenMap.get(token);
String[] previousScope = tokenObj.getScope();
String[] newScope = new String[tokenObj.getScope().length + 1];
System.arraycopy(previousScope, 0, newScope, 0, previousScope.length);
newScope[previousScope.length] = resultSet.getString("TOKEN_SCOPE");
tokenObj.setScope(newScope);
} else {
String consumerKey = resultSet.getString("CONSUMER_KEY");
String tokenScope = resultSet.getString("TOKEN_SCOPE");
String refreshToken = resultSet.getString("REFRESH_TOKEN");
String tokenId = resultSet.getString("TOKEN_ID");
int tenantId = resultSet.getInt("TENANT_ID");
String authzUser = resultSet.getString("AUTHZ_USER");
String userDomain = resultSet.getString("USER_DOMAIN");
String authenticatedIDPName = resultSet.getString("NAME");
AuthenticatedUser user = OAuth2Util.createAuthenticatedUser(authzUser, userDomain, OAuth2Util.getTenantDomain(tenantId), authenticatedIDPName);
Timestamp issuedTime = resultSet.getTimestamp("TIME_CREATED", Calendar.getInstance(TimeZone.getTimeZone(UTC)));
Timestamp refreshTokenIssuedTime = resultSet.getTimestamp("REFRESH_TOKEN_TIME_CREATED", Calendar.getInstance(TimeZone.getTimeZone(UTC)));
long validityPeriodInMillis = resultSet.getLong("VALIDITY_PERIOD");
long refreshTokenValidityPeriodMillis = resultSet.getLong("REFRESH_TOKEN_VALIDITY_PERIOD");
String tokenType = resultSet.getString("USER_TYPE");
String[] scope = OAuth2Util.buildScopeArray(tokenScope);
accessTokenDO.setAccessToken(token);
accessTokenDO.setConsumerKey(consumerKey);
accessTokenDO.setScope(scope);
accessTokenDO.setAuthzUser(user);
accessTokenDO.setTenantID(tenantId);
accessTokenDO.setRefreshToken(refreshToken);
accessTokenDO.setTokenId(tokenId);
accessTokenDO.setIssuedTime(issuedTime);
accessTokenDO.setRefreshTokenIssuedTime(refreshTokenIssuedTime);
accessTokenDO.setValidityPeriod(validityPeriodInMillis);
accessTokenDO.setRefreshTokenValidityPeriod(refreshTokenValidityPeriodMillis);
accessTokenDO.setTokenType(tokenType);
tokenMap.put(token, accessTokenDO);
}
return Collections.emptySet();
}), (PreparedStatement preparedStatement) -> {
preparedStatement.setString(1, bindingRef);
});
return new HashSet<>(tokenMap.values());
} catch (DataAccessException e) {
throw new IdentityOAuth2Exception("Error occurred while retrieving access tokens.", e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project identity-inbound-auth-oauth by wso2-extensions.
the class AccessTokenDAOImpl method getAccessTokensByBindingRef.
public Set<AccessTokenDO> getAccessTokensByBindingRef(AuthenticatedUser user, String bindingRef) throws IdentityOAuth2Exception {
if (log.isDebugEnabled()) {
log.debug("Retrieving active access tokens issued to user, " + user.getUserName() + " with binding " + "reference " + bindingRef);
}
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
String sqlQuery = OAuth2Util.getTokenPartitionedSqlByUserStore(SQLQueries.GET_ACCESS_TOKENS_BY_BINDING_REFERENCE_AND_USER, user.getUserStoreDomain());
int tenantId = OAuth2Util.getTenantId(user.getTenantDomain());
Map<String, AccessTokenDO> tokenMap = new HashMap<>();
jdbcTemplate.executeQuery(sqlQuery, rethrowRowMapper((resultSet, i) -> {
String token = getPersistenceProcessor().getPreprocessedAccessTokenIdentifier(resultSet.getString("ACCESS_TOKEN"));
AccessTokenDO accessTokenDO = new AccessTokenDO();
if (tokenMap.containsKey(token)) {
AccessTokenDO tokenObj = tokenMap.get(token);
String[] previousScope = tokenObj.getScope();
String[] newSope = new String[tokenObj.getScope().length + 1];
System.arraycopy(previousScope, 0, newSope, 0, previousScope.length);
newSope[previousScope.length] = resultSet.getString(2);
tokenObj.setScope(newSope);
} else {
String consumerKey = resultSet.getString("CONSUMER_KEY");
String tokenScope = resultSet.getString("TOKEN_SCOPE");
String refreshToken = resultSet.getString("REFRESH_TOKEN");
String tokenId = resultSet.getString("TOKEN_ID");
Timestamp issuedTime = resultSet.getTimestamp("TIME_CREATED", Calendar.getInstance(TimeZone.getTimeZone(UTC)));
Timestamp refreshTokenIssuedTime = resultSet.getTimestamp("REFRESH_TOKEN_TIME_CREATED", Calendar.getInstance(TimeZone.getTimeZone(UTC)));
long validityPeriodInMillis = resultSet.getLong("VALIDITY_PERIOD");
long refreshTokenValidityPeriodMillis = resultSet.getLong("REFRESH_TOKEN_VALIDITY_PERIOD");
String tokenType = resultSet.getString("USER_TYPE");
String[] scope = OAuth2Util.buildScopeArray(tokenScope);
accessTokenDO.setAccessToken(token);
accessTokenDO.setConsumerKey(consumerKey);
accessTokenDO.setScope(scope);
accessTokenDO.setAuthzUser(user);
accessTokenDO.setTenantID(tenantId);
accessTokenDO.setRefreshToken(refreshToken);
accessTokenDO.setTokenId(tokenId);
accessTokenDO.setIssuedTime(issuedTime);
accessTokenDO.setRefreshTokenIssuedTime(refreshTokenIssuedTime);
accessTokenDO.setValidityPeriod(validityPeriodInMillis);
accessTokenDO.setRefreshTokenValidityPeriod(refreshTokenValidityPeriodMillis);
accessTokenDO.setTokenType(tokenType);
tokenMap.put(token, accessTokenDO);
}
return null;
}), (PreparedStatement preparedStatement) -> {
preparedStatement.setString(1, user.getUserName());
preparedStatement.setInt(2, tenantId);
preparedStatement.setString(3, user.getUserStoreDomain());
preparedStatement.setString(4, bindingRef);
});
return new HashSet<>(tokenMap.values());
} catch (DataAccessException e) {
throw new IdentityOAuth2Exception("Error occurred while retrieving access tokens.", e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopeClaimMappingDAOImpl method updateScope.
/**
* To add new claims for an existing scope.
*
* @param scope Updated scope name.
* @param tenantId Tenant Id.
* @throws IdentityOAuth2Exception If an error occurs when adding a new claim for a scope.
*/
@Override
public void updateScope(ScopeDTO scope, int tenantId) throws IdentityOAuth2Exception {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
int scopeId = getScopeId(scope.getName(), tenantId);
if (scopeId != Oauth2ScopeConstants.INVALID_SCOPE_ID) {
updateScopeDetails(scope, jdbcTemplate, scopeId);
deleteClaimMappings(scopeId, jdbcTemplate);
Set<String> claimsSet = new HashSet<>(Arrays.asList(scope.getClaim()));
insertClaims(tenantId, scopeId, claimsSet);
}
} catch (DataAccessException e) {
throw new IdentityOAuth2Exception("Error while updating the scope: " + scope.getName() + " and it's related claims.", e);
}
}
Aggregations