|
|
|
@ -1,14 +1,15 @@
|
|
|
|
|
package org.gcube.keycloak.avatar;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.jboss.resteasy.annotations.cache.NoCache;
|
|
|
|
|
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
|
|
|
|
|
import org.jboss.resteasy.reactive.RestForm;
|
|
|
|
|
import org.jboss.resteasy.reactive.multipart.FileUpload;
|
|
|
|
|
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
|
|
|
|
import org.keycloak.http.HttpRequest;
|
|
|
|
|
import org.keycloak.models.KeycloakSession;
|
|
|
|
|
import org.keycloak.services.resources.Cors;
|
|
|
|
|
import org.keycloak.services.cors.Cors;
|
|
|
|
|
import org.keycloak.services.resources.RealmsResource;
|
|
|
|
|
|
|
|
|
|
import jakarta.ws.rs.Consumes;
|
|
|
|
@ -74,7 +75,7 @@ public class AvatarResource extends AbstractAvatarResource {
|
|
|
|
|
@POST
|
|
|
|
|
@NoCache
|
|
|
|
|
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
|
|
|
|
public Response uploadCurrentUserAvatarImage(MultipartFormDataInput input, @Context UriInfo uriInfo) {
|
|
|
|
|
public Response uploadCurrentUserAvatarImage(@RestForm(AVATAR_IMAGE_PARAMETER) FileUpload image, @Context UriInfo uriInfo) {
|
|
|
|
|
if (auth == null) {
|
|
|
|
|
throw new NotAuthorizedException("Bearer");
|
|
|
|
|
}
|
|
|
|
@ -86,9 +87,7 @@ public class AvatarResource extends AbstractAvatarResource {
|
|
|
|
|
logger.debugf("Uploading new avatar for user %s in realm %s", auth.getUser(), auth.getSession().getRealm());
|
|
|
|
|
Response response = null;
|
|
|
|
|
try {
|
|
|
|
|
InputStream imageInputStream = input.getFormDataPart(AVATAR_IMAGE_PARAMETER, InputStream.class, null);
|
|
|
|
|
|
|
|
|
|
saveUserImage(auth.getSession().getRealm(), auth.getUser(), imageInputStream);
|
|
|
|
|
saveUserImage(auth.getSession().getRealm(), auth.getUser(), Files.newInputStream(image.uploadedFile()));
|
|
|
|
|
|
|
|
|
|
if (uriInfo.getQueryParameters().containsKey("account")) {
|
|
|
|
|
UriBuilder uriBuilder = RealmsResource.accountUrl(session.getContext().getUri().getBaseUriBuilder());
|
|
|
|
|