use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class UserSettingController method createDefaultSetting.
/**
* Creates a default setting of the given username.
* The setting inputs should be represented as pairs of keys and
* values (a map). The keys must only contains alphabets, numbers,
* hypens or underscores.
*
* @param context
* security context
* @param username
* username
* @param map
* the default setting
* @return status code 201 if a new resource is created, or 200 if
* an existing resource is edited.
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@ResourceFilters({ AuthenticationFilter.class, PiwikFilter.class, BlockingFilter.class })
public Response createDefaultSetting(@Context SecurityContext context, @PathParam("username") String username, Map<String, Object> map) {
TokenContext tokenContext = (TokenContext) context.getUserPrincipal();
try {
scopeService.verifyScope(tokenContext, OAuth2Scope.CREATE_DEFAULT_SETTING);
int statusCode = settingService.handlePutRequest(username, map, tokenContext.getUsername());
return Response.status(statusCode).build();
} catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
}
}
use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class UserSettingController method deleteDefaultSetting.
/**
* Deletes the default setting of the given username. If such a
* setting does not exists, no error will be thrown and response
* status 200 will be returned since the purpose of the request
* has been achieved.
*
* @param context
* @param username
* a username
* @return 200 if the request is successful
*/
@DELETE
@ResourceFilters({ AuthenticationFilter.class, PiwikFilter.class, BlockingFilter.class })
public Response deleteDefaultSetting(@Context SecurityContext context, @PathParam("username") String username) {
TokenContext tokenContext = (TokenContext) context.getUserPrincipal();
try {
scopeService.verifyScope(tokenContext, OAuth2Scope.DELETE_DEFAULT_SETTING);
settingService.deleteSetting(username, tokenContext.getUsername());
return Response.ok().build();
} catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
}
}
use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class VirtualCorpusController method deleteVCAccessById.
/**
* Only VCA Admins and system admins are allowed to delete a
* VC-access.
*
* <br /><br />
* Not allowed via third-party apps.
*
* @param securityContext
* @param accessId
* @return
*/
@DELETE
@Path("access/{accessId}")
public Response deleteVCAccessById(@Context SecurityContext securityContext, @PathParam("accessId") int accessId) {
TokenContext context = (TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.DELETE_VC_ACCESS);
service.deleteQueryAccess(accessId, context.getUsername());
} catch (KustvaktException 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 VirtualCorpusController method shareVC.
/**
* VC can only be shared with a group, not individuals.
* Only VCA admins are allowed to share VC and the VC must have
* been created by themselves.
*
* <br /><br />
* Not allowed via third-party apps.
*
* @param securityContext
* @param vcCreator
* the username of the vc creator
* @param vcName
* the name of the vc
* @param groupName
* the name of the group to share
* @return HTTP status 200, if successful
*/
@POST
@Path("~{vcCreator}/{vcName}/share/@{groupName}")
public Response shareVC(@Context SecurityContext securityContext, @PathParam("vcCreator") String vcCreator, @PathParam("vcName") String vcName, @PathParam("groupName") String groupName) {
TokenContext context = (TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.SHARE_VC);
service.shareQuery(context.getUsername(), vcCreator, vcName, groupName);
} catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
}
return Response.ok("SUCCESS").build();
}
use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class APIAuthentication method createTokenContext.
@Override
public TokenContext createTokenContext(User user, Map<String, Object> attr) throws KustvaktException {
TokenContext c = new TokenContext();
c.setUsername(user.getUsername());
SignedJWT jwt = signedToken.createJWT(user, attr);
try {
c.setExpirationTime(jwt.getJWTClaimsSet().getExpirationTime().getTime());
if (DEBUG) {
jlog.debug(jwt.getJWTClaimsSet().getClaim(Attributes.AUTHENTICATION_TIME));
}
Date authTime = jwt.getJWTClaimsSet().getDateClaim(Attributes.AUTHENTICATION_TIME);
ZonedDateTime time = ZonedDateTime.ofInstant(authTime.toInstant(), ZoneId.of(Attributes.DEFAULT_TIME_ZONE));
c.setAuthenticationTime(time);
} catch (ParseException e) {
throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT);
}
c.setTokenType(getTokenType());
c.setToken(jwt.serialize());
// id_tokens.put(new Element(c.getToken(), c));
return c;
}
Aggregations