use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method collapsePanel.
/**
* Collapse panel on frontend - persist updated identity profile setting.
*
* @param backendId identity codeable identifier
* @param panelId panel identitfier ~ uiKey
* @return updated profile
* @since 11.2.0
*/
@RequestMapping(value = "/{backendId}/profile/panels/{panelId}/collapse", method = RequestMethod.PATCH)
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.PROFILE_UPDATE + "')")
@ApiOperation(value = "Collapse panel", nickname = "collapsePanel", tags = { IdmIdentityController.TAG }, notes = "Collapse panel - persist updated identity profile setting.", authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_UPDATE, description = "") }) })
public ResponseEntity<?> collapsePanel(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Panel identifier - uiKey.", required = true) @PathVariable @NotNull String panelId) {
IdmIdentityDto identity = getDto(backendId);
if (identity == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
IdmProfileDto profile = profileService.collapsePanel(backendId, panelId, IdmBasePermission.UPDATE);
//
// refresh with permissions are needed
IdmProfileFilter context = new IdmProfileFilter();
context.setAddPermissions(true);
profile = profileController.getService().get(profile, context, IdmBasePermission.READ);
//
return new ResponseEntity<>(profileController.toResource(profile), HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method expandPanel.
/**
* Expand panel on frontend - persist updated identity profile setting.
*
* @param backendId identity codeable identifier
* @param panelId panel identitfier ~ uiKey
* @return updated profile
* @since 11.2.0
*/
@RequestMapping(value = "/{backendId}/profile/panels/{panelId}/expand", method = RequestMethod.PATCH)
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.PROFILE_UPDATE + "')")
@ApiOperation(value = "Expand panel", nickname = "expandPanel", tags = { IdmIdentityController.TAG }, notes = "Expand panel - persist updated identity profile setting.", authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_UPDATE, description = "") }) })
public ResponseEntity<?> expandPanel(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Panel identifier - uiKey.", required = true) @PathVariable @NotNull String panelId) {
IdmIdentityDto identity = getDto(backendId);
if (identity == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
IdmProfileDto profile = profileService.expandPanel(backendId, panelId, IdmBasePermission.UPDATE);
//
// refresh with permissions are needed
IdmProfileFilter context = new IdmProfileFilter();
context.setAddPermissions(true);
profile = profileController.getService().get(profile, context, IdmBasePermission.READ);
//
return new ResponseEntity<>(profileController.toResource(profile), HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method getProfileImage.
/**
* Returns profile image attachment from identity
*
* @return
* @since 9.0.0
*/
@RequestMapping(value = "/{backendId}/profile/image", method = RequestMethod.GET)
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.PROFILE_AUTOCOMPLETE + "')")
@ApiOperation(value = "Profile image", nickname = "getProfileImage", tags = { IdmIdentityController.TAG }, notes = "Returns input stream to identity profile image.", authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_AUTOCOMPLETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_AUTOCOMPLETE, description = "") }) })
public ResponseEntity<InputStreamResource> getProfileImage(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable String backendId) {
IdmProfileDto profile = profileService.findOneByIdentity(backendId, IdmBasePermission.AUTOCOMPLETE);
if (profile == null) {
return new ResponseEntity<InputStreamResource>(HttpStatus.NO_CONTENT);
}
if (profile.getImage() == null) {
return new ResponseEntity<InputStreamResource>(HttpStatus.NO_CONTENT);
}
IdmAttachmentDto attachment = attachmentManager.get(profile.getImage());
String mimetype = attachment.getMimetype();
InputStream is = attachmentManager.getAttachmentData(attachment.getId());
try {
BodyBuilder response = ResponseEntity.ok().contentLength(is.available()).header(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=\"%s\"", attachment.getName()));
// append media type, if it's filled
if (StringUtils.isNotBlank(mimetype)) {
response = response.contentType(MediaType.valueOf(attachment.getMimetype()));
}
//
return response.body(new InputStreamResource(is));
} catch (IOException e) {
throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, e);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method uploadProfileImage.
/**
* Upload new profile picture
*
* @param backendId
* @param fileName
* @param data
* @return
* @throws IOException
* @since 9.0.0
*/
@ResponseBody
@RequestMapping(value = "/{backendId}/profile/image", method = RequestMethod.POST)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.PROFILE_UPDATE + "')")
@ApiOperation(value = "Update profile picture", nickname = "postProfilePicture", tags = { IdmProfileController.TAG }, notes = "Upload new profile image", authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_UPDATE, description = "") }) })
public ResponseEntity<?> uploadProfileImage(@ApiParam(value = "Identity's uuid identifier or username.", required = false) @PathVariable String backendId, @RequestParam(required = true, name = "fileName") @NotNull String fileName, @RequestParam(required = true, name = "data") MultipartFile data) {
IdmProfileDto profile = profileService.findOrCreateByIdentity(backendId, IdmBasePermission.READ, IdmBasePermission.CREATE);
//
profile = profileService.uploadImage(profile, data, fileName, IdmBasePermission.UPDATE);
// refresh with permissions are needed
IdmProfileFilter context = new IdmProfileFilter();
context.setAddPermissions(true);
profile = profileController.getService().get(profile, context, IdmBasePermission.READ);
//
return new ResponseEntity<>(profileController.toResource(profile), HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method getProfilePermissions.
/**
* Returns profile permissions
*
* @return
* @since 9.0.0
*/
@ResponseBody
@RequestMapping(value = "/{backendId}/profile/permissions", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.PROFILE_READ + "')" + " or hasAuthority('" + CoreGroupPermission.PROFILE_AUTOCOMPLETE + "')")
@ApiOperation(value = "What logged identity can do with identity profile", nickname = "getPermissionsOnIdentityProfile", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_READ, description = ""), @AuthorizationScope(scope = CoreGroupPermission.PROFILE_AUTOCOMPLETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_READ, description = ""), @AuthorizationScope(scope = CoreGroupPermission.PROFILE_AUTOCOMPLETE, description = "") }) })
public Set<String> getProfilePermissions(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId) {
IdmProfileDto profile = profileService.findOneByIdentity(backendId);
if (profile == null) {
IdmIdentityDto identity = (IdmIdentityDto) getLookupService().lookupDto(IdmIdentityDto.class, backendId);
if (identity == null) {
throw new EntityNotFoundException(IdmIdentity.class, backendId);
}
profile = new IdmProfileDto();
profile.setIdentity(identity.getId());
}
// profile can be null (create)
return profileController.getService().getPermissions(profile);
}
Aggregations