Search in sources :

Example 1 with OsmAndProUser

use of net.osmand.server.WebSecurityConfiguration.OsmAndProUser in project OsmAnd-tools by osmandapp.

the class MapApiController method userInfo.

@GetMapping(path = { "/auth/info" }, produces = "application/json")
@ResponseBody
public String userInfo(java.security.Principal user) {
    if (user == null) {
        return gson.toJson(user);
    }
    if (user instanceof Authentication) {
        Object obj = ((Authentication) user).getPrincipal();
        // hide device accesscceToekn
        if (obj instanceof OsmAndProUser) {
            OsmAndProUser pu = (OsmAndProUser) ((Authentication) user).getPrincipal();
            obj = Collections.singletonMap("username", pu.getUsername());
        }
        return gson.toJson(obj);
    }
    return gson.toJson(null);
}
Also used : OsmAndProUser(net.osmand.server.WebSecurityConfiguration.OsmAndProUser) Authentication(org.springframework.security.core.Authentication) JsonObject(com.google.gson.JsonObject) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

JsonObject (com.google.gson.JsonObject)1 OsmAndProUser (net.osmand.server.WebSecurityConfiguration.OsmAndProUser)1 Authentication (org.springframework.security.core.Authentication)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1