added userdata, email to lowercase
This commit is contained in:
@@ -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,11 @@ 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 start the start
|
||||
* @param starts the starts
|
||||
* @param expires the expires
|
||||
*/
|
||||
public void applyItem(Long target, Integer item, JsonArray answers, Instant starts,
|
||||
Instant expires) {
|
||||
@@ -264,10 +265,11 @@ 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 start
|
||||
* @param starts the starts
|
||||
* @param expires the expires
|
||||
* @return the for item
|
||||
*/
|
||||
public List<Permission> getForItem(Long target, Integer item, JsonArray answers, Instant starts,
|
||||
|
||||
@@ -33,7 +33,7 @@ public class QuotaManager implements UserDataProvider {
|
||||
* Gets the.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @return the quota
|
||||
*/
|
||||
public Quota get(Long target, String name) {
|
||||
@@ -85,7 +85,7 @@ public class QuotaManager implements UserDataProvider {
|
||||
* Checks for quota.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean hasQuota(Long target, String name) {
|
||||
@@ -96,10 +96,10 @@ public class QuotaManager implements UserDataProvider {
|
||||
/**
|
||||
* Creates the.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param value the value
|
||||
* @param unit the unit
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param value the value
|
||||
* @param unit the unit
|
||||
* @param disposable the disposable
|
||||
* @return the quota
|
||||
*/
|
||||
@@ -141,7 +141,7 @@ public class QuotaManager implements UserDataProvider {
|
||||
/**
|
||||
* Clone.
|
||||
*
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @param clone the clone
|
||||
* @param value the value
|
||||
* @return the list
|
||||
@@ -164,7 +164,7 @@ public class QuotaManager implements UserDataProvider {
|
||||
* Delete.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
*/
|
||||
public void delete(Long target, String name) {
|
||||
Assert.isTrue(quotaRepository.exists(qQuota.target.eq(target).and(qQuota.name.eq(name))),
|
||||
@@ -197,10 +197,11 @@ public class QuotaManager implements UserDataProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @param item
|
||||
* @return
|
||||
* Adds the for item.
|
||||
*
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param quotas the quotas
|
||||
*/
|
||||
public void addForItem(Long target, Integer item, List<Quota> quotas) {
|
||||
for (QuotaMapping quotaMapping : quotaMappingManager.getAllByItem(item)) {
|
||||
@@ -241,7 +242,7 @@ public class QuotaManager implements UserDataProvider {
|
||||
* Apply item.
|
||||
*
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param item the item
|
||||
*/
|
||||
public void applyItem(Long target, Integer item) {
|
||||
for (QuotaMapping quotaMapping : quotaMappingManager.getAllByItem(item)) {
|
||||
|
||||
@@ -60,10 +60,13 @@ public class UserDataManager implements SmartInitializingSingleton {
|
||||
private List<UserDataProvider> providers;
|
||||
private Gson gson = new Gson();
|
||||
|
||||
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#
|
||||
* afterSingletonsInstantiated()
|
||||
*/
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
providers = Lists.newArrayList();
|
||||
@@ -78,6 +81,15 @@ public class UserDataManager implements SmartInitializingSingleton {
|
||||
*/
|
||||
@Scheduled(cron = "${we.bstly.userdata.cron:0 0 0 * * * }")
|
||||
public void purge() {
|
||||
purge(!purge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge.
|
||||
*
|
||||
* @param dry the dry
|
||||
*/
|
||||
public void purge(boolean dry) {
|
||||
long days = systemPropertyManager.getLong(SYSTEM_PROPERTY_USERDATA_DAYS,
|
||||
SYSTEM_PROPERTY_USERDATA_DAYS_DEFAULT);
|
||||
|
||||
@@ -90,7 +102,7 @@ public class UserDataManager implements SmartInitializingSingleton {
|
||||
if (permissionManager.getNotExpiresByTargetIgnoreStart(user.getId())
|
||||
.isEmpty()) {
|
||||
if (UserStatus.PURGE.equals(user.getStatus())) {
|
||||
purge(user, !purge);
|
||||
purge(user, dry);
|
||||
} else if (UserStatus.NORMAL.equals(user.getStatus())) {
|
||||
Instant last = Instant.MIN;
|
||||
for (Permission permission : permissionManager
|
||||
@@ -101,7 +113,7 @@ public class UserDataManager implements SmartInitializingSingleton {
|
||||
}
|
||||
|
||||
if (Instant.now().minus(days, ChronoUnit.DAYS).isAfter(last)) {
|
||||
purge(user, !purge);
|
||||
purge(user, dry);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,7 +121,6 @@ public class UserDataManager implements SmartInitializingSingleton {
|
||||
}
|
||||
pageable = page.nextPageable();
|
||||
} while (page.hasNext());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,10 +132,16 @@ public class UserDataManager implements SmartInitializingSingleton {
|
||||
public void purge(User user, boolean dry) {
|
||||
Long userId = user.getId();
|
||||
if (dry) {
|
||||
logger.debug("Would purge all data of user '" + user.getUsername() + "' [id="
|
||||
+ user.getId() + "]!");
|
||||
logger.debug("Would purge all data of user '"
|
||||
+ user.getUsername()
|
||||
+ "' [id="
|
||||
+ user.getId()
|
||||
+ "]!");
|
||||
} else {
|
||||
logger.warn("Purge all data of user '" + user.getUsername() + "' [id=" + user.getId()
|
||||
logger.warn("Purge all data of user '"
|
||||
+ user.getUsername()
|
||||
+ "' [id="
|
||||
+ user.getId()
|
||||
+ "]!");
|
||||
}
|
||||
|
||||
@@ -132,22 +149,34 @@ public class UserDataManager implements SmartInitializingSingleton {
|
||||
if (dry) {
|
||||
List<UserData> result = provider.getUserData(userId);
|
||||
if (!result.isEmpty()) {
|
||||
logger.debug("\tWould have purged '" + provider.getId() + "' data of user '"
|
||||
+ user.getUsername() + "' [id=" + user.getId() + "]!");
|
||||
logger.debug("\tWould have purged '"
|
||||
+ provider.getId()
|
||||
+ "' data of user '"
|
||||
+ user.getUsername()
|
||||
+ "' [id="
|
||||
+ user.getId()
|
||||
+ "]!");
|
||||
if (logger.isTraceEnabled()) {
|
||||
for (UserData userData : result) {
|
||||
logger.trace("\t\t" + gson.toJson(userData));
|
||||
logger.trace("\t\t"
|
||||
+ gson.toJson(userData));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<UserData> result = provider.getUserData(userId);
|
||||
if (!result.isEmpty()) {
|
||||
logger.warn("\tPurge '" + provider.getId() + "' data of user '"
|
||||
+ user.getUsername() + "' [id=" + user.getId() + "]!");
|
||||
logger.warn("\tPurge '"
|
||||
+ provider.getId()
|
||||
+ "' data of user '"
|
||||
+ user.getUsername()
|
||||
+ "' [id="
|
||||
+ user.getId()
|
||||
+ "]!");
|
||||
if (logger.isTraceEnabled()) {
|
||||
for (UserData userData : result) {
|
||||
logger.trace("\t\t" + gson.toJson(userData));
|
||||
logger.trace("\t\t"
|
||||
+ gson.toJson(userData));
|
||||
}
|
||||
}
|
||||
provider.purgeUserData(userId);
|
||||
@@ -156,7 +185,10 @@ public class UserDataManager implements SmartInitializingSingleton {
|
||||
}
|
||||
|
||||
if (!dry) {
|
||||
logger.warn("Purged all data of user '" + user.getUsername() + "' [id=" + user.getId()
|
||||
logger.warn("Purged all data of user '"
|
||||
+ user.getUsername()
|
||||
+ "' [id="
|
||||
+ user.getId()
|
||||
+ "]!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.we.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.bstly.we.businesslogic.UserDataManager;
|
||||
import de.bstly.we.businesslogic.UserManager;
|
||||
import de.bstly.we.controller.support.EntityResponseStatusException;
|
||||
import de.bstly.we.model.User;
|
||||
import de.bstly.we.model.UserData;
|
||||
|
||||
/**
|
||||
* The Class UserDataManagementController.
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/users/manage/data")
|
||||
public class UserDataManagementController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private UserManager userManager;
|
||||
@Autowired
|
||||
private UserDataManager userDataManager;
|
||||
|
||||
/**
|
||||
* Gets the for user.
|
||||
*
|
||||
* @param username the username
|
||||
* @return
|
||||
* @return the for user
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@GetMapping("/{username}")
|
||||
public Map<String, List<UserData>> getForUser(@PathVariable("username") String username) {
|
||||
User user = userManager.getByUsername(username);
|
||||
|
||||
if (user == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
return userDataManager.get(user.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge.
|
||||
*
|
||||
* @param dry the dry
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@PostMapping("/purge")
|
||||
public void purge(@RequestParam("dry") boolean dry) {
|
||||
userDataManager.purge(dry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge by username.
|
||||
*
|
||||
* @param username the username
|
||||
* @param dry the dry
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@PostMapping("/purge/{username}")
|
||||
public void purgeByUsername(@PathVariable("username") String username,
|
||||
@RequestParam("dry") boolean dry) {
|
||||
User user = userManager.getByUsername(username);
|
||||
|
||||
if (user == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
userDataManager.purge(user, dry);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class TokenSessionManager {
|
||||
* Gets the permission mappings for token.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param token the token
|
||||
* @param token the token
|
||||
* @return the permission mappings for token
|
||||
*/
|
||||
public List<PermissionMapping> getPermissionMappingsForToken(Long userId, String token) {
|
||||
@@ -79,7 +79,7 @@ public class TokenSessionManager {
|
||||
* Gets the permissions for token.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param token the token
|
||||
* @param token the token
|
||||
* @return the permissions for token
|
||||
*/
|
||||
public List<Permission> getPermissionsForToken(Long userId, String token) {
|
||||
@@ -113,7 +113,7 @@ public class TokenSessionManager {
|
||||
* Gets the quota mappings for token.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param token the token
|
||||
* @param token the token
|
||||
* @return the quota mappings for token
|
||||
*/
|
||||
public List<QuotaMapping> getQuotaMappingsForToken(Long userId, String token) {
|
||||
@@ -133,6 +133,13 @@ public class TokenSessionManager {
|
||||
return quotaMappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the quotas for token.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param token the token
|
||||
* @param quotas the quotas
|
||||
*/
|
||||
public void addQuotasForToken(Long userId, String token, List<Quota> quotas) {
|
||||
try {
|
||||
JsonObject result = pretixManager.getCheckInItemBySecret(token);
|
||||
@@ -215,7 +222,7 @@ public class TokenSessionManager {
|
||||
/**
|
||||
* Adds the token to session.
|
||||
*
|
||||
* @param secret the secret
|
||||
* @param secret the secret
|
||||
* @param session the session
|
||||
*/
|
||||
public void addTokenToSession(String secret, HttpSession session) {
|
||||
@@ -242,7 +249,7 @@ public class TokenSessionManager {
|
||||
/**
|
||||
* Removes the token from session.
|
||||
*
|
||||
* @param secret the secret
|
||||
* @param secret the secret
|
||||
* @param session the session
|
||||
*/
|
||||
public void removeTokenFromSession(String secret, HttpSession session) {
|
||||
@@ -278,7 +285,7 @@ public class TokenSessionManager {
|
||||
/**
|
||||
* Creates the new auth.
|
||||
*
|
||||
* @param auth the auth
|
||||
* @param auth the auth
|
||||
* @param details the details
|
||||
* @return the authentication
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,6 @@ package de.bstly.we.model;
|
||||
/**
|
||||
* The Interface UserData.
|
||||
*/
|
||||
public interface UserData {
|
||||
public interface UserData extends AbstractModel {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user