Search in sources :

Example 26 with IdmProfileDto

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);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) ResponseEntity(org.springframework.http.ResponseEntity) IdmProfileFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 27 with IdmProfileDto

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);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) ResponseEntity(org.springframework.http.ResponseEntity) IdmProfileFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 28 with IdmProfileDto

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);
    }
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) ResponseEntity(org.springframework.http.ResponseEntity) InputStream(java.io.InputStream) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) BodyBuilder(org.springframework.http.ResponseEntity.BodyBuilder) InputStreamResource(org.springframework.core.io.InputStreamResource) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 29 with IdmProfileDto

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);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) ResponseEntity(org.springframework.http.ResponseEntity) IdmProfileFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with IdmProfileDto

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);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IdmProfileDto (eu.bcvsolutions.idm.core.api.dto.IdmProfileDto)32 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)22 Test (org.junit.Test)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)6 ApiOperation (io.swagger.annotations.ApiOperation)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 IdmProfileFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter)5 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)5 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 ResponseEntity (org.springframework.http.ResponseEntity)5 Transactional (org.springframework.transaction.annotation.Transactional)4 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3