Skip to content

Commit

Permalink
GwtSession cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Nov 22, 2022
1 parent d637c09 commit aa826a7
Showing 1 changed file with 96 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,44 @@ public class GwtSession extends KapuaBaseModel implements Serializable {
private boolean ssoEnabled;
private boolean datastoreDisabled;

// User info
// Account info
private String accountId;
private String accountName;
private String accountPath;
private String rootAccountId;
private String rootAccountName;

// Selected Account info
private String selectedAccountId;
private String selectedAccountName;
private String selectedAccountPath;

// User info
private String userId;
private String userName;
private String userDisplayName;
private String openIDIdToken;

private String tokenId;

private String trustKey;
private String openIDIdToken;

// Permission info
private List<GwtSessionPermission> sessionPermissions = new ArrayList<GwtSessionPermission>();
private Map<GwtSessionPermission, Boolean> checkedPermissionsCache = new HashMap<GwtSessionPermission, Boolean>();

// UI
/**
* Is UI form dirty and needs save.
* <p>
* This field is set by UI to offer "Do you want to discard unsaved changes?" feature.
*
* @since 1.0.0
*/
private boolean formDirty;

public GwtSession() {
}

// Console info
public String getVersion() {
return version;
}
Expand All @@ -87,14 +94,23 @@ public void setBuildNumber(String buildNumber) {
this.buildNumber = buildNumber;
}

public String getUserId() {
return userId;
public boolean isSsoEnabled() {
return ssoEnabled;
}

public void setUserId(String userId) {
this.userId = userId;
public void setSsoEnabled(boolean ssoEnabled) {
this.ssoEnabled = ssoEnabled;
}

public boolean isDatastoreDisabled() {
return datastoreDisabled;
}

public void setDatastoreDisabled(boolean datastoreDisabled) {
this.datastoreDisabled = datastoreDisabled;
}

// Account info
public String getAccountId() {
return accountId;
}
Expand All @@ -103,6 +119,14 @@ public void setAccountId(String accountId) {
this.accountId = accountId;
}

public String getAccountName() {
return accountName;
}

public void setAccountName(String name) {
this.accountName = name;
}

public String getAccountPath() {
return accountPath;
}
Expand All @@ -111,28 +135,37 @@ public void setAccountPath(String accountPath) {
this.accountPath = accountPath;
}

public String getRootAccountId() {
return rootAccountId;
}

public void setRootAccountId(String rootAccountId) {
this.rootAccountId = rootAccountId;
}

public String getRootAccountId() {
return rootAccountId;
public String getRootAccountName() {
return rootAccountName;
}

public String getAccountName() {
return accountName;
public void setRootAccountName(String rootAccountName) {
this.rootAccountName = rootAccountName;
}

public void setAccountName(String name) {
this.accountName = name;
// Selected Account info
public String getSelectedAccountId() {
return selectedAccountId;
}

public void setSelectedAccountId(String selectedAccountId) {
this.selectedAccountId = selectedAccountId;
}

public String getSelectedAccountId() {
return selectedAccountId;
public String getSelectedAccountName() {
return selectedAccountName;
}

public void setSelectedAccountName(String selectedAccountName) {
this.selectedAccountName = selectedAccountName;
}

public String getSelectedAccountPath() {
Expand All @@ -143,6 +176,15 @@ public void setSelectedAccountPath(String selectedAccountPath) {
this.selectedAccountPath = selectedAccountPath;
}

// User info
public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public String getUserName() {
return userName;
}
Expand All @@ -159,22 +201,6 @@ public void setUserDisplayName(String userDisplayName) {
this.userDisplayName = userDisplayName;
}

public String getRootAccountName() {
return rootAccountName;
}

public void setRootAccountName(String rootAccountName) {
this.rootAccountName = rootAccountName;
}

public String getSelectedAccountName() {
return selectedAccountName;
}

public void setSelectedAccountName(String selectedAccountName) {
this.selectedAccountName = selectedAccountName;
}

public String getTokenId() {
return tokenId;
}
Expand All @@ -183,22 +209,23 @@ public void setTokenId(String tokenId) {
this.tokenId = tokenId;
}

public boolean isSsoEnabled() {
return ssoEnabled;
public String getTrustKey() {
return trustKey;
}

public void setSsoEnabled(boolean ssoEnabled) {
this.ssoEnabled = ssoEnabled;
public void setTrustKey(String trustKey) {
this.trustKey = trustKey;
}

public boolean isDatastoreDisabled() {
return datastoreDisabled;
public String getOpenIDIdToken() {
return openIDIdToken;
}

public void setDatastoreDisabled(boolean datastoreDisabled) {
this.datastoreDisabled = datastoreDisabled;
public void setOpenIDIdToken(String openIDIdToken) {
this.openIDIdToken = openIDIdToken;
}

// Permission info
public List<GwtSessionPermission> getSessionPermissions() {
if (sessionPermissions == null) {
sessionPermissions = new ArrayList<GwtSessionPermission>();
Expand All @@ -222,7 +249,7 @@ public void addSessionPermission(GwtSessionPermission permission) {
* @param domain The domain to check
* @param action The {@link GwtSessionPermissionAction} to check
* @param targetScope The {@link GwtSessionPermissionScope} to check
* @return {@code true} if the current {@link GwtSession} has the permission, {@false} otherwise
* @return {@code true} if the current {@link GwtSession} has the permission, {@code false} otherwise
* @since 1.0.0
*/
public boolean hasPermission(String domain, GwtSessionPermissionAction action, GwtSessionPermissionScope targetScope) {
Expand All @@ -239,14 +266,14 @@ public boolean hasPermission(String domain, GwtSessionPermissionAction action, G
* </p>
*
* @param permissionToCheck The {@link GwtSessionPermission} to check
* @return {@code true} if the current {@link GwtSession} has the permission, {@false} otherwise
* @return {@code true} if the current {@link GwtSession} has the permission, {@code false} otherwise
* @since 1.0.0
*/
public boolean hasPermission(GwtSessionPermission permissionToCheck) {
// Check cache
Boolean cachedResult = checkedPermissionsCache.get(permissionToCheck);
if (cachedResult != null) {
return cachedResult.booleanValue();
return cachedResult;
}

// Check permission
Expand All @@ -259,30 +286,12 @@ public boolean hasPermission(GwtSessionPermission permissionToCheck) {
return permitted;
}

/**
* Is UI form dirty and needs confirmation to switch menu.
*
* @return true if user needs to confirm menu change.
*/
public boolean isFormDirty() {
return formDirty;
}

/**
* Set user interface into dirty state.
*
* @param formDirty true if user will need to confirm menu change.
*/
public void setFormDirty(boolean formDirty) {
this.formDirty = formDirty;
}

/**
* This methods simulates the check that is performed by the {@link org.eclipse.kapua.service.authorization.AuthorizationService#isPermitted(Permission)}.
* {@link Permission#getForwardable()} property is supported in a different way, but produces the same results.
*
* @param permissionToCheck The {@link GwtSessionPermission} to check
* @return {@code true} if the current {@link GwtSession} has the permission, {@false} otherwise
* @return {@code true} if the current {@link GwtSession} has the permission, {@code false} otherwise
* @since 1.0.0
*/
private boolean isPermitted(GwtSessionPermission permissionToCheck) {
Expand All @@ -295,16 +304,16 @@ private boolean isPermitted(GwtSessionPermission permissionToCheck) {

boolean check = false;
switch (gsp.getPermissionScope()) {
case ALL:
check = true;
break;
case CHILDREN:
check = (GwtSessionPermissionScope.CHILDREN.equals(permissionToCheckScope) ||
GwtSessionPermissionScope.SELF.equals(permissionToCheckScope));
break;
case SELF:
check = GwtSessionPermissionScope.SELF.equals(permissionToCheckScope);
break;
case ALL:
check = true;
break;
case CHILDREN:
check = (GwtSessionPermissionScope.CHILDREN.equals(permissionToCheckScope) ||
GwtSessionPermissionScope.SELF.equals(permissionToCheckScope));
break;
case SELF:
check = GwtSessionPermissionScope.SELF.equals(permissionToCheckScope);
break;
}

if (check) {
Expand All @@ -317,20 +326,23 @@ private boolean isPermitted(GwtSessionPermission permissionToCheck) {
return false;
}

public String getOpenIDIdToken() {
return openIDIdToken;
}
// UI

public void setOpenIDIdToken(String openIDIdToken) {
this.openIDIdToken = openIDIdToken;
}

public String getTrustKey() {
return trustKey;
/**
* Is UI form dirty and needs confirmation to switch menu.
*
* @return true if user needs to confirm menu change.
*/
public boolean isFormDirty() {
return formDirty;
}

public void setTrustKey(String trustKey) {
this.trustKey = trustKey;
/**
* Set user interface into dirty state.
*
* @param formDirty true if user will need to confirm menu change.
*/
public void setFormDirty(boolean formDirty) {
this.formDirty = formDirty;
}

}

0 comments on commit aa826a7

Please sign in to comment.