use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class RoleServiceImpl method findById.
@Override
public RoleEntity findById(final RoleScope scope, final String name) {
try {
LOGGER.debug("Find Role by id");
Optional<Role> role = roleRepository.findById(scope, name);
if (!role.isPresent()) {
throw new RoleNotFoundException(scope, name);
}
return convert(role.get());
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find a role : {} {}", scope, name, ex);
throw new TechnicalManagementException("An error occurs while trying to find a role : " + scope + " " + name, ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class RoleServiceImpl method findDefaultRoleByScopes.
@Override
public List<RoleEntity> findDefaultRoleByScopes(RoleScope... scopes) {
try {
LOGGER.debug("Find default Roles by scope");
List<RoleEntity> roles = new ArrayList<>();
for (RoleScope scope : scopes) {
roles.addAll(roleRepository.findByScope(scope).stream().filter(Role::isDefaultRole).map(this::convert).collect(Collectors.toList()));
}
return roles;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find default roles by scope", ex);
throw new TechnicalManagementException("An error occurs while trying to find default roles by scope", ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class RoleServiceImpl method createOrUpdateSystemRoles.
@Override
public void createOrUpdateSystemRoles() {
try {
// MANAGEMENT - ADMIN
createOrUpdateSystemRole(SystemRole.ADMIN, RoleScope.MANAGEMENT, io.gravitee.management.model.permissions.RoleScope.MANAGEMENT, ManagementPermission.values());
// PORTAL - ADMIN
createOrUpdateSystemRole(SystemRole.ADMIN, RoleScope.PORTAL, io.gravitee.management.model.permissions.RoleScope.PORTAL, PortalPermission.values());
// API - PRIMARY_OWNER
createOrUpdateSystemRole(SystemRole.PRIMARY_OWNER, RoleScope.API, io.gravitee.management.model.permissions.RoleScope.API, ApiPermission.values());
// APPLICATION - PRIMARY_OWNER
createOrUpdateSystemRole(SystemRole.PRIMARY_OWNER, RoleScope.APPLICATION, io.gravitee.management.model.permissions.RoleScope.APPLICATION, ApplicationPermission.values());
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create admin roles", ex);
throw new TechnicalManagementException("An error occurs while trying to create admin roles ", ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class ApiKeyServiceImpl method update.
@Override
public ApiKeyEntity update(ApiKeyEntity apiKeyEntity) {
try {
LOGGER.debug("Update API Key {}", apiKeyEntity.getKey());
Optional<ApiKey> optKey = apiKeyRepository.findById(apiKeyEntity.getKey());
if (!optKey.isPresent()) {
throw new ApiKeyNotFoundException();
}
ApiKey key = optKey.get();
setExpiration(apiKeyEntity.getExpireAt(), key);
return convert(key);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while updating an API Key {}", apiKeyEntity.getKey(), ex);
throw new TechnicalManagementException(String.format("An error occurs while updating an API Key %s", apiKeyEntity.getKey()), ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class ApiKeyServiceImpl method renew.
@Override
public ApiKeyEntity renew(String subscription) {
try {
LOGGER.debug("Renew API Key for subscription {}", subscription);
ApiKey newApiKey = generateForSubscription(subscription);
newApiKey = apiKeyRepository.create(newApiKey);
Instant expirationInst = newApiKey.getCreatedAt().toInstant().plus(Duration.ofHours(2));
Date expirationDate = Date.from(expirationInst);
// Previously generated keys should be set as revoked
// Get previously generated keys to set their expiration date
Set<ApiKey> oldKeys = apiKeyRepository.findBySubscription(subscription);
for (ApiKey oldKey : oldKeys) {
if (!oldKey.equals(newApiKey)) {
setExpiration(expirationDate, oldKey);
}
}
// TODO: Send a notification to the application owner
// Audit
final PlanEntity plan = planService.findById(newApiKey.getPlan());
auditService.createApiAuditLog(plan.getApis().iterator().next(), Collections.singletonMap(API_KEY, newApiKey.getKey()), APIKEY_RENEWED, newApiKey.getCreatedAt(), null, newApiKey);
return convert(newApiKey);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to renew an API Key for {}", subscription, ex);
throw new TechnicalManagementException(String.format("An error occurs while trying to renew an API Key for %s", subscription), ex);
}
}
Aggregations