diff --git a/core/src/main/java/de/bstly/we/businesslogic/PermissionManager.java b/core/src/main/java/de/bstly/we/businesslogic/PermissionManager.java index 7bf73eb..a3fb9df 100755 --- a/core/src/main/java/de/bstly/we/businesslogic/PermissionManager.java +++ b/core/src/main/java/de/bstly/we/businesslogic/PermissionManager.java @@ -42,7 +42,7 @@ public class PermissionManager implements UserDataProvider { * Gets the. * * @param target the target - * @param name the name + * @param name the name * @return the list */ public List get(Long target, String name) { @@ -126,7 +126,7 @@ public class PermissionManager implements UserDataProvider { * Checks for permission. * * @param target the target - * @param name the name + * @param name the name * @return true, if successful */ public boolean hasPermission(Long target, String name) { @@ -143,10 +143,10 @@ public class PermissionManager implements UserDataProvider { /** * Creates the. * - * @param target the target - * @param name the name - * @param addon the addon - * @param starts the starts + * @param target the target + * @param name the name + * @param addon the addon + * @param starts the starts * @param expires the expires * @return the permission */ @@ -188,7 +188,7 @@ public class PermissionManager implements UserDataProvider { /** * Clone. * - * @param name the name + * @param name the name * @param clone the clone * @return the list */ @@ -212,7 +212,7 @@ public class PermissionManager implements UserDataProvider { * Delete. * * @param target the target - * @param name the name + * @param name the name */ public void delete(Long target, String name) { Assert.isTrue( @@ -249,10 +249,10 @@ public class PermissionManager implements UserDataProvider { /** * Apply item. * - * @param target the target - * @param item the item + * @param target the target + * @param item the item * @param answers the answers - * @param starts the starts + * @param starts the starts * @param expires the expires */ public void applyItem(Long target, Integer item, JsonArray answers, Instant starts, @@ -265,10 +265,10 @@ public class PermissionManager implements UserDataProvider { /** * Gets the for item. * - * @param target the target - * @param item the item + * @param target the target + * @param item the item * @param answers the answers - * @param starts the starts + * @param starts the starts * @param expires the expires * @return the for item */ diff --git a/core/src/main/java/de/bstly/we/businesslogic/PermissionMappingManager.java b/core/src/main/java/de/bstly/we/businesslogic/PermissionMappingManager.java index c992c29..4a4aac3 100755 --- a/core/src/main/java/de/bstly/we/businesslogic/PermissionMappingManager.java +++ b/core/src/main/java/de/bstly/we/businesslogic/PermissionMappingManager.java @@ -78,14 +78,16 @@ public class PermissionMappingManager { /** * Creates the. * - * @param item the item - * @param names the names - * @param lifetime the lifetime - * @param lifetimeUnit the lifetime unit - * @param lifetimeRound the lifetime round - * @param addon the addon - * @param product the product - * @param startsQuestion the starts question + * @param item the item + * @param names the names + * @param lifetime the lifetime + * @param lifetimeUnit the lifetime unit + * @param lifetimeRound the lifetime round + * @param addon the addon + * @param product the product + * @param starts the starts + * @param expires the expires + * @param startsQuestion the starts question * @param expiresQuestion the expires question * @return the permission mapping */ @@ -140,9 +142,9 @@ public class PermissionMappingManager { /** * Gets the. * - * @param page the page - * @param size the size - * @param sortBy the sort by + * @param page the page + * @param size the size + * @param sortBy the sort by * @param descending the descending * @return the page */ diff --git a/core/src/main/java/de/bstly/we/businesslogic/SystemPropertyManager.java b/core/src/main/java/de/bstly/we/businesslogic/SystemPropertyManager.java index ab6b93c..f7db183 100755 --- a/core/src/main/java/de/bstly/we/businesslogic/SystemPropertyManager.java +++ b/core/src/main/java/de/bstly/we/businesslogic/SystemPropertyManager.java @@ -42,7 +42,7 @@ public class SystemPropertyManager { /** * Gets the. * - * @param key the key + * @param key the key * @param defaultValue the default value * @return the string */ @@ -64,7 +64,7 @@ public class SystemPropertyManager { /** * Gets the boolean. * - * @param key the key + * @param key the key * @param defaultValue the default value * @return the boolean */ @@ -85,7 +85,7 @@ public class SystemPropertyManager { /** * Gets the integer. * - * @param key the key + * @param key the key * @param defaultValue the default value * @return the integer */ @@ -106,7 +106,7 @@ public class SystemPropertyManager { /** * Gets the long. * - * @param key the key + * @param key the key * @param defaultValue the default value * @return the long */ @@ -117,7 +117,7 @@ public class SystemPropertyManager { /** * Adds the. * - * @param key the key + * @param key the key * @param value the value */ public void add(String key, String value) { @@ -129,7 +129,7 @@ public class SystemPropertyManager { /** * Update. * - * @param key the key + * @param key the key * @param value the value */ public void update(String key, String value) { @@ -140,6 +140,12 @@ public class SystemPropertyManager { systemPropertyRepository.save(systemProperty); } + /** + * Sets the. + * + * @param key the key + * @param value the value + */ public void set(String key, String value) { if (systemPropertyRepository.existsById(key)) { update(key, value); diff --git a/core/src/main/java/de/bstly/we/businesslogic/UserManager.java b/core/src/main/java/de/bstly/we/businesslogic/UserManager.java index d0349d6..f81b9f7 100755 --- a/core/src/main/java/de/bstly/we/businesslogic/UserManager.java +++ b/core/src/main/java/de/bstly/we/businesslogic/UserManager.java @@ -106,7 +106,7 @@ public class UserManager implements UserDataProvider { /** * Sets the password. * - * @param id the id + * @param id the id * @param password the password * @return the user */ @@ -124,7 +124,7 @@ public class UserManager implements UserDataProvider { * * @param username the username * @param password the password - * @param status the status + * @param status the status * @return the user */ public User create(String username, String password, UserStatus status) { @@ -148,9 +148,9 @@ public class UserManager implements UserDataProvider { /** * Gets the. * - * @param page the page - * @param size the size - * @param sortBy the sort by + * @param page the page + * @param size the size + * @param sortBy the sort by * @param descending the descending * @return the page */ @@ -218,7 +218,7 @@ public class UserManager implements UserDataProvider { /** * Write public key. * - * @param username the username + * @param username the username * @param publicKey the public key */ public void writePublicKey(String username, String publicKey) { @@ -263,10 +263,11 @@ public class UserManager implements UserDataProvider { /** * Password reset. * - * @param user the user + * @param user the user * @param outputStream the output stream */ public void passwordReset(User user, ServletOutputStream outputStream) { + // TODO: change to public key profile field String resetToken = RandomStringUtils.random(64, true, true); String command = "echo \"" + resetToken diff --git a/core/src/main/java/de/bstly/we/businesslogic/UserProfileFieldManager.java b/core/src/main/java/de/bstly/we/businesslogic/UserProfileFieldManager.java index 02fc2e4..c1e0076 100644 --- a/core/src/main/java/de/bstly/we/businesslogic/UserProfileFieldManager.java +++ b/core/src/main/java/de/bstly/we/businesslogic/UserProfileFieldManager.java @@ -100,7 +100,11 @@ public class UserProfileFieldManager implements UserDataProvider { Assert.isTrue( userProfileFieldRepository.exists( qUserProfileField.target.eq(target).and(qUserProfileField.name.eq(name))), - "ProfileField '" + name + "' for target + '" + target + "' not exists!"); + "ProfileField '" + + name + + "' for target + '" + + target + + "' not exists!"); UserProfileField delete = userProfileFieldRepository .findOne(qUserProfileField.target.eq(target).and(qUserProfileField.name.eq(name))) .get(); @@ -143,7 +147,9 @@ public class UserProfileFieldManager implements UserDataProvider { @Override public void purgeUserData(Long userId) { for (UserProfileField userProfileField : getAllByTarget(userId)) { - userProfileFieldRepository.delete(userProfileField); + if (!userProfileField.getName().equals(UserProfileFields.PROFILE_FIELD_PUBLIC_KEY)) { + userProfileFieldRepository.delete(userProfileField); + } } } diff --git a/core/src/main/java/de/bstly/we/businesslogic/UserProfileFields.java b/core/src/main/java/de/bstly/we/businesslogic/UserProfileFields.java index 3ad3e54..6cf8ee6 100644 --- a/core/src/main/java/de/bstly/we/businesslogic/UserProfileFields.java +++ b/core/src/main/java/de/bstly/we/businesslogic/UserProfileFields.java @@ -9,6 +9,7 @@ package de.bstly.we.businesslogic; public interface UserProfileFields { public static final String PROFILE_FIELD_EMAIL = "email"; + public static final String PROFILE_FIELD_PUBLIC_KEY = "publicKey"; public static final String PROFILE_FIELD_EMAIL_PRIMARY = "primaryEmail"; public static final String PROFILE_FIELD_LOCALE = "locale"; } diff --git a/core/src/main/java/de/bstly/we/controller/PermissionManagementController.java b/core/src/main/java/de/bstly/we/controller/PermissionManagementController.java index 2fc7c4e..1a8de01 100644 --- a/core/src/main/java/de/bstly/we/controller/PermissionManagementController.java +++ b/core/src/main/java/de/bstly/we/controller/PermissionManagementController.java @@ -103,10 +103,10 @@ public class PermissionManagementController extends BaseController { } /** - * Update permission. + * Update permissions. * - * @param permission the permission - * @return the permission + * @param permissions the permissions + * @return the list */ @PreAuthorize("hasRole('ROLE_ADMIN')") @PatchMapping("list") @@ -125,7 +125,7 @@ public class PermissionManagementController extends BaseController { /** * Clone. * - * @param name the name + * @param name the name * @param clone the clone * @return the list */ diff --git a/core/src/main/java/de/bstly/we/model/PermissionMapping.java b/core/src/main/java/de/bstly/we/model/PermissionMapping.java index 92ed7a3..e029327 100755 --- a/core/src/main/java/de/bstly/we/model/PermissionMapping.java +++ b/core/src/main/java/de/bstly/we/model/PermissionMapping.java @@ -206,6 +206,8 @@ public class PermissionMapping { } /** + * Gets the starts. + * * @return the starts */ public Instant getStarts() { @@ -213,13 +215,17 @@ public class PermissionMapping { } /** - * @param starts the starts to set + * Sets the starts. + * + * @param starts the new starts */ public void setStarts(Instant starts) { this.starts = starts; } /** + * Gets the expires. + * * @return the expires */ public Instant getExpires() { @@ -227,7 +233,9 @@ public class PermissionMapping { } /** - * @param expires the expires to set + * Sets the expires. + * + * @param expires the new expires */ public void setExpires(Instant expires) { this.expires = expires; @@ -275,6 +283,9 @@ public class PermissionMapping { @Converter public static class ChronoUnitConverter implements AttributeConverter { + /* + * @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object) + */ /* * @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang. * Object) @@ -284,6 +295,9 @@ public class PermissionMapping { return chronoUnit.name(); } + /* + * @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object) + */ /* * @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang. * Object) diff --git a/invite/src/main/java/de/bstly/we/invite/businesslogic/InviteMappingManager.java b/invite/src/main/java/de/bstly/we/invite/businesslogic/InviteMappingManager.java index a8fbc93..bd66067 100644 --- a/invite/src/main/java/de/bstly/we/invite/businesslogic/InviteMappingManager.java +++ b/invite/src/main/java/de/bstly/we/invite/businesslogic/InviteMappingManager.java @@ -46,7 +46,7 @@ public class InviteMappingManager { /** * Gets the by item and quota. * - * @param item the item + * @param item the item * @param quota the quota * @return the by item and quota */ @@ -59,9 +59,9 @@ public class InviteMappingManager { /** * Gets the. * - * @param page the page - * @param size the size - * @param sortBy the sort by + * @param page the page + * @param size the size + * @param sortBy the sort by * @param descending the descending * @return the page */ @@ -73,9 +73,9 @@ public class InviteMappingManager { /** * Creates the. * - * @param quota the quota - * @param item the item - * @param starts the starts + * @param quota the quota + * @param item the item + * @param starts the starts * @param expires the expires * @return the invite mapping */ diff --git a/invite/src/main/java/de/bstly/we/invite/controller/InviteController.java b/invite/src/main/java/de/bstly/we/invite/controller/InviteController.java index a8fe21a..764673a 100644 --- a/invite/src/main/java/de/bstly/we/invite/controller/InviteController.java +++ b/invite/src/main/java/de/bstly/we/invite/controller/InviteController.java @@ -92,10 +92,12 @@ public class InviteController extends BaseController { invite.setItem(null); invite.setNote(null); invite.setOwner(null); + invite.setRedeemedBy(null); } else if (!getCurrentUserId().equals(invite.getOwner())) { invite.setCode(null); invite.setCodeLink(null); invite.setOwner(null); + invite.setRedeemedBy(null); if (!permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_MEMBER)) { invite.setNote(null); } @@ -201,6 +203,8 @@ public class InviteController extends BaseController { User user = userManager.create(userModel.getUsername(), userModel.getPassword(), userModel.getStatus()); + Long userId = user.getId(); + for (UserProfileField userProfileField : userModel.getProfileFields()) { userProfileField.setTarget(user.getId()); if (userProfileField.getType() == null) { @@ -214,11 +218,42 @@ public class InviteController extends BaseController { userProfileField = userProfileFieldManager.save(userProfileField); } - permissionManager.applyItem(user.getId(), invite.getItem(), new JsonArray(), - invite.getStarts(), invite.getExpires()); - quotaManager.applyItem(user.getId(), invite.getItem()); + permissionManager.applyItem(userId, invite.getItem(), new JsonArray(), invite.getStarts(), + invite.getExpires()); + quotaManager.applyItem(userId, invite.getItem()); invite.setRedeemed(true); + invite.setRedeemedBy(userId); + inviteManager.save(invite); + } + + /** + * Redeem. + * + * @param code the code + */ + @PreAuthorize("isAuthenticated()") + @PostMapping("redeem") + public void redeem(@RequestBody String code) { + Invite invite = inviteManager.getByCode(code); + + if (invite == null) { + throw new EntityResponseStatusException(HttpStatus.NOT_ACCEPTABLE); + } + + if (invite.isRedeemed() + || invite.getExpires() != null && invite.getExpires().isBefore(Instant.now())) { + throw new EntityResponseStatusException(HttpStatus.GONE); + } + + Long userId = getCurrentUserId(); + + permissionManager.applyItem(userId, invite.getItem(), new JsonArray(), invite.getStarts(), + invite.getExpires()); + quotaManager.applyItem(userId, invite.getItem()); + + invite.setRedeemed(true); + invite.setRedeemedBy(userId); inviteManager.save(invite); } @@ -283,6 +318,7 @@ public class InviteController extends BaseController { invite.setCodeLink(null); invite.setMessage(null); invite.setOwner(null); + invite.setRedeemedBy(null); } return page; diff --git a/invite/src/main/java/de/bstly/we/invite/model/Invite.java b/invite/src/main/java/de/bstly/we/invite/model/Invite.java index c9217a9..3fac4fb 100644 --- a/invite/src/main/java/de/bstly/we/invite/model/Invite.java +++ b/invite/src/main/java/de/bstly/we/invite/model/Invite.java @@ -36,6 +36,7 @@ public class Invite implements UserData { private String message; private String note; private boolean redeemed; + private Long redeemedBy; private String codeLink; private String url; @@ -219,6 +220,24 @@ public class Invite implements UserData { this.redeemed = redeemed; } + /** + * Gets the redeemed by. + * + * @return the redeemed by + */ + public Long getRedeemedBy() { + return redeemedBy; + } + + /** + * Sets the redeemed by. + * + * @param redeemedBy the new redeemed by + */ + public void setRedeemedBy(Long redeemedBy) { + this.redeemedBy = redeemedBy; + } + /** * Gets the code link. * diff --git a/pom.xml b/pom.xml index 20477d2..0fec4e8 100755 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ UTF-8 11 2.17.1 - 1.6.0-SNAPSHOT + 1.6.1-SNAPSHOT