Search in sources :

Example 21 with TokenContext

use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.

the class KustvaktAuthenticationManager method createTokenContext.

// getAccess
@Override
public TokenContext createTokenContext(User user, Map<String, Object> attr, TokenType type) throws KustvaktException {
    // use api token
    AuthenticationIface provider = getProvider(type, TokenType.API);
    // EM: not in the new DB
    // if (attr.get(Attributes.SCOPES) != null)
    // this.getUserData(user, UserDetails.class);
    TokenContext context = provider.createTokenContext(user, attr);
    if (context == null)
        throw new KustvaktException(StatusCodes.NOT_SUPPORTED);
    context.setUserAgent((String) attr.get(Attributes.USER_AGENT));
    context.setHostAddress(Attributes.HOST);
    return context;
}
Also used : TokenContext(de.ids_mannheim.korap.security.context.TokenContext) KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException)

Example 22 with TokenContext

use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.

the class DemoFilter method createContext.

private SecurityContext createContext() {
    TokenContext context = new TokenContext();
    String token = null;
    try {
        token = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("demo", "demo2015");
    } catch (KustvaktException e) {
        e.printStackTrace();
    }
    context.setToken(token);
    context.setTokenType(TokenType.BASIC);
    context.setUsername("demo");
    return new KustvaktContext(context);
}
Also used : TokenContext(de.ids_mannheim.korap.security.context.TokenContext) KustvaktContext(de.ids_mannheim.korap.security.context.KustvaktContext) KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException)

Example 23 with TokenContext

use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.

the class DemoUserFilter method createShorterToken.

private TokenContext createShorterToken(String host, String agent) {
    User demo = User.UserFactory.getDemoUser();
    TokenContext c = new TokenContext();
    c.setUsername(demo.getUsername());
    c.setHostAddress(host);
    c.setUserAgent(agent);
    c.setExpirationTime(TimeUtils.plusSeconds(config.getShortTokenTTL()).getMillis());
    c.setTokenType(TokenType.BASIC);
    return c;
}
Also used : TokenContext(de.ids_mannheim.korap.security.context.TokenContext) User(de.ids_mannheim.korap.user.User)

Example 24 with TokenContext

use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.

the class SessionAuthentication method createTokenContext.

@Override
public TokenContext createTokenContext(User user, Map<String, Object> attr) throws KustvaktException {
    DateTime now = TimeUtils.getNow();
    DateTime ex = TimeUtils.getExpiration(now.getMillis(), config.getShortTokenTTL());
    String token = crypto.createToken(true, user.getUsername(), now.getMillis());
    TokenContext ctx = new TokenContext();
    ctx.setUsername(user.getUsername());
    ctx.setTokenType(TokenType.SESSION);
    ctx.setToken(token);
    ctx.setExpirationTime(ex.getMillis() + (1000));
    ctx.setHostAddress(attr.get(Attributes.HOST).toString());
    ctx.setUserAgent(attr.get(Attributes.USER_AGENT).toString());
    this.sessions.putSession(token, ctx);
    if (DEBUG) {
        jlog.debug(ctx.toJson());
        jlog.debug("session " + sessions.getSession(token).toString());
        jlog.info("create session for user: " + user.getUsername());
    }
    return ctx;
}
Also used : TokenContext(de.ids_mannheim.korap.security.context.TokenContext) DateTime(org.joda.time.DateTime)

Example 25 with TokenContext

use of de.ids_mannheim.korap.security.context.TokenContext in project Kustvakt by KorAP.

the class DummyAuthenticationManager method getTokenContext.

@Override
public TokenContext getTokenContext(TokenType type, String token, String host, String useragent) throws KustvaktException {
    TokenContext c = new TokenContext();
    c.setUsername("guest");
    c.setHostAddress(host);
    c.setUserAgent(useragent);
    c.setExpirationTime(TimeUtils.plusSeconds(config.getShortTokenTTL()).getMillis());
    c.setTokenType(TokenType.BASIC);
    c.setToken("dummyToken");
    return c;
}
Also used : TokenContext(de.ids_mannheim.korap.security.context.TokenContext)

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