-
-
Notifications
You must be signed in to change notification settings - Fork 615
XWIKI-23915: Introduce a rest endpoint for user information #5199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
| package org.xwiki.rest.resources.user; | ||
|
|
||
| import javax.ws.rs.GET; | ||
| import javax.ws.rs.Path; | ||
| import javax.ws.rs.PathParam; | ||
| import javax.ws.rs.QueryParam; | ||
|
|
||
| import org.xwiki.rest.XWikiRestException; | ||
| import org.xwiki.rest.model.jaxb.User; | ||
|
|
||
| /** | ||
| * @since 18.2.0RC1 | ||
| * @version $Id$ | ||
| */ | ||
| @Path("/wikis/{wikiName}/user") | ||
| public interface CurrentUserResource | ||
| { | ||
| @GET User getUser( | ||
| @PathParam("wikiName") String wikiName, | ||
| @QueryParam("preferences") boolean preferences | ||
| ) throws XWikiRestException; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
| package org.xwiki.rest.resources.user; | ||
|
|
||
| import javax.ws.rs.GET; | ||
| import javax.ws.rs.Path; | ||
| import javax.ws.rs.PathParam; | ||
| import javax.ws.rs.QueryParam; | ||
|
|
||
| import org.xwiki.rest.XWikiRestException; | ||
| import org.xwiki.rest.model.jaxb.User; | ||
|
|
||
| /** | ||
| * @since 18.2.0RC1 | ||
| * @version $Id$ | ||
| */ | ||
| @Path("/wikis/{wikiName}/users/{userId}") | ||
| public interface UserResource | ||
| { | ||
| @GET User getUser( | ||
| @PathParam("wikiName") String wikiName, | ||
| @PathParam("userId") String userId, | ||
| @QueryParam("preferences") boolean preferences | ||
| ) throws XWikiRestException; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
| package org.xwiki.rest.resources.user; | ||
|
|
||
| import javax.ws.rs.DefaultValue; | ||
| import javax.ws.rs.GET; | ||
| import javax.ws.rs.Path; | ||
| import javax.ws.rs.PathParam; | ||
| import javax.ws.rs.QueryParam; | ||
|
|
||
| import org.xwiki.rest.XWikiRestException; | ||
| import org.xwiki.rest.model.jaxb.Users; | ||
|
|
||
| /** | ||
| * @since 18.2.0RC1 | ||
| * @version $Id$ | ||
| */ | ||
| @Path("/wikis/{wikiName}/users") | ||
| public interface UsersResource | ||
| { | ||
| @GET Users getUsers( | ||
| @PathParam("wikiName") String wikiName, | ||
| @QueryParam("start") @DefaultValue("0") Integer start, | ||
| @QueryParam("number") Integer number | ||
| ) throws XWikiRestException; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,6 +177,11 @@ public final class Relations | |
| */ | ||
| public static final String CLIENT = "http://www.xwiki.org/rel/client"; | ||
|
|
||
| /** | ||
| * Relation for links pointing to the user. | ||
| */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
| public static final String USER = "http://www.xwiki.org/rel/user"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you actually use it? Btw I'm surprised: there should be a dependency to xwiki-platform-user-rest somewhere if you want the model to reuse the UserSummary in some existing REST resources no?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use it only in the users list endpoint, to point to the full user profile endpoint. |
||
|
|
||
| /** | ||
| * Avoid instantiation. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
| package org.xwiki.rest; | ||
|
|
||
| import java.net.URI; | ||
|
|
||
| import org.xwiki.component.annotation.Role; | ||
| import org.xwiki.rest.model.jaxb.User; | ||
| import org.xwiki.rest.model.jaxb.UserSummary; | ||
| import org.xwiki.user.UserReference; | ||
|
|
||
| import com.xpn.xwiki.XWikiException; | ||
|
|
||
| /** | ||
| * A component that converts a User Reference to REST API model elements. | ||
| * | ||
| * @since 18.2.0RC1 | ||
| * @version $Id$ | ||
| */ | ||
| @Role | ||
| public interface UserReferenceModelSerializer | ||
| { | ||
| /** | ||
| * Return a summary of the user's information to include in, e.g., user lists. | ||
| * | ||
| * @param baseUri the base URL of the current instance | ||
| * @param userId the id of the user (e.g., "wikiName:Space.Page" for a user stored as a document) | ||
| * @param userReference the user reference to serialize | ||
| * @return a user summary | ||
| * @throws XWikiException if there was a problem during serialization | ||
| */ | ||
| UserSummary toRestUserSummary(URI baseUri, String userId, UserReference userReference) throws XWikiException; | ||
|
|
||
| /** | ||
| * Return all the information available on the user. | ||
| * | ||
| * @param baseUri the base URL of the current instance | ||
| * @param userId the id of the user (e.g., "wikiName:Space.Page" for a user stored as a document) | ||
| * @param userReference the user reference to serialize | ||
| * @param preferences whether to include user preferences in the output | ||
| * @return a user | ||
| * @throws XWikiException if there was a problem during serialization | ||
| */ | ||
| User toRestUser(URI baseUri, String userId, UserReference userReference, boolean preferences) throws XWikiException; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
| package org.xwiki.rest.internal.resources.user; | ||
|
|
||
| import java.net.URI; | ||
|
|
||
| import javax.ws.rs.ServerErrorException; | ||
| import javax.ws.rs.WebApplicationException; | ||
| import javax.ws.rs.core.Response; | ||
|
|
||
| import org.xwiki.component.annotation.Component; | ||
| import org.xwiki.localization.ContextualLocalizationManager; | ||
| import org.xwiki.model.reference.DocumentReference; | ||
| import org.xwiki.rest.UserReferenceModelSerializer; | ||
| import org.xwiki.rest.XWikiResource; | ||
| import org.xwiki.rest.XWikiRestException; | ||
| import org.xwiki.rest.model.jaxb.User; | ||
| import org.xwiki.rest.resources.user.CurrentUserResource; | ||
| import org.xwiki.user.UserReference; | ||
| import org.xwiki.user.UserReferenceResolver; | ||
| import org.xwiki.user.UserReferenceSerializer; | ||
|
|
||
| import com.xpn.xwiki.XWikiException; | ||
|
|
||
| import jakarta.inject.Inject; | ||
| import jakarta.inject.Named; | ||
| import jakarta.inject.Provider; | ||
|
|
||
| /** | ||
| * @since 18.2.0RC1 | ||
| * @version $Id$ | ||
| */ | ||
| @Component | ||
| @Named("org.xwiki.rest.internal.resources.user.CurrentUserResourceImpl") | ||
| public class CurrentUserResourceImpl extends XWikiResource implements CurrentUserResource | ||
| { | ||
| @Inject | ||
| @Named("document") | ||
| private UserReferenceResolver<DocumentReference> userReferenceResolver; | ||
|
|
||
| @Inject | ||
| private UserReferenceSerializer<String> stringUserReferenceSerializer; | ||
|
|
||
| @Inject | ||
| private Provider<UserReferenceModelSerializer> userReferenceModelSerializerProvider; | ||
|
|
||
| @Inject | ||
| private ContextualLocalizationManager contextualLocalizationManager; | ||
|
|
||
| @Override | ||
| public User getUser(String wikiName, boolean preferences) throws XWikiRestException | ||
| { | ||
| URI baseUri = this.uriInfo.getBaseUri(); | ||
|
|
||
| // Fail if we don't have a serializer for the current user store. | ||
| UserReferenceModelSerializer userReferenceModelSerializer = this.userReferenceModelSerializerProvider.get(); | ||
| if (userReferenceModelSerializer == null) { | ||
| throw new ServerErrorException(Response.status(Response.Status.NOT_IMPLEMENTED).entity( | ||
| this.contextualLocalizationManager.getTranslationPlain( | ||
| "rest.exception.userResource.unsupportedStore")).build()); | ||
| } | ||
|
|
||
| DocumentReference userDocumentReference = this.xcontextProvider.get().getUserReference(); | ||
| if (userDocumentReference == null) { | ||
| throw new WebApplicationException(Response.Status.UNAUTHORIZED); | ||
| } | ||
|
|
||
| try { | ||
| UserReference userReference = this.userReferenceResolver.resolve(userDocumentReference); | ||
|
|
||
| return userReferenceModelSerializer.toRestUser(baseUri, | ||
| this.stringUserReferenceSerializer.serialize(userReference), userReference, preferences); | ||
| } catch (XWikiException e) { | ||
| throw new XWikiRestException(e); | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.