use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class OAuth2Authentication method getTokenContext.
@Override
public TokenContext getTokenContext(String authToken) throws KustvaktException {
AccessToken accessToken = accessDao.retrieveAccessToken(authToken);
if (accessToken.isRevoked()) {
throw new KustvaktException(StatusCodes.INVALID_ACCESS_TOKEN, "Access token is invalid");
}
String scopes = scopeService.convertAccessScopesToString(accessToken.getScopes());
TokenContext c = new TokenContext();
c.setUsername(accessToken.getUserId());
c.setExpirationTime(accessToken.getExpiryDate().toInstant().toEpochMilli());
c.setToken(authToken);
c.setTokenType(TokenType.BEARER);
c.addContextParameter(Attributes.SCOPE, scopes);
c.setAuthenticationTime(accessToken.getUserAuthenticationTime());
return c;
}
use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.
the class PiwikFilter method filter.
@Override
public ContainerRequest filter(ContainerRequest request) {
if (ENABLED) {
try {
TokenContext context = (TokenContext) request.getUserPrincipal();
if (context.getUsername() != null) {
// since this is cached, not very expensive!
User user = authenticationManager.getUser(context.getUsername());
Userdata data = authenticationManager.getUserData(user, UserSettingProcessor.class);
if ((Boolean) data.get(Attributes.COLLECT_AUDITING_DATA))
customVars.put("username", context.getUsername());
}
} catch (KustvaktException | UnsupportedOperationException e) {
// do nothing
}
send(request);
}
return request;
}
Aggregations