add retrofit role requests

pull/5/head
Felix Prahl-Kamps 2019-07-16 14:53:36 +02:00
parent 25762d6a49
commit 55713e8a99
4 changed files with 348 additions and 0 deletions

View File

@ -23,9 +23,11 @@ import javax.net.ssl.X509TrustManager;
import lu.circl.mispbump.interfaces.MispRestInterface;
import lu.circl.mispbump.models.restModels.MispOrganisation;
import lu.circl.mispbump.models.restModels.MispRole;
import lu.circl.mispbump.models.restModels.MispServer;
import lu.circl.mispbump.models.restModels.MispUser;
import lu.circl.mispbump.models.restModels.Organisation;
import lu.circl.mispbump.models.restModels.Role;
import lu.circl.mispbump.models.restModels.Server;
import lu.circl.mispbump.models.restModels.User;
import lu.circl.mispbump.models.restModels.Version;
@ -176,6 +178,36 @@ public class MispRestClient {
});
}
public void getRoles(final AllRolesCallback callback) {
Call<List<MispRole>> call = mispRestInterface.getRoles();
call.enqueue(new Callback<List<MispRole>>() {
@Override
public void onResponse(Call<List<MispRole>> call, Response<List<MispRole>> response) {
if (!response.isSuccessful()) {
callback.failure(extractError(response));
return;
}
List<MispRole> mispRoles = response.body();
assert mispRoles != null;
Role[] roles = new Role[mispRoles.size()];
for (int i = 0; i < roles.length; i++) {
roles[i] = mispRoles.get(i).role;
}
callback.success(roles);
}
@Override
public void onFailure(Call<List<MispRole>> call, Throwable t) {
callback.failure(extractError(t));
}
});
}
/**
* Fetches information about the user that is associated with saved auth key.
@ -620,4 +652,10 @@ public class MispRestClient {
void failure(String error);
}
public interface AllRolesCallback {
void success(Role[] roles);
void failure(String error);
}
}

View File

@ -3,6 +3,7 @@ package lu.circl.mispbump.interfaces;
import java.util.List;
import lu.circl.mispbump.models.restModels.MispOrganisation;
import lu.circl.mispbump.models.restModels.MispRole;
import lu.circl.mispbump.models.restModels.MispServer;
import lu.circl.mispbump.models.restModels.MispUser;
import lu.circl.mispbump.models.restModels.Organisation;
@ -25,6 +26,9 @@ public interface MispRestInterface {
@GET("servers/getPyMISPVersion")
Call<Version> pyMispVersion();
@GET("admin/roles")
Call<List<MispRole>> getRoles();
// user routes
@GET("users/view/me")

View File

@ -0,0 +1,10 @@
package lu.circl.mispbump.models.restModels;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class MispRole {
@SerializedName("Role")
@Expose
public Role role;
}

View File

@ -0,0 +1,296 @@
package lu.circl.mispbump.models.restModels;
import com.google.gson.annotations.SerializedName;
public class Role {
@SerializedName("id")
private String id;
@SerializedName("name")
private String name;
@SerializedName("created")
private String created;
@SerializedName("modified")
private String modified;
@SerializedName("perm_add")
private Boolean permAdd;
@SerializedName("perm_modify")
private Boolean permModify;
@SerializedName("perm_modify_org")
private Boolean permModifyOrg;
@SerializedName("perm_publish")
private Boolean permPublish;
@SerializedName("perm_delegate")
private Boolean permDelegate;
@SerializedName("perm_sync")
private Boolean permSync;
@SerializedName("perm_admin")
private Boolean permAdmin;
@SerializedName("perm_audit")
private Boolean permAudit;
@SerializedName("perm_auth")
private Boolean permAuth;
@SerializedName("perm_site_admin")
private Boolean permSiteAdmin;
@SerializedName("perm_regexp_access")
private Boolean permRegexpAccess;
@SerializedName("perm_tagger")
private Boolean permTagger;
@SerializedName("perm_template")
private Boolean permTemplate;
@SerializedName("perm_sharing_group")
private Boolean permSharingGroup;
@SerializedName("perm_tag_editor")
private Boolean permTagEditor;
@SerializedName("perm_sighting")
private Boolean permSighting;
@SerializedName("perm_object_template")
private Boolean permObjectTemplate;
@SerializedName("default_role")
private Boolean defaultRole;
@SerializedName("memory_limit")
private String memoryLimit;
@SerializedName("max_execution_time")
private String maxExecutionTime;
@SerializedName("restricted_to_site_admin")
private Boolean restrictedToSiteAdmin;
@SerializedName("perm_publish_zmq")
private Boolean permPublishZmq;
@SerializedName("perm_publish_kafka")
private Boolean permPublishKafka;
@SerializedName("permission")
private String permission;
@SerializedName("permission_description")
private String permissionDescription;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
public String getModified() {
return modified;
}
public void setModified(String modified) {
this.modified = modified;
}
public Boolean getPermAdd() {
return permAdd;
}
public void setPermAdd(Boolean permAdd) {
this.permAdd = permAdd;
}
public Boolean getPermModify() {
return permModify;
}
public void setPermModify(Boolean permModify) {
this.permModify = permModify;
}
public Boolean getPermModifyOrg() {
return permModifyOrg;
}
public void setPermModifyOrg(Boolean permModifyOrg) {
this.permModifyOrg = permModifyOrg;
}
public Boolean getPermPublish() {
return permPublish;
}
public void setPermPublish(Boolean permPublish) {
this.permPublish = permPublish;
}
public Boolean getPermDelegate() {
return permDelegate;
}
public void setPermDelegate(Boolean permDelegate) {
this.permDelegate = permDelegate;
}
public Boolean getPermSync() {
return permSync;
}
public void setPermSync(Boolean permSync) {
this.permSync = permSync;
}
public Boolean getPermAdmin() {
return permAdmin;
}
public void setPermAdmin(Boolean permAdmin) {
this.permAdmin = permAdmin;
}
public Boolean getPermAudit() {
return permAudit;
}
public void setPermAudit(Boolean permAudit) {
this.permAudit = permAudit;
}
public Boolean getPermAuth() {
return permAuth;
}
public void setPermAuth(Boolean permAuth) {
this.permAuth = permAuth;
}
public Boolean getPermSiteAdmin() {
return permSiteAdmin;
}
public void setPermSiteAdmin(Boolean permSiteAdmin) {
this.permSiteAdmin = permSiteAdmin;
}
public Boolean getPermRegexpAccess() {
return permRegexpAccess;
}
public void setPermRegexpAccess(Boolean permRegexpAccess) {
this.permRegexpAccess = permRegexpAccess;
}
public Boolean getPermTagger() {
return permTagger;
}
public void setPermTagger(Boolean permTagger) {
this.permTagger = permTagger;
}
public Boolean getPermTemplate() {
return permTemplate;
}
public void setPermTemplate(Boolean permTemplate) {
this.permTemplate = permTemplate;
}
public Boolean getPermSharingGroup() {
return permSharingGroup;
}
public void setPermSharingGroup(Boolean permSharingGroup) {
this.permSharingGroup = permSharingGroup;
}
public Boolean getPermTagEditor() {
return permTagEditor;
}
public void setPermTagEditor(Boolean permTagEditor) {
this.permTagEditor = permTagEditor;
}
public Boolean getPermSighting() {
return permSighting;
}
public void setPermSighting(Boolean permSighting) {
this.permSighting = permSighting;
}
public Boolean getPermObjectTemplate() {
return permObjectTemplate;
}
public void setPermObjectTemplate(Boolean permObjectTemplate) {
this.permObjectTemplate = permObjectTemplate;
}
public Boolean getDefaultRole() {
return defaultRole;
}
public void setDefaultRole(Boolean defaultRole) {
this.defaultRole = defaultRole;
}
public String getMemoryLimit() {
return memoryLimit;
}
public void setMemoryLimit(String memoryLimit) {
this.memoryLimit = memoryLimit;
}
public String getMaxExecutionTime() {
return maxExecutionTime;
}
public void setMaxExecutionTime(String maxExecutionTime) {
this.maxExecutionTime = maxExecutionTime;
}
public Boolean getRestrictedToSiteAdmin() {
return restrictedToSiteAdmin;
}
public void setRestrictedToSiteAdmin(Boolean restrictedToSiteAdmin) {
this.restrictedToSiteAdmin = restrictedToSiteAdmin;
}
public Boolean getPermPublishZmq() {
return permPublishZmq;
}
public void setPermPublishZmq(Boolean permPublishZmq) {
this.permPublishZmq = permPublishZmq;
}
public Boolean getPermPublishKafka() {
return permPublishKafka;
}
public void setPermPublishKafka(Boolean permPublishKafka) {
this.permPublishKafka = permPublishKafka;
}
public String getPermission() {
return permission;
}
public void setPermission(String permission) {
this.permission = permission;
}
public String getPermissionDescription() {
return permissionDescription;
}
public void setPermissionDescription(String permissionDescription) {
this.permissionDescription = permissionDescription;
}
}