fix permission calculation

This commit is contained in:
_Bastler 2022-11-09 16:07:53 +01:00
parent b876bad3e7
commit c6f8365e54
7 changed files with 196 additions and 261 deletions

View File

@ -285,10 +285,6 @@ public class PermissionManager implements UserDataProvider {
permissionsExpires = permissionMapping.getExpires(); permissionsExpires = permissionMapping.getExpires();
} }
if (permissionMapping.isLifetimeRound()) {
permissionStarts = InstantHelper.truncate(permissionStarts, permissionMapping.getLifetimeUnit());
}
if (permissionsExpires == null) { if (permissionsExpires == null) {
permissionsExpires = InstantHelper.plus(permissionStarts == null ? Instant.now() : permissionStarts, permissionsExpires = InstantHelper.plus(permissionStarts == null ? Instant.now() : permissionStarts,
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit()); permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit());

View File

@ -14,14 +14,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.beust.jcommander.internal.Lists;
import de.bstly.we.partey.api.controller.model.MapDetailsData; import de.bstly.we.partey.api.controller.model.MapDetailsData;
import de.bstly.we.partey.api.controller.support.DebugLogger; import de.bstly.we.partey.api.controller.support.DebugLogger;
import de.bstly.we.partey.api.security.ParteyApiAuthentication; import de.bstly.we.partey.api.security.ParteyApiAuthentication;
import de.bstly.we.partey.businesslogic.ParteyMapManager; import de.bstly.we.partey.businesslogic.ParteyMapManager;
import de.bstly.we.partey.businesslogic.model.Room; import de.bstly.we.partey.businesslogic.model.Room;
import de.bstly.we.partey.model.GameRoomPolicyTypes;
/** /**
* The Class MapController. * The Class MapController.
@ -51,19 +48,13 @@ public class MapController extends DebugLogger {
debugPrintRequest(request); debugPrintRequest(request);
MapDetailsData mapData = new MapDetailsData(); MapDetailsData mapData = new MapDetailsData();
mapData.setTags(Lists.newArrayList());
mapData.setPolicy_type(GameRoomPolicyTypes.UNKNOWN);
Room room = parteyMapManager.parseRoom(playUri, request); Room room = parteyMapManager.parseRoom(playUri, request);
if (room.isAuthenticationMandatory()) {
mapData.setAuthenticationMandatory(true);
}
mapData.setMapUrl(room.getMapUrl()); mapData.setMapUrl(room.getMapUrl());
mapData.setExpireOn("");
if (room.getTags() != null) {
mapData.setTags(room.getTags());
}
if (room.getPolicyType() != null) {
mapData.setPolicy_type(room.getPolicyType());
}
debugPrintResponse(request, Optional.of(mapData)); debugPrintResponse(request, Optional.of(mapData));

View File

@ -7,139 +7,55 @@ import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import de.bstly.we.partey.model.GameRoomPolicyTypes;
/** /**
* The Class MapDetailsData. * The Class MapDetailsData.
*/ */
public class MapDetailsData { public class MapDetailsData {
private String mapUrl = ""; private String mapUrl = "";
private GameRoomPolicyTypes policy_type = GameRoomPolicyTypes.ANONYMOUS_POLICY;
private List<String> tags = Lists.newArrayList();
private boolean authenticationMandatory; private boolean authenticationMandatory;
private String roomSlug;
private String contactPage;
private String group; private String group;
private List<Object> mucRooms = Lists.newArrayList();
private String contactPage;
private String iframeAuthentication; private String iframeAuthentication;
private String expireOn;
private boolean canReport = true;
private String loadingCowebsiteLogo;
private String miniLogo; private String miniLogo;
private String loadingLogo; private String loadingLogo;
private String loginSceneLogo; private String loginSceneLogo;
private boolean showPoweredBy = false; private boolean showPoweredBy = false;
private String loadingCowebsiteLogo; private Object thirdParty;
private boolean canReport = true;
/** /**
* Gets the map url. * @return the mapUrl
*
* @return the map url
*/ */
public String getMapUrl() { public String getMapUrl() {
return mapUrl; return mapUrl;
} }
/** /**
* Sets the map url. * @param mapUrl the mapUrl to set
*
* @param mapUrl the new map url
*/ */
public void setMapUrl(String mapUrl) { public void setMapUrl(String mapUrl) {
this.mapUrl = mapUrl; this.mapUrl = mapUrl;
} }
/** /**
* Gets the policy type. * @return the authenticationMandatory
*
* @return the policy type
*/
public GameRoomPolicyTypes getPolicy_type() {
return policy_type;
}
/**
* Sets the policy type.
*
* @param policy_type the new policy type
*/
public void setPolicy_type(GameRoomPolicyTypes policy_type) {
this.policy_type = policy_type;
}
/**
* Gets the tags.
*
* @return the tags
*/
public List<String> getTags() {
return tags;
}
/**
* Sets the tags.
*
* @param tags the new tags
*/
public void setTags(List<String> tags) {
this.tags = tags;
}
/**
* Checks if is authentication mandatory.
*
* @return true, if is authentication mandatory
*/ */
public boolean isAuthenticationMandatory() { public boolean isAuthenticationMandatory() {
return authenticationMandatory; return authenticationMandatory;
} }
/** /**
* Sets the authentication mandatory. * @param authenticationMandatory the authenticationMandatory to set
*
* @param authenticationMandatory the new authentication mandatory
*/ */
public void setAuthenticationMandatory(boolean authenticationMandatory) { public void setAuthenticationMandatory(boolean authenticationMandatory) {
this.authenticationMandatory = authenticationMandatory; this.authenticationMandatory = authenticationMandatory;
} }
/** /**
* Gets the room slug.
*
* @return the room slug
*/
public String getRoomSlug() {
return roomSlug;
}
/**
* Sets the room slug.
*
* @param roomSlug the new room slug
*/
public void setRoomSlug(String roomSlug) {
this.roomSlug = roomSlug;
}
/**
* Gets the contact page.
*
* @return the contact page
*/
public String getContactPage() {
return contactPage;
}
/**
* Sets the contact page.
*
* @param contactPage the new contact page
*/
public void setContactPage(String contactPage) {
this.contactPage = contactPage;
}
/**
* Gets the group.
*
* @return the group * @return the group
*/ */
public String getGroup() { public String getGroup() {
@ -147,138 +63,164 @@ public class MapDetailsData {
} }
/** /**
* Sets the group. * @param group the group to set
*
* @param group the new group
*/ */
public void setGroup(String group) { public void setGroup(String group) {
this.group = group; this.group = group;
} }
/** /**
* Gets the iframe authentication. * @return the mucRooms
* */
* @return the iframe authentication public List<Object> getMucRooms() {
return mucRooms;
}
/**
* @param mucRooms the mucRooms to set
*/
public void setMucRooms(List<Object> mucRooms) {
this.mucRooms = mucRooms;
}
/**
* @return the contactPage
*/
public String getContactPage() {
return contactPage;
}
/**
* @param contactPage the contactPage to set
*/
public void setContactPage(String contactPage) {
this.contactPage = contactPage;
}
/**
* @return the iframeAuthentication
*/ */
public String getIframeAuthentication() { public String getIframeAuthentication() {
return iframeAuthentication; return iframeAuthentication;
} }
/** /**
* Sets the iframe authentication. * @param iframeAuthentication the iframeAuthentication to set
*
* @param iframeAuthentication the new iframe authentication
*/ */
public void setIframeAuthentication(String iframeAuthentication) { public void setIframeAuthentication(String iframeAuthentication) {
this.iframeAuthentication = iframeAuthentication; this.iframeAuthentication = iframeAuthentication;
} }
/** /**
* Gets the mini logo. * @return the expireOn
*
* @return the mini logo
*/ */
public String getMiniLogo() { public String getExpireOn() {
return miniLogo; return expireOn;
} }
/** /**
* Sets the mini logo. * @param expireOn the expireOn to set
*
* @param miniLogo the new mini logo
*/ */
public void setMiniLogo(String miniLogo) { public void setExpireOn(String expireOn) {
this.miniLogo = miniLogo; this.expireOn = expireOn;
} }
/** /**
* Gets the loading logo. * @return the canReport
*
* @return the loading logo
*/
public String getLoadingLogo() {
return loadingLogo;
}
/**
* Sets the loading logo.
*
* @param loadingLogo the new loading logo
*/
public void setLoadingLogo(String loadingLogo) {
this.loadingLogo = loadingLogo;
}
/**
* Gets the login scene logo.
*
* @return the login scene logo
*/
public String getLoginSceneLogo() {
return loginSceneLogo;
}
/**
* Sets the login scene logo.
*
* @param loginSceneLogo the new login scene logo
*/
public void setLoginSceneLogo(String loginSceneLogo) {
this.loginSceneLogo = loginSceneLogo;
}
/**
* Checks if is show powered by.
*
* @return true, if is show powered by
*/
public boolean isShowPoweredBy() {
return showPoweredBy;
}
/**
* Sets the show powered by.
*
* @param showPoweredBy the new show powered by
*/
public void setShowPoweredBy(boolean showPoweredBy) {
this.showPoweredBy = showPoweredBy;
}
/**
* Gets the loading cowebsite logo.
*
* @return the loading cowebsite logo
*/
public String getLoadingCowebsiteLogo() {
return loadingCowebsiteLogo;
}
/**
* Sets the loading cowebsite logo.
*
* @param loadingCowebsiteLogo the new loading cowebsite logo
*/
public void setLoadingCowebsiteLogo(String loadingCowebsiteLogo) {
this.loadingCowebsiteLogo = loadingCowebsiteLogo;
}
/**
* Checks if is can report.
*
* @return true, if is can report
*/ */
public boolean isCanReport() { public boolean isCanReport() {
return canReport; return canReport;
} }
/** /**
* Sets the can report. * @param canReport the canReport to set
*
* @param canReport the new can report
*/ */
public void setCanReport(boolean canReport) { public void setCanReport(boolean canReport) {
this.canReport = canReport; this.canReport = canReport;
} }
/**
* @return the loadingCowebsiteLogo
*/
public String getLoadingCowebsiteLogo() {
return loadingCowebsiteLogo;
}
/**
* @param loadingCowebsiteLogo the loadingCowebsiteLogo to set
*/
public void setLoadingCowebsiteLogo(String loadingCowebsiteLogo) {
this.loadingCowebsiteLogo = loadingCowebsiteLogo;
}
/**
* @return the miniLogo
*/
public String getMiniLogo() {
return miniLogo;
}
/**
* @param miniLogo the miniLogo to set
*/
public void setMiniLogo(String miniLogo) {
this.miniLogo = miniLogo;
}
/**
* @return the loadingLogo
*/
public String getLoadingLogo() {
return loadingLogo;
}
/**
* @param loadingLogo the loadingLogo to set
*/
public void setLoadingLogo(String loadingLogo) {
this.loadingLogo = loadingLogo;
}
/**
* @return the loginSceneLogo
*/
public String getLoginSceneLogo() {
return loginSceneLogo;
}
/**
* @param loginSceneLogo the loginSceneLogo to set
*/
public void setLoginSceneLogo(String loginSceneLogo) {
this.loginSceneLogo = loginSceneLogo;
}
/**
* @return the showPoweredBy
*/
public boolean isShowPoweredBy() {
return showPoweredBy;
}
/**
* @param showPoweredBy the showPoweredBy to set
*/
public void setShowPoweredBy(boolean showPoweredBy) {
this.showPoweredBy = showPoweredBy;
}
/**
* @return the thirdParty
*/
public Object getThirdParty() {
return thirdParty;
}
/**
* @param thirdParty the thirdParty to set
*/
public void setThirdParty(Object thirdParty) {
this.thirdParty = thirdParty;
}
} }

View File

@ -20,6 +20,9 @@ public class MemberData {
private List<Object> messages = Lists.newArrayList(); private List<Object> messages = Lists.newArrayList();
private boolean anonymous; private boolean anonymous;
private String userRoomToken; private String userRoomToken;
private String jabberId;
private String jabberPassword;
private List<Object> mucRooms = Lists.newArrayList();
/** /**
* Gets the email. * Gets the email.
@ -165,4 +168,46 @@ public class MemberData {
this.userRoomToken = userRoomToken; this.userRoomToken = userRoomToken;
} }
/**
* @return the jabberId
*/
public String getJabberId() {
return jabberId;
}
/**
* @param jabberId the jabberId to set
*/
public void setJabberId(String jabberId) {
this.jabberId = jabberId;
}
/**
* @return the jabberPassword
*/
public String getJabberPassword() {
return jabberPassword;
}
/**
* @param jabberPassword the jabberPassword to set
*/
public void setJabberPassword(String jabberPassword) {
this.jabberPassword = jabberPassword;
}
/**
* @return the mucRooms
*/
public List<Object> getMucRooms() {
return mucRooms;
}
/**
* @param mucRooms the mucRooms to set
*/
public void setMucRooms(List<Object> mucRooms) {
this.mucRooms = mucRooms;
}
} }

View File

@ -20,10 +20,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import com.beust.jcommander.internal.Lists;
import de.bstly.we.partey.businesslogic.model.Room; import de.bstly.we.partey.businesslogic.model.Room;
import de.bstly.we.partey.model.GameRoomPolicyTypes;
import de.bstly.we.partey.model.ParteyMap; import de.bstly.we.partey.model.ParteyMap;
import de.bstly.we.partey.repository.ParteyMapRepository; import de.bstly.we.partey.repository.ParteyMapRepository;
@ -38,6 +35,8 @@ public class ParteyMapManager {
@Value("${we.bstly.partey.mapUrl:http://localhost/}") @Value("${we.bstly.partey.mapUrl:http://localhost/}")
private String internalMapUri; private String internalMapUri;
@Value("${we.bstly.partey.startRoom:}")
private String startRoom;
private Pattern internalMapUriPattern = Pattern.compile("\\/@\\/(.+)"); private Pattern internalMapUriPattern = Pattern.compile("\\/@\\/(.+)");
private Pattern externalMapUriPattern = Pattern.compile("\\/_\\/[^/]+\\/(.+)"); private Pattern externalMapUriPattern = Pattern.compile("\\/_\\/[^/]+\\/(.+)");
@ -96,8 +95,6 @@ public class ParteyMapManager {
*/ */
public Room parseRoom(String url, HttpServletRequest request) { public Room parseRoom(String url, HttpServletRequest request) {
Room room = new Room(); Room room = new Room();
room.setPolicyType(GameRoomPolicyTypes.UNKNOWN);
room.setTags(Lists.newArrayList());
room.setUrl(url); room.setUrl(url);
URI uri; URI uri;
try { try {
@ -110,7 +107,7 @@ public class ParteyMapManager {
Matcher externalMatcher = externalMapUriPattern.matcher(uri.getPath()); Matcher externalMatcher = externalMapUriPattern.matcher(uri.getPath());
if (internalMatcher.matches()) { if (internalMatcher.matches()) {
room.setPolicyType(GameRoomPolicyTypes.MEMBERS_ONLY_POLICY); room.setAuthenticationMandatory(true);
room.setMapId(internalMatcher.group(1)); room.setMapId(internalMatcher.group(1));
room.setMapUrl(internalMapUri + room.getMapId()); room.setMapUrl(internalMapUri + room.getMapId());
} else if (externalMatcher.matches()) { } else if (externalMatcher.matches()) {
@ -120,20 +117,13 @@ public class ParteyMapManager {
} else { } else {
room.setMapUrl(request.getScheme() + "://" + room.getMapId()); room.setMapUrl(request.getScheme() + "://" + room.getMapId());
} }
} else if (StringUtils.hasText(startRoom)) {
room.setMapId(startRoom);
room.setMapUrl(internalMapUri + room.getMapId());
} else { } else {
throw new ResponseStatusException(HttpStatus.CONFLICT, "invalid playUri"); throw new ResponseStatusException(HttpStatus.CONFLICT, "invalid playUri");
} }
ParteyMap parteyMap = get(room.getMapId());
if (parteyMap != null) {
if (parteyMap.getPolicyType() != null) {
room.setPolicyType(parteyMap.getPolicyType());
}
if (parteyMap.getTags() != null) {
room.setTags(parteyMap.getTags());
}
}
return room; return room;
} }

View File

@ -3,12 +3,6 @@
*/ */
package de.bstly.we.partey.businesslogic.model; package de.bstly.we.partey.businesslogic.model;
import java.util.List;
import com.google.common.collect.Lists;
import de.bstly.we.partey.model.GameRoomPolicyTypes;
/** /**
* The Class Room. * The Class Room.
*/ */
@ -17,8 +11,7 @@ public class Room {
private String url; private String url;
private String mapId; private String mapId;
private String mapUrl; private String mapUrl;
private GameRoomPolicyTypes policyType; private boolean authenticationMandatory;
private List<String> tags = Lists.newArrayList();
/** /**
* Gets the url. * Gets the url.
@ -75,39 +68,17 @@ public class Room {
} }
/** /**
* Gets the policy type. * @return the authenticationMandatory
*
* @return the policy type
*/ */
public GameRoomPolicyTypes getPolicyType() { public boolean isAuthenticationMandatory() {
return policyType; return authenticationMandatory;
} }
/** /**
* Sets the policy type. * @param authenticationMandatory the authenticationMandatory to set
*
* @param policyType the new policy type
*/ */
public void setPolicyType(GameRoomPolicyTypes policyType) { public void setAuthenticationMandatory(boolean authenticationMandatory) {
this.policyType = policyType; this.authenticationMandatory = authenticationMandatory;
}
/**
* Gets the tags.
*
* @return the tags
*/
public List<String> getTags() {
return tags;
}
/**
* Sets the tags.
*
* @param tags the new tags
*/
public void setTags(List<String> tags) {
this.tags = tags;
} }
} }

View File

@ -13,7 +13,7 @@
<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>
<log4j2.version>2.17.2</log4j2.version> <log4j2.version>2.17.2</log4j2.version>
<revision>1.9.1-SNAPSHOT</revision> <revision>1.9.2-SNAPSHOT</revision>
</properties> </properties>
<parent> <parent>