fix token redeem

This commit is contained in:
_Bastler 2021-11-11 19:23:37 +01:00
parent cd05e008ae
commit fad01fc0d7
7 changed files with 61 additions and 32 deletions

View File

@ -280,13 +280,18 @@ public class PermissionManager implements UserDataProvider {
Instant permissionStarts = starts; Instant permissionStarts = starts;
Instant permissionsExpires = expires; Instant permissionsExpires = expires;
if (permissionMapping.isLifetimeRound()) {
permissionStarts = InstantHelper.truncate(permissionStarts,
permissionMapping.getLifetimeUnit());
}
if (permissionsExpires == null) { if (permissionsExpires == null) {
permissionsExpires = InstantHelper.plus( permissionsExpires = InstantHelper.plus(
permissionStarts == null ? Instant.now() : permissionStarts, permissionStarts == null ? Instant.now() : permissionStarts,
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit()); permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit());
} }
boolean additional = true; boolean additional = permissionMapping.isAddon();
for (JsonElement anwser : answers) { for (JsonElement anwser : answers) {
if (anwser.isJsonObject() if (anwser.isJsonObject()

View File

@ -143,7 +143,7 @@ public class UserController extends BaseController {
} }
if (!register) { if (!register) {
throw new EntityResponseStatusException(HttpStatus.UNAUTHORIZED); throw new EntityResponseStatusException(HttpStatus.LOCKED);
} }
userModelValidator.validate(userModel, errors); userModelValidator.validate(userModel, errors);

View File

@ -100,7 +100,7 @@ public class TokenSessionManager {
} }
permissions.addAll(permissionManager.getForItem(userId, item, permissions.addAll(permissionManager.getForItem(userId, item,
orderPosition.get("answers").getAsJsonArray(), null, null)); orderPosition.get("answers").getAsJsonArray(),lastPaymentDate, null));
} }
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
@ -180,7 +180,7 @@ public class TokenSessionManager {
} }
permissionManager.applyItem(userId, item, permissionManager.applyItem(userId, item,
position.get("answers").getAsJsonArray(), null, null); position.get("answers").getAsJsonArray(), lastPaymentDate, null);
permissionMappings.addAll(permissionMappingManager.getAllByItem(item)); permissionMappings.addAll(permissionMappingManager.getAllByItem(item));
quotaManager.applyItem(userId, item); quotaManager.applyItem(userId, item);
quotaMappings.addAll(quotaMappingManager.getAllByItem(item)); quotaMappings.addAll(quotaMappingManager.getAllByItem(item));

View File

