update invite, keep public key

This commit is contained in:
_Bastler 2022-02-05 10:37:49 +01:00
parent e3a437bd76
commit 1db9257889
12 changed files with 142 additions and 57 deletions

View File

@ -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<Permission> 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
*/

View File

@ -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
*/

View File

@ -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);

View File

@ -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

View File

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

View File

@ -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";
}

View File

@ -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
*/

View File

@ -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<ChronoUnit, String> {
/*
* @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)

View File

@ -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
*/

View File

@ -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;

View File

@ -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.
*

View File

@ -13,7 +13,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<log4j2.version>2.17.1</log4j2.version>
<revision>1.6.0-SNAPSHOT</revision>
<revision>1.6.1-SNAPSHOT</revision>
</properties>
<parent>