Skip to content
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

Refactor Privileges API/Store to use separate class #31191

Merged
merged 8 commits into from
Jun 21, 2018

Conversation

tvernum
Copy link
Contributor

@tvernum tvernum commented Jun 8, 2018

The ApplicationPrivilege class had a dual purpose of defining
application privileges as stored in the security index, and also being
the means by which those privileges were tested against roles.
This made the class difficult to work with - in particular validation
was dependent on which purpose it was being used for.

This commit splits the index storage part into a new
ApplicationPrivilegeDescriptor class

The ApplicationPrivilege class had a dual purpose of defining
application privileges as stored in the security index, and also being
the means by which those privileges were tested against roles.
This made the class difficult to work with - in particular validation
was dependent on which purpose it was being used for.

This commit splits the index storage part into a new
ApplicationPrivilegeDescriptor class
Copy link
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. I left a few minor comments.

validationException = addValidationError(e.getMessage(), validationException);
}
try {
ApplicationPrivilege.validatePrivilegeName(privilege.getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I think this should be something else or removed?

@@ -13,6 +13,7 @@
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
import org.elasticsearch.xpack.core.security.authz.accesscontrol.IndicesAccessControl;
import org.elasticsearch.xpack.core.security.authz.privilege.ApplicationPrivilege;
import org.elasticsearch.xpack.core.security.authz.privilege.ApplicationPrivilegeDescriptor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed?

private static final Pattern VALID_NAME = Pattern.compile("^[a-z][a-zA-Z0-9_.-]*$");
private static final Pattern VALID_NAME_OR_ACTION = Pattern.compile("^\\p{Graph}*$");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind adding a comment about this? My regex isn't great so I had to go look up what this was

* @throws IllegalArgumentException if the name is not valid
*/
public static void validatePrivilegeOrActionName(String name) {
if(VALID_NAME_OR_ACTION.matcher(name).matches() == false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space between if and (

out.writeCollection(actions, StreamOutput::writeString);
out.writeMap(metadata);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

assertThat(exception, notNullValue());
assertThat(exception.validationErrors(), hasItem(containsString(message)));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

@tvernum
Copy link
Contributor Author

tvernum commented Jun 18, 2018

I've addressed all feedback on this PR.

Copy link
Contributor

@albertzaharovits albertzaharovits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat! LGTM Thanks!

Copy link
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


/**
* A name or action must be composed of printable, visible ASCII characters.
* That is: letters, numbers & symbols, but no whitespace.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the & needs to be &

# Conflicts:
#	x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ApplicationPrivilege.java
#	x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/privilege/TransportGetPrivilegesAction.java
@tvernum tvernum merged commit ecea2e4 into elastic:security-app-privs Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants