-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-55803] - Attempt to solve issue:removing the intermediate collections created each time getRolesHavingPermission() is invoked #54
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
0161a03
.
deepanshnagaria 4272e24
ATTEMPT TO SOLVE ISSUE
deepanshnagaria e267e58
ATTEMPT TO SOLVE ISSUE
deepanshnagaria d07716c
solved indentation issues
deepanshnagaria 34d3852
jenkins 55803
deepanshnagaria 3333460
jenkins 55803 further optimised
deepanshnagaria 158a04b
[JENKINS 55916] and [JENKINS:55803] improved RoleWalker + optimised h…
deepanshnagaria 32efae2
[JENKINS 55916] and [JENKINS:55803] improved RoleWalker + optimised h…
deepanshnagaria da0f23f
fixed conflict
deepanshnagaria 5bf5f19
k
deepanshnagaria 42cb0f6
sinked with pr 58
deepanshnagaria ad046c1
sinked with pr 58+ formatting
deepanshnagaria 8a4e6b5
sinked with pr 58
deepanshnagaria c3ffe35
formatting
deepanshnagaria e3f5463
troubleshooting
deepanshnagaria 8259b00
problem resolved
deepanshnagaria a288ec8
resolved unintentional formatting
deepanshnagaria ba6295a
Merge branch 'master' into master
oleg-nenashev 1face1c
formatting
deepanshnagaria 1aa43d3
formatting
deepanshnagaria 42a2e70
formatting
deepanshnagaria cf68543
formatting
deepanshnagaria cb9c4f0
formatting
deepanshnagaria 277b0ac
formatting
deepanshnagaria e8daa76
formatting
deepanshnagaria f572cb2
last
deepanshnagaria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,35 +109,49 @@ private boolean hasPermission(String sid, Permission p, RoleType roleType, Acces | |
/* if this is a dangerous permission, fall back to Administer unless we're in compat mode */ | ||
p = Jenkins.ADMINISTER; | ||
} | ||
|
||
for(Role role : getRolesHavingPermission(p)) { | ||
|
||
if(this.grantedRoles.get(role).contains(sid)) { | ||
final Set<Permission> permissions = new HashSet<>(); | ||
final Permission per = p; | ||
final boolean[] temp = {false}; | ||
// Get the implying permissions | ||
for (; p!=null; p=p.impliedBy) { | ||
permissions.add(p); | ||
} | ||
// Walk through the roles, and only add the roles having the given permission, | ||
// or a permission implying the given permission | ||
new RoleWalker() { | ||
public void perform(Role current) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to add an overide annotation here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure |
||
if (current.hasAnyPermission(permissions)) { | ||
if (grantedRoles.get(current).contains(sid)) { | ||
// Handle roles macro | ||
if (Macro.isMacro(role)) { | ||
Macro macro = RoleMacroExtension.getMacro(role.getName()); | ||
if (macro != null) { | ||
RoleMacroExtension macroExtension = RoleMacroExtension.getMacroExtension(macro.getName()); | ||
if (macroExtension.IsApplicable(roleType) && macroExtension.hasPermission(sid, p, roleType, controlledItem, macro)) { | ||
return true; | ||
} | ||
if (Macro.isMacro(current)) { | ||
Macro macro = RoleMacroExtension.getMacro(current.getName()); | ||
if (macro != null) { | ||
RoleMacroExtension macroExtension = RoleMacroExtension.getMacroExtension(macro.getName()); | ||
if (macroExtension.IsApplicable(roleType) && macroExtension.hasPermission(sid, per, roleType, controlledItem, macro)) { | ||
temp[0] =true; | ||
abort(); | ||
return ; | ||
} | ||
} // Default handling | ||
else { | ||
return true; | ||
} | ||
} else { | ||
temp[0] =true; | ||
abort(); | ||
return ; | ||
} | ||
} else if (Settings.TREAT_USER_AUTHORITIES_AS_ROLES) { | ||
} else if (Settings.TREAT_USER_AUTHORITIES_AS_ROLES) { | ||
try { | ||
UserDetails userDetails = cache.getIfPresent(sid); | ||
if (userDetails == null) { | ||
userDetails = Jenkins.getActiveInstance().getSecurityRealm().loadUserByUsername(sid); | ||
cache.put(sid, userDetails); | ||
} | ||
for (GrantedAuthority grantedAuthority : userDetails.getAuthorities()) { | ||
if (grantedAuthority.getAuthority().equals(role.getName())) { | ||
return true; | ||
} | ||
UserDetails userDetails = cache.getIfPresent(sid); | ||
if (userDetails == null) { | ||
userDetails = Jenkins.getActiveInstance().getSecurityRealm().loadUserByUsername(sid); | ||
cache.put(sid, userDetails); | ||
} | ||
for (GrantedAuthority grantedAuthority : userDetails.getAuthorities()) { | ||
if (grantedAuthority.getAuthority().equals(current.getName())) { | ||
temp[0] =true; | ||
abort(); | ||
return ; | ||
} | ||
} | ||
} catch (BadCredentialsException e) { | ||
LOGGER.log(Level.FINE, "Bad credentials", e); | ||
} catch (DataAccessException e) { | ||
|
@@ -147,11 +161,11 @@ private boolean hasPermission(String sid, Permission p, RoleType roleType, Acces | |
// So we want to ensure this method does not fail horribly in such case | ||
LOGGER.log(Level.WARNING, "Unhandled exception during user authorities processing", ex); | ||
} | ||
} | ||
} | ||
|
||
// TODO: Handle users macro | ||
} | ||
return false; | ||
} | ||
}; | ||
return temp[0]; | ||
} | ||
|
||
/** | ||
|
@@ -408,7 +422,7 @@ public static List<String> getMatchingJobNames(Pattern pattern, int maxJobs) { | |
|
||
return matchingJobNames; | ||
} | ||
|
||
/** | ||
* The Acl class that will delegate the permission check to the {@link RoleMap} object. | ||
*/ | ||
|
@@ -421,7 +435,7 @@ public AclImpl(RoleType roleType, AccessControlled item) { | |
this.item = item; | ||
this.roleType = roleType; | ||
} | ||
|
||
/** | ||
* Checks if the sid has the given permission. | ||
* <p>Actually only delegate the check to the {@link RoleMap} instance.</p> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional would be recommended, but ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sir i didn't understand.... Can you clarify a bit....?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html