use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class PermissionsFilter method filter.
protected void filter(Permissions permissions, ContainerRequestContext requestContext) {
if (permissions != null && permissions.value().length > 0) {
Principal principal = securityContext.getUserPrincipal();
if (principal != null) {
String username = principal.getName();
for (Permission permission : permissions.value()) {
Map<String, char[]> memberPermissions;
switch(permission.value().getScope()) {
case ORGANIZATION:
memberPermissions = membershipService.getUserMemberPermissions(MembershipReferenceType.ORGANIZATION, GraviteeContext.getCurrentOrganization(), username);
if (roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls())) {
return;
}
break;
case ENVIRONMENT:
memberPermissions = membershipService.getUserMemberPermissions(MembershipReferenceType.ENVIRONMENT, GraviteeContext.getCurrentEnvironment(), username);
if (roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls())) {
return;
}
break;
case APPLICATION:
ApplicationEntity application = getApplication(requestContext);
memberPermissions = membershipService.getUserMemberPermissions(application, username);
if (roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls())) {
return;
}
break;
case API:
ApiEntity api = getApi(requestContext);
memberPermissions = membershipService.getUserMemberPermissions(api, username);
if (roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls())) {
return;
}
break;
case GROUP:
GroupEntity group = getGroup(requestContext);
memberPermissions = membershipService.getUserMemberPermissions(group, username);
if (roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls())) {
return;
}
break;
default:
sendSecurityError();
}
}
}
sendSecurityError();
}
}
use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationResourceAdminTest method shouldRestoreApplication.
@Test
public void shouldRestoreApplication() {
reset(applicationService);
ApplicationEntity restored = new ApplicationEntity();
restored.setId("my-beautiful-application");
doReturn(restored).when(applicationService).restore(any());
final Response response = envTarget("_restore").request().post(null);
assertEquals(HttpStatusCode.OK_200, response.getStatus());
assertEquals(response.readEntity(ApplicationEntity.class).getId(), "my-beautiful-application");
}
use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMapper method convert.
public Application convert(ApplicationEntity applicationEntity, UriInfo uriInfo) {
final Application application = new Application();
application.setApplicationType(applicationEntity.getType());
application.setCreatedAt(applicationEntity.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
application.setDescription(applicationEntity.getDescription());
Set<String> groupEntities = applicationEntity.getGroups();
if (groupEntities != null && !groupEntities.isEmpty()) {
List<Group> groups = groupEntities.stream().map(groupService::findById).map(groupEntity -> new Group().id(groupEntity.getId()).name(groupEntity.getName())).collect(Collectors.toList());
application.setGroups(groups);
}
application.setId(applicationEntity.getId());
application.setName(applicationEntity.getName());
UserEntity primaryOwnerUserEntity = userService.findById(applicationEntity.getPrimaryOwner().getId());
User owner = userMapper.convert(primaryOwnerUserEntity);
owner.setLinks(userMapper.computeUserLinks(usersURL(uriInfo.getBaseUriBuilder(), primaryOwnerUserEntity.getId()), primaryOwnerUserEntity.getUpdatedAt()));
application.setOwner(owner);
application.setUpdatedAt(applicationEntity.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC));
application.setPicture(applicationEntity.getPicture());
application.setBackground(applicationEntity.getBackground());
final ApplicationSettings applicationEntitySettings = applicationEntity.getSettings();
if (applicationEntitySettings != null) {
io.gravitee.rest.api.portal.rest.model.ApplicationSettings appSettings = new io.gravitee.rest.api.portal.rest.model.ApplicationSettings();
final SimpleApplicationSettings simpleAppEntitySettings = applicationEntitySettings.getApp();
if (simpleAppEntitySettings != null) {
appSettings.app(new io.gravitee.rest.api.portal.rest.model.SimpleApplicationSettings().clientId(simpleAppEntitySettings.getClientId()).type(simpleAppEntitySettings.getType()));
application.setHasClientId(simpleAppEntitySettings.getClientId() != null);
} else {
final OAuthClientSettings oAuthClientEntitySettings = applicationEntitySettings.getoAuthClient();
appSettings.oauth(new io.gravitee.rest.api.portal.rest.model.OAuthClientSettings().applicationType(oAuthClientEntitySettings.getApplicationType()).clientId(oAuthClientEntitySettings.getClientId()).clientSecret(oAuthClientEntitySettings.getClientSecret()).clientUri(oAuthClientEntitySettings.getClientUri()).logoUri(oAuthClientEntitySettings.getLogoUri()).grantTypes(oAuthClientEntitySettings.getGrantTypes()).redirectUris(oAuthClientEntitySettings.getRedirectUris()).responseTypes(oAuthClientEntitySettings.getResponseTypes()).renewClientSecretSupported(oAuthClientEntitySettings.isRenewClientSecretSupported()));
application.setHasClientId(oAuthClientEntitySettings.getClientId() != null);
}
application.setSettings(appSettings);
}
return application;
}
use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class PermissionsFilter method hasPermission.
protected boolean hasPermission(ContainerRequestContext requestContext, String username, Permission permission) {
Map<String, char[]> memberPermissions;
switch(permission.value().getScope()) {
case ORGANIZATION:
memberPermissions = membershipService.getUserMemberPermissions(MembershipReferenceType.ORGANIZATION, GraviteeContext.getCurrentOrganization(), username);
return roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls());
case ENVIRONMENT:
memberPermissions = membershipService.getUserMemberPermissions(MembershipReferenceType.ENVIRONMENT, GraviteeContext.getCurrentEnvironment(), username);
return roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls());
case APPLICATION:
ApplicationEntity application = getApplication(requestContext);
memberPermissions = membershipService.getUserMemberPermissions(application, username);
return roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls());
case API:
ApiEntity api = getApi(requestContext);
memberPermissions = membershipService.getUserMemberPermissions(api, username);
return roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls());
default:
sendSecurityError();
}
return false;
}
use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceImpl method create.
@Override
public AlertTriggerEntity create(String applicationId, NewAlertTriggerEntity alert) {
final ApplicationEntity application = applicationService.findById(applicationId);
alert.setName(generateAlertName(application, alert));
alert.setReferenceType(AlertReferenceType.APPLICATION);
alert.setReferenceId(application.getId());
alert.setSource("REQUEST");
alert.setSeverity(Trigger.Severity.INFO);
alert.setDampening(Dampening.strictCount(1));
Filter filter = StringCondition.equals("application", applicationId).build();
alert.setFilters(singletonList(filter));
final List<String> recipients = getNotificationRecipients(application.getId(), application.getGroups());
if (!CollectionUtils.isEmpty(recipients)) {
alert.setNotifications(createNotification(alert.getType(), recipients));
}
return alertService.create(alert);
}
Aggregations