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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations