com.github.lontime.extpac4j.impl.JEETokenContextFactory Maven / Gradle / Ivy
The newest version!
package com.github.lontime.extpac4j.impl;
import java.time.Duration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.github.lontime.base.commonj.utils.UuidHelper;
import org.pac4j.core.context.JEEContext;
import org.pac4j.core.context.WebContext;
import org.pac4j.core.context.WebContextFactory;
import org.pac4j.core.context.session.SessionStore;
/**
* JEETokenContextFactory.
* @author lontime
* @since 1.0
*/
public class JEETokenContextFactory implements WebContextFactory {
public static final Duration DEFAULT_EXPIRE = Duration.ofHours(2);
public static final JEETokenContextFactory INSTANCE = new JEETokenContextFactory();
private String token;
private Duration expire;
public JEETokenContextFactory() {
this(DEFAULT_EXPIRE);
}
public JEETokenContextFactory(Duration expire) {
this(null, DEFAULT_EXPIRE);
}
public JEETokenContextFactory(String token, Duration expire) {
this.token = token;
this.expire = expire;
}
@Override
@SuppressWarnings("unchecked")
public WebContext newContext(Object... parameters) {
final JEETokenContext context;
if (parameters.length > 2) {
context = new JEETokenContext((HttpServletRequest) parameters[0], (HttpServletResponse) parameters[1],
(SessionStore) parameters[2]);
} else {
context = new JEETokenContext((HttpServletRequest) parameters[0], (HttpServletResponse) parameters[1]);
}
if (token == null) {
context.setToken(UuidHelper.fastUUID());
} else {
context.setToken(token);
}
context.setExpire(expire);
return context;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy