use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class ShibbolethUserController method updateSettings.
@Deprecated
@POST
@Path("settings")
@Consumes({ MediaType.APPLICATION_JSON })
@ResourceFilters({ AuthenticationFilter.class, PiwikFilter.class, BlockingFilter.class })
public Response updateSettings(@Context SecurityContext context, @Context Locale locale, Map settings) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
if (settings == null)
return Response.notModified().build();
try {
User user = controller.getUser(ctx.getUsername());
if (User.UserFactory.isDemo(ctx.getUsername()))
return Response.notModified().build();
Userdata data = controller.getUserData(user, UserSettingProcessor.class);
// todo: check setting only within the scope of user settings permissions; not foundry range. Latter is part of
// frontend which only displays available foundries and
// SecurityManager.findbyId(us.getDefaultConstfoundry(), user, Foundry.class);
// SecurityManager.findbyId(us.getDefaultLemmafoundry(), user, Foundry.class);
// SecurityManager.findbyId(us.getDefaultPOSfoundry(), user, Foundry.class);
// SecurityManager.findbyId(us.getDefaultRelfoundry(), user, Foundry.class);
Userdata new_data = new UserSettingProcessor(user.getId());
new_data.readQuietly((Map<String, Object>) settings, false);
data.update(new_data);
controller.updateUserData(data);
} catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().build();
}
use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class ShibbolethUserController method updateQueries.
// fixme: if policy allows, foreign user might be allowed to change search!
@POST
@Path("queries")
@Consumes(MediaType.APPLICATION_JSON)
@ResourceFilters({ AuthenticationFilter.class, PiwikFilter.class, BlockingFilter.class })
public Response updateQueries(@Context SecurityContext context, String json) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
Collection<UserQuery> add = new HashSet<>();
try {
User user = controller.getUser(ctx.getUsername());
List<UserQuery> userQuieres = new ArrayList<>();
JsonNode nodes = JsonUtils.readTree(json);
Iterator<JsonNode> node = nodes.elements();
while (node.hasNext()) {
JsonNode cursor = node.next();
UserQuery query = new UserQuery(cursor.path("id").asInt(), user.getId());
query.setQueryLanguage(cursor.path("queryLanguage").asText());
query.setQuery(cursor.path("query").asText());
query.setDescription(cursor.path("description").asText());
userQuieres.add(query);
}
// 1: add all that are new, update all that are retained, delete the rest
// Set<UserQuery> resources = ResourceFinder
// .search(user, UserQuery.class);
//
// add.addAll(userQuieres);
// add.removeAll(resources);
// Collection<UserQuery> update = new HashSet<>(userQuieres);
// update.retainAll(resources);
// resources.removeAll(userQuieres);
//
// if (!update.isEmpty()) {
// resourceHandler.updateResources(user,
// update.toArray(new UserQuery[update.size()]));
// }
// if (!add.isEmpty()) {
// resourceHandler.storeResources(user,
// add.toArray(new UserQuery[add.size()]));
// }
// if (!resources.isEmpty()) {
// resourceHandler.deleteResources(user,
// resources.toArray(new UserQuery[resources.size()]));
// }
} catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
throw kustvaktResponseHandler.throwit(e);
}
try {
return Response.ok(JsonUtils.toJSON(add)).build();
} catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
}
}
use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class UserGroupController method addMemberRoles.
/**
* Adds roles of an active member of a user-group. Only user-group
* admins and system admins are allowed.
*
* @param securityContext
* @param groupName
* a group name
* @param memberUsername
* a username of a group member
* @param roleId
* a role id or multiple role ids
* @return if successful, HTTP response status OK
*/
@POST
@Path("@{groupName}/role/add")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response addMemberRoles(@Context SecurityContext securityContext, @PathParam("groupName") String groupName, @FormParam("memberUsername") String memberUsername, @FormParam("roleId") List<Integer> roleIds) {
TokenContext context = (TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.ADD_USER_GROUP_MEMBER_ROLE);
service.addMemberRoles(context.getUsername(), groupName, memberUsername, roleIds);
return Response.ok("SUCCESS").build();
} catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
}
}
use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class UserGroupController method subscribeToGroup.
/**
* Handles requests to accept membership invitation. Only invited
* users can subscribe to the corresponding user-group.
*
* @param securityContext
* @param groupName
* a group name
* @return if successful, HTTP response status OK
*/
@POST
@Path("@{groupName}/subscribe")
public Response subscribeToGroup(@Context SecurityContext securityContext, @PathParam("groupName") String groupName) {
TokenContext context = (TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.ADD_USER_GROUP_MEMBER);
service.acceptInvitation(groupName, context.getUsername());
return Response.ok("SUCCESS").build();
} catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
}
}
use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class UserGroupController method removeUserFromGroup.
/**
* Removes a user-group member. Group owner cannot be removed.
* Only group admins, system admins and the member himself can
* remove a member.
*
* @param securityContext
* @param memberUsername
* a username of a group member
* @param groupName
* a group name
* @return if successful, HTTP response status OK
*/
@DELETE
@Path("@{groupName}/~{memberUsername}")
public Response removeUserFromGroup(@Context SecurityContext securityContext, @PathParam("memberUsername") String memberUsername, @PathParam("groupName") String groupName) {
TokenContext context = (TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.DELETE_USER_GROUP_MEMBER);
service.deleteGroupMember(memberUsername, groupName, context.getUsername());
return Response.ok().build();
} catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
}
}
Aggregations