Java tutorial
/* * mxisd - Matrix Identity Server Daemon * Copyright (C) 2018 Kamax Sarl * * https://www.kamax.io/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package io.kamax.mxisd.controller.profile.v1; import io.kamax.matrix.MatrixID; import io.kamax.matrix._MatrixID; import io.kamax.matrix.json.GsonUtil; import io.kamax.mxisd.profile.ProfileManager; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import static org.springframework.web.bind.annotation.RequestMethod.GET; @RestController @CrossOrigin @RequestMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public class ProfileInternalController { private final ProfileManager mgr; public ProfileInternalController(ProfileManager mgr) { this.mgr = mgr; } @RequestMapping(method = GET, path = "/_matrix-internal/profile/v1/{userId:.+}") public String getProfile(@PathVariable String userId) throws UnsupportedEncodingException { userId = URLDecoder.decode(userId, StandardCharsets.UTF_8.name()); _MatrixID mxId = MatrixID.asAcceptable(userId); return GsonUtil.get().toJson(GsonUtil.makeObj("roles", GsonUtil.asArray(mgr.getRoles(mxId)))); } }