1 19 20 package com.sslexplorer.security.itemactions; 21 22 import com.sslexplorer.boot.Util; 23 import com.sslexplorer.core.UserDatabaseManager; 24 import com.sslexplorer.policyframework.Permission; 25 import com.sslexplorer.policyframework.PolicyConstants; 26 import com.sslexplorer.policyframework.PolicyDatabaseFactory; 27 import com.sslexplorer.policyframework.ResourceType; 28 import com.sslexplorer.policyframework.itemactions.AbstractPathAction; 29 import com.sslexplorer.security.SessionInfo; 30 import com.sslexplorer.security.User; 31 import com.sslexplorer.security.UserDatabase; 32 import com.sslexplorer.security.UserItem; 33 import com.sslexplorer.table.AvailableTableItemAction; 34 35 38 public class EditAccountTableAction extends AbstractPathAction { 39 private final boolean requiresPasswordSupport; 40 private final boolean requiresAccountCreationSupport; 41 42 48 public EditAccountTableAction(String actionName, int weight, boolean important, String requiredPath) { 49 this(actionName, weight, important, requiredPath, false, false); 50 } 51 52 59 public EditAccountTableAction(String actionName, String messageResourcesKey, int weight, boolean important, String requiredPath) { 60 this(actionName, messageResourcesKey, weight, important, requiredPath, false, false); 61 } 62 63 71 public EditAccountTableAction(String actionName, int weight, boolean important, String requiredPath, boolean requiresPasswordSupport, boolean requiresAccountCreationSupport) { 72 this(actionName, "security", weight, important, requiredPath, requiresPasswordSupport, requiresAccountCreationSupport); 73 } 74 75 84 public EditAccountTableAction(String actionName, String messageResourcesKey, int weight, boolean important, String requiredPath, boolean requiresPasswordSupport, boolean requiresAccountCreationSupport) { 85 super(actionName, messageResourcesKey, weight, important, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, requiredPath); 86 this.requiresPasswordSupport = requiresPasswordSupport; 87 this.requiresAccountCreationSupport = requiresAccountCreationSupport; 88 } 89 90 94 @Override 95 public String getPath(AvailableTableItemAction availableItem) { 96 UserItem item = (UserItem) availableItem.getRowItem(); 97 String principalName = item.getUser().getPrincipalName(); 98 String encodedPrincipalName = Util.urlEncode(principalName); 99 return getPath(encodedPrincipalName, availableItem); 100 } 101 102 106 public boolean isEnabled(AvailableTableItemAction availableItem) { 107 try { 108 User user = availableItem.getSessionInfo().getUser(); 109 UserItem item = (UserItem) availableItem.getRowItem(); 110 return isPermitted(user) && isEnabled(item); 111 } catch (Exception e) { 112 return false; 113 } 114 } 115 116 private boolean isPermitted(User user) throws Exception { 117 ResourceType resourceType = PolicyDatabaseFactory.getInstance().getResourceType(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE_ID); 118 Permission[] permissions = getPermissions(resourceType); 119 boolean isPermitted = permissions.length == 0 ? true : PolicyDatabaseFactory.getInstance().isPermitted(resourceType, permissions, user, true); 120 121 UserDatabase userDatabase = UserDatabaseManager.getInstance().getUserDatabase(user.getRealm().getResourceId()); 122 if(requiresPasswordSupport) { 123 isPermitted = isPermitted && userDatabase.supportsPasswordChange(); 124 } 125 if(requiresAccountCreationSupport) { 126 isPermitted = isPermitted && userDatabase.supportsAccountCreation(); 127 } 128 return isPermitted; 129 } 130 131 135 public Permission[] getPermissions(ResourceType resourceType) { 136 return new Permission[] {resourceType.getPermission(PolicyConstants.PERM_CREATE_AND_ASSIGN_ID)}; 137 } 138 139 144 public boolean isEnabled(UserItem userItem) throws Exception { 145 return true; 146 } 147 } | Popular Tags |