@Test public void test_isAuthorized_adminuser_success() { String username = "testuser1"; String powerToken = "self_support_token"; String userToken = "ordinary_client_token"; boolean admin = true; String safename = "mysafe01"; String safeType = "shared"; String path = "shared/mysafe01"; String latestPoliciesStr = "s_shared_mysafe01, safeadmin"; String policiesTobeCheckedStr = "s_shared_mysafe01"; String safeOwner = "owner@someorg.com"; String safeOwnerId = "normaluser"; UserDetails userDetails = createUserDetails(username, powerToken, userToken, admin); Safe safeMetaData = createSafe(safename, safeType, path, safeOwner, safeOwnerId); String[] latestPolicies = createLatestPolicies(latestPoliciesStr); ArrayList<String> policiesTobeChecked = createPoliciesTobeChecked(policiesTobeCheckedStr); boolean forceCapabilityCheck = true; boolean actual = authorizationUtils.isAuthorized(userDetails, safeMetaData, latestPolicies, policiesTobeChecked, forceCapabilityCheck); assertEquals(actual, true); }
public boolean isAuthorized(UserDetails userDetails, Safe safeMetaData, String[] latestPolicies, ArrayList<String> policiesTobeChecked, boolean forceCapabilityCheck) { boolean authorized = false; String powerToken = userDetails.getSelfSupportToken(); if (userDetails.isAdmin()) { return true; } else { if (userDetails.getUsername() != null && userDetails.getUsername().equalsIgnoreCase(safeMetaData.getSafeBasicDetails().getOwnerid())) { if (!forceCapabilityCheck) { return true; } } } String safeType = getSafeTypeFromPath(safeMetaData.getPath()); for (String policyTobeChecked: policiesTobeChecked) { String policyKeyTobeChecked = new StringBuffer().append(safeType).toString(); authorized = isAuthorized(latestPolicies, policyTobeChecked, policyKeyTobeChecked, powerToken); if (authorized) { break; } } return authorized; }
AuthorizationUtils { public boolean isAuthorized(UserDetails userDetails, Safe safeMetaData, String[] latestPolicies, ArrayList<String> policiesTobeChecked, boolean forceCapabilityCheck) { boolean authorized = false; String powerToken = userDetails.getSelfSupportToken(); if (userDetails.isAdmin()) { return true; } else { if (userDetails.getUsername() != null && userDetails.getUsername().equalsIgnoreCase(safeMetaData.getSafeBasicDetails().getOwnerid())) { if (!forceCapabilityCheck) { return true; } } } String safeType = getSafeTypeFromPath(safeMetaData.getPath()); for (String policyTobeChecked: policiesTobeChecked) { String policyKeyTobeChecked = new StringBuffer().append(safeType).toString(); authorized = isAuthorized(latestPolicies, policyTobeChecked, policyKeyTobeChecked, powerToken); if (authorized) { break; } } return authorized; } }
AuthorizationUtils { public boolean isAuthorized(UserDetails userDetails, Safe safeMetaData, String[] latestPolicies, ArrayList<String> policiesTobeChecked, boolean forceCapabilityCheck) { boolean authorized = false; String powerToken = userDetails.getSelfSupportToken(); if (userDetails.isAdmin()) { return true; } else { if (userDetails.getUsername() != null && userDetails.getUsername().equalsIgnoreCase(safeMetaData.getSafeBasicDetails().getOwnerid())) { if (!forceCapabilityCheck) { return true; } } } String safeType = getSafeTypeFromPath(safeMetaData.getPath()); for (String policyTobeChecked: policiesTobeChecked) { String policyKeyTobeChecked = new StringBuffer().append(safeType).toString(); authorized = isAuthorized(latestPolicies, policyTobeChecked, policyKeyTobeChecked, powerToken); if (authorized) { break; } } return authorized; } AuthorizationUtils(); }
AuthorizationUtils { public boolean isAuthorized(UserDetails userDetails, Safe safeMetaData, String[] latestPolicies, ArrayList<String> policiesTobeChecked, boolean forceCapabilityCheck) { boolean authorized = false; String powerToken = userDetails.getSelfSupportToken(); if (userDetails.isAdmin()) { return true; } else { if (userDetails.getUsername() != null && userDetails.getUsername().equalsIgnoreCase(safeMetaData.getSafeBasicDetails().getOwnerid())) { if (!forceCapabilityCheck) { return true; } } } String safeType = getSafeTypeFromPath(safeMetaData.getPath()); for (String policyTobeChecked: policiesTobeChecked) { String policyKeyTobeChecked = new StringBuffer().append(safeType).toString(); authorized = isAuthorized(latestPolicies, policyTobeChecked, policyKeyTobeChecked, powerToken); if (authorized) { break; } } return authorized; } AuthorizationUtils(); boolean isAuthorized(UserDetails userDetails, Safe safeMetaData, String[] latestPolicies, ArrayList<String> policiesTobeChecked, boolean forceCapabilityCheck); boolean containsAdminPolicies(List<String> policies, List<String> adminPolicies); boolean isAuthorizedCert(UserDetails userDetails, SSLCertificateMetadataDetails sslMetaData, String[] latestPolicies, ArrayList<String> policiesTobeChecked, boolean forceCapabilityCheck); }
AuthorizationUtils { public boolean isAuthorized(UserDetails userDetails, Safe safeMetaData, String[] latestPolicies, ArrayList<String> policiesTobeChecked, boolean forceCapabilityCheck) { boolean authorized = false; String powerToken = userDetails.getSelfSupportToken(); if (userDetails.isAdmin()) { return true; } else { if (userDetails.getUsername() != null && userDetails.getUsername().equalsIgnoreCase(safeMetaData.getSafeBasicDetails().getOwnerid())) { if (!forceCapabilityCheck) { return true; } } } String safeType = getSafeTypeFromPath(safeMetaData.getPath()); for (String policyTobeChecked: policiesTobeChecked) { String policyKeyTobeChecked = new StringBuffer().append(safeType).toString(); authorized = isAuthorized(latestPolicies, policyTobeChecked, policyKeyTobeChecked, powerToken); if (authorized) { break; } } return authorized; } AuthorizationUtils(); boolean isAuthorized(UserDetails userDetails, Safe safeMetaData, String[] latestPolicies, ArrayList<String> policiesTobeChecked, boolean forceCapabilityCheck); boolean containsAdminPolicies(List<String> policies, List<String> adminPolicies); boolean isAuthorizedCert(UserDetails userDetails, SSLCertificateMetadataDetails sslMetaData, String[] latestPolicies, ArrayList<String> policiesTobeChecked, boolean forceCapabilityCheck);  }