Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
package base.jee.api.cassandra;
import java.io.IOException;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.PreparedStatement;
import java.util.UUID;
import base.Command;
import base.jee.Constants;
import base.json.Json;
import base.security.ResourceUid;
import base.security.User;
import static base.jee.api.cassandra.util.Log.log;
import static base.jee.api.cassandra.util.UpdatePersonTokenRoleString.updatePersonTokenRoleString;
public class DeleteRole extends Command {
private CassandraAPI c;
private User updator;
private UUID personUuid;
private String role;
public DeleteRole(CassandraAPI c, User user, UUID personUuid, String role) {
if(c == null) {
throw new IllegalArgumentException("Invalid parameter: c");
}
if(role == null || role.length() == 0) {
throw new IllegalArgumentException("Invalid parameter: role");
}
if(user == null || !user.isAuthenticated()) {
throw new IllegalArgumentException("Invalid parameter: user");
}
if(personUuid == null) {
throw new IllegalArgumentException("Invalid parameter: personId");
}
if(role.trim().length() > Constants.MAX_ROLE_NAME_LENGTH) {
throw new IllegalArgumentException("Role names should not have more than " + Constants.MAX_ROLE_NAME_LENGTH + " characters.");
}
this.c = c;
this.personUuid = personUuid;
this.role = role.trim();
this.updator = user;
}
public DeleteRole() {
}
@Override
protected void execute() throws IOException {
Session s = c.getCassandraSession();
if(!updator.hasRole(Constants.PERSON_MANAGE_ROLE)) {
log(s, "WARN", updator, "Permission denied invoking: " + DeleteRole.class.getSimpleName() + " " + getJsonParameters());
throw new IllegalStateException("You do not have permission to manage roles.");
}
PreparedStatement p = s.prepare("delete from role where resource='#' and uid='#' and role=? and person_uuid=?");
s.execute(p.bind(role, personUuid));
updatePersonTokenRoleString(s, personUuid);
log(s, "INFO", updator, "Removed role " + role + " for person " + personUuid, new ResourceUid("Person", personUuid.toString()));
}
@Override
public String getJsonParameters() {
return "{" +
"\"person\":" + personUuid + "," +
"\"role\":\"" + Json.escape(role) + "\"," +
"\"updator.person\":" + updator.getPersonUuid() + "" +
"}";
}
}