Search in sources :

Example 61 with TokenContext

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;
}
Also used : TokenContext(de.ids_mannheim.korap.security.context.TokenContext) KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) AccessToken(de.ids_mannheim.korap.oauth2.entity.AccessToken)

Example 62 with TokenContext

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;
}
Also used : TokenContext(de.ids_mannheim.korap.security.context.TokenContext) User(de.ids_mannheim.korap.user.User) KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) Userdata(de.ids_mannheim.korap.user.Userdata)

Aggregations

TokenContext (de.ids_mannheim.korap.security.context.TokenContext)62 KustvaktException (de.ids_mannheim.korap.exceptions.KustvaktException)54 Path (javax.ws.rs.Path)40 Consumes (javax.ws.rs.Consumes)21 POST (javax.ws.rs.POST)19 User (de.ids_mannheim.korap.user.User)16 ResourceFilters (com.sun.jersey.spi.container.ResourceFilters)15 GET (javax.ws.rs.GET)11 KorAPUser (de.ids_mannheim.korap.user.KorAPUser)10 DELETE (javax.ws.rs.DELETE)10 Produces (javax.ws.rs.Produces)9 Userdata (de.ids_mannheim.korap.user.Userdata)5 ZonedDateTime (java.time.ZonedDateTime)5 HashMap (java.util.HashMap)4 PUT (javax.ws.rs.PUT)4 AuthorizationData (de.ids_mannheim.korap.authentication.http.AuthorizationData)3 FormRequestWrapper (de.ids_mannheim.korap.web.utils.FormRequestWrapper)3 HashSet (java.util.HashSet)3 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)3 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)3