alpha
parent
90c696bd54
commit
542dd89422
|
|
@ -26,14 +26,15 @@ public class ExtToken extends UsernamePasswordAuthenticationToken {
|
|||
|
||||
public boolean validate(String clientToken) {
|
||||
String sha3 = DigestUtils.sha3_512Hex(clientToken + timestamp);
|
||||
// logger.info("Token to compare: " + sha3);
|
||||
TimeZone tz = TimeZone.getTimeZone("UTC");
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
|
||||
df.setTimeZone(tz);
|
||||
try {
|
||||
Date parsedTimestamp = df.parse(timestamp);
|
||||
Long timeDiff = parsedTimestamp.getTime() - Timestamp.from(Instant.now()).getTime();
|
||||
System.out.println("Time diff: " + timeDiff);
|
||||
if (Math.abs(timeDiff) > 15000) {
|
||||
// logger.info("Time diff: " + timeDiff);
|
||||
if (Math.abs(timeDiff) > 150000) {
|
||||
return false;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class ExtTokenAuthenticationProvider extends AbstractUserDetailsAuthentic
|
|||
protected UserDetails retrieveUser(String s, UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken) throws AuthenticationException {
|
||||
ExtToken token = (ExtToken) usernamePasswordAuthenticationToken;
|
||||
if (token.validate(extToken)) {
|
||||
logger.info("Token validated");
|
||||
// logger.info("Token validated");
|
||||
return new ExtUser();
|
||||
} else {
|
||||
logger.info("Token not valid");
|
||||
|
|
|
|||
|
|
@ -14,17 +14,19 @@ import java.io.IOException;
|
|||
|
||||
public class ExtTokenAuthenticationTokenFilter extends AbstractAuthenticationProcessingFilter {
|
||||
private final static String TOKEN_HEADER = "Authorization";
|
||||
private final static String TIMESTAMP_HEADER = "X-Timestamp";
|
||||
private final static String TIMESTAMP_HEADER = "Timestamp";
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExtTokenAuthenticationTokenFilter.class);
|
||||
|
||||
public ExtTokenAuthenticationTokenFilter() {
|
||||
super("/api/**");
|
||||
super("/**");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Authentication attemptAuthentication(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws AuthenticationException, IOException, ServletException {
|
||||
String authToken = httpServletRequest.getHeader(TOKEN_HEADER);
|
||||
String timestamp = httpServletRequest.getHeader(TIMESTAMP_HEADER);
|
||||
// logger.info("Token:" + authToken);
|
||||
// logger.info("Timestamp:" + timestamp);
|
||||
return getAuthenticationManager().authenticate(new ExtToken(authToken, timestamp));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,3 +5,5 @@ spring.kafka.producer.bootstrap-servers=localhost:9092
|
|||
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
|
||||
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
|
||||
spring.kafka.producer.properties.max.request.size=20242880
|
||||
|
||||
logging.level.org.springframework.web=INFO
|
||||
Loading…
Reference in New Issue