@ -18,6 +18,7 @@ import org.springframework.util.Assert;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import de.bstly.we.controller.support.TokenSessionManager;
import de.bstly.we.security.token.LocalSecondFactorAuthenticationToken; import de.bstly.we.security.token.LocalSecondFactorAuthenticationToken;
/** /**
@ -28,6 +29,8 @@ public class FormAuthenticationSuccessHandler
@Autowired @Autowired
protected RememberMeServices rememberMeServices; protected RememberMeServices rememberMeServices;
@Autowired
protected TokenSessionManager tokenSessionManager;
private String totpRedirectUrl; private String totpRedirectUrl;
private String rememberMeParameter; private String rememberMeParameter;
@ -61,7 +64,7 @@ public class FormAuthenticationSuccessHandler
@Override @Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws ServletException, IOException { Authentication authentication) throws ServletException, IOException {
if (!authentication.isAuthenticated() if (!authentication.isAuthenticated()
&& authentication instanceof PreAuthenticatedAuthenticationToken) { && authentication instanceof PreAuthenticatedAuthenticationToken) {
rememberMeServices.loginFail(request, response); rememberMeServices.loginFail(request, response);

View File

@ -31,7 +31,7 @@ public class RestAuthenticationSuccessHandler extends FormAuthenticationSuccessH
*/ */
@Override @Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException { Authentication authentication) throws IOException, ServletException {
if (!authentication.isAuthenticated()) { if (!authentication.isAuthenticated()) {
rememberMeServices.loginFail(request, response); rememberMeServices.loginFail(request, response);
response.sendError(HttpStatus.PRECONDITION_REQUIRED.value(), response.sendError(HttpStatus.PRECONDITION_REQUIRED.value(),

View File

@ -118,8 +118,11 @@ public class MembershipManager {
int membershipId = Integer.valueOf(membershipIdAnswer.get("answer").getAsInt()); int membershipId = Integer.valueOf(membershipIdAnswer.get("answer").getAsInt());
if (internalMembershipId == membershipId) { if (internalMembershipId == membershipId) {
writeMembershipId = false; writeMembershipId = false;
logger.trace("Order '" + orderPosition.get("order").getAsString() logger.trace("Order '"
+ "' already processed, membership id: '" + membershipId + "'"); + orderPosition.get("order").getAsString()
+ "' already processed, membership id: '"
+ membershipId
+ "'");
} }
} }
@ -137,9 +140,10 @@ public class MembershipManager {
JsonObject payload = new JsonObject(); JsonObject payload = new JsonObject();
payload.add("answers", answers); payload.add("answers", answers);
logger.debug( logger.debug("Write membershipId for '"
"Write membershipId for '" + orderPosition.get("order").getAsString() + orderPosition.get("order").getAsString()
+ "': " + internalMembershipId); + "': "
+ internalMembershipId);
pretixManager.request( pretixManager.request(
String.format("/api/v1/organizers/%s/events/%s/orderpositions/%s/", String.format("/api/v1/organizers/%s/events/%s/orderpositions/%s/",
@ -178,8 +182,10 @@ public class MembershipManager {
payload.add("answers", answers); payload.add("answers", answers);
logger.debug("Create membershipId for '" + orderPosition.get("order").getAsString() logger.debug("Create membershipId for '"
+ "': " + nextMembershipId); + orderPosition.get("order").getAsString()
+ "': "
+ nextMembershipId);
pretixManager pretixManager
.request( .request(
@ -261,7 +267,8 @@ public class MembershipManager {
if (membershipId == 0) { if (membershipId == 0) {
logger.warn("No membership number found for '" logger.warn("No membership number found for '"
+ membershipOrderPosition.get("order").getAsString() + "'!"); + membershipOrderPosition.get("order").getAsString()
+ "'!");
continue; continue;
} }
@ -270,7 +277,8 @@ public class MembershipManager {
if (membershipStart == null) { if (membershipStart == null) {
logger.warn("No last payment found for '" logger.warn("No last payment found for '"
+ membershipOrderPosition.get("order").getAsString() + "'!"); + membershipOrderPosition.get("order").getAsString()
+ "'!");
continue; continue;
} }
@ -307,11 +315,13 @@ public class MembershipManager {
HttpMethod.PATCH, payload); HttpMethod.PATCH, payload);
logger.debug("Write active state for '" logger.debug("Write active state for '"
+ membershipOrderPosition.get("order").getAsString() + "': " + membershipOrderPosition.get("order").getAsString()
+ "': "
+ activeAnswer); + activeAnswer);
} else { } else {
logger.trace("Order active state for '" logger.trace("Order active state for '"
+ membershipOrderPosition.get("order").getAsString() + "' already set: " + membershipOrderPosition.get("order").getAsString()
+ "' already set: "
+ activeAnswer); + activeAnswer);
} }
} }
@ -383,8 +393,11 @@ public class MembershipManager {
.isBefore(Instant.now())) { .isBefore(Instant.now())) {
expireMemberships.add(membershipOrderPosition); expireMemberships.add(membershipOrderPosition);
} else { } else {
logger.trace("Membership '" + membershipOrderPosition.get("order").getAsString() logger.trace("Membership '"
+ "' not expiring in next " + membershipfeeOrderDays + " days."); + membershipOrderPosition.get("order").getAsString()
+ "' not expiring in next "
+ membershipfeeOrderDays
+ " days.");
} }
} }
@ -428,7 +441,8 @@ public class MembershipManager {
if (membershipId == 0) { if (membershipId == 0) {
logger.warn("No membership number found for '" logger.warn("No membership number found for '"
+ membershipOrderPosition.get("order").getAsString() + "'!"); + membershipOrderPosition.get("order").getAsString()
+ "'!");
continue; continue;
} }
@ -445,7 +459,7 @@ public class MembershipManager {
JsonObject membershipFeeOrderPosition = new JsonObject(); JsonObject membershipFeeOrderPosition = new JsonObject();
membershipFeeOrderPosition.addProperty("item", membershipFeeItemId); membershipFeeOrderPosition.addProperty("item", membershipFeeItemId);
JsonArray membershipFeeOrderPositionAnswers = new JsonArray(); JsonArray membershipFeeOrderPositionAnswers = new JsonArray();
JsonObject membershipFeeReferenceAnswer = new JsonObject(); JsonObject membershipFeeReferenceAnswer = new JsonObject();
membershipFeeReferenceAnswer.addProperty("question", membershipFeeReferenceAnswer.addProperty("question",
@ -454,13 +468,13 @@ public class MembershipManager {
membershipFeeReferenceAnswer.add("option_identifiers", new JsonArray()); membershipFeeReferenceAnswer.add("option_identifiers", new JsonArray());
membershipFeeReferenceAnswer.addProperty("answer", membershipId); membershipFeeReferenceAnswer.addProperty("answer", membershipId);
membershipFeeOrderPositionAnswers.add(membershipFeeReferenceAnswer); membershipFeeOrderPositionAnswers.add(membershipFeeReferenceAnswer);
JsonObject membershipFeeCodeAnswer = new JsonObject(); JsonObject membershipFeeCodeAnswer = new JsonObject();
membershipFeeCodeAnswer.addProperty("question", membershipFeeCodeAnswer.addProperty("question", membershipFeeCodeQuestion);
membershipFeeCodeQuestion);
membershipFeeCodeAnswer.add("options", new JsonArray()); membershipFeeCodeAnswer.add("options", new JsonArray());
membershipFeeCodeAnswer.add("option_identifiers", new JsonArray()); membershipFeeCodeAnswer.add("option_identifiers", new JsonArray());
membershipFeeCodeAnswer.addProperty("answer", membershipOrderPosition.get("order").getAsString()); membershipFeeCodeAnswer.addProperty("answer",
membershipOrderPosition.get("order").getAsString());
membershipFeeOrderPositionAnswers.add(membershipFeeCodeAnswer); membershipFeeOrderPositionAnswers.add(membershipFeeCodeAnswer);
membershipFeeOrderPosition.add("answers", membershipFeeOrderPositionAnswers); membershipFeeOrderPosition.add("answers", membershipFeeOrderPositionAnswers);
@ -477,6 +491,12 @@ public class MembershipManager {
membershipFeeOrder.add("payment_provider", payment.get("provider")); membershipFeeOrder.add("payment_provider", payment.get("provider"));
} }
Instant expires = InstantHelper.minus(InstantHelper.truncate(
InstantHelper.plus(Instant.now(), 1, ChronoUnit.YEARS), ChronoUnit.YEARS),
1, ChronoUnit.DAYS);
membershipFeeOrder.addProperty("expires",
pretixDateFormat.format(Date.from(expires)));
membershipFeeOrder.addProperty("send_email", orderSendmail); membershipFeeOrder.addProperty("send_email", orderSendmail);
membershipFeeOrder.addProperty("testmode", orderTestmode); membershipFeeOrder.addProperty("testmode", orderTestmode);
membershipFeeOrder.addProperty("simulate", orderSimulate); membershipFeeOrder.addProperty("simulate", orderSimulate);
@ -484,14 +504,12 @@ public class MembershipManager {
membershipFeeOrder = pretixManager.createOrder(membershipFeeOrder); membershipFeeOrder = pretixManager.createOrder(membershipFeeOrder);
JsonObject expire = new JsonObject(); JsonObject expire = new JsonObject();
Instant expires = InstantHelper.minus(InstantHelper.truncate(
InstantHelper.plus(Instant.now(), 1, ChronoUnit.YEARS), ChronoUnit.YEARS),
1, ChronoUnit.DAYS);
expire.addProperty("expires", pretixDateFormat.format(Date.from(expires))); expire.addProperty("expires", pretixDateFormat.format(Date.from(expires)));
membershipFeeOrder = pretixManager membershipFeeOrder = pretixManager
.extendOrder(membershipFeeOrder.get("code").getAsString(), expire); .extendOrder(membershipFeeOrder.get("code").getAsString(), expire);
logger.debug("Create membership fee order: " + membershipFeeOrder.toString()); logger.debug("Create membership fee order: "
+ membershipFeeOrder.toString());
} else } else
// send reminder mail for membership fee order // send reminder mail for membership fee order
if (membershipfeeReminderDays > 0 && membershipfeeReminderQuestion > 0 if (membershipfeeReminderDays > 0 && membershipfeeReminderQuestion > 0
@ -687,7 +705,8 @@ public class MembershipManager {
active = date.toInstant(); active = date.toInstant();
} catch (ParseException e) { } catch (ParseException e) {
logger.error("Error on parsing active date for '" logger.error("Error on parsing active date for '"
+ orderPosition.get("order").getAsString() + "'!", e); + orderPosition.get("order").getAsString()
+ "'!", e);
} }
} }
} }
@ -810,7 +829,9 @@ public class MembershipManager {
return pretixDateFormat.parse(answer.get("answer").getAsString()).toInstant(); return pretixDateFormat.parse(answer.get("answer").getAsString()).toInstant();
} catch (ParseException e) { } catch (ParseException e) {
logger.error("Error on parsing active date for '" logger.error("Error on parsing active date for '"
+ orderPosition.get("order").getAsString() + "' in question '" + question + orderPosition.get("order").getAsString()
+ "' in question '"
+ question
+ "'!", e); + "'!", e);
} }
} }

View File

@ -12,7 +12,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version> <java.version>11</java.version>
<revision>1.3.2-SNAPSHOT</revision> <revision>1.4.0-SNAPSHOT</revision>
</properties> </properties>
<parent> <parent>