Skip to content

Commit

Permalink
Merge pull request #187 from bioinformatics-ua/imp/rbac
Browse files Browse the repository at this point in the history
RBAC + Restrictions to admin/non admin and restrictions for each web plugin
  • Loading branch information
bastiao committed Jan 28, 2016
2 parents b0f781c + 96c12e5 commit c4ffe89
Show file tree
Hide file tree
Showing 35 changed files with 1,161 additions and 158 deletions.
Empty file removed dicoogle/dicoogle.log
Empty file.
2 changes: 1 addition & 1 deletion dicoogle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>pt.ua.ieeta</groupId>
<artifactId>dicoogle-all</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.3.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
*/
package pt.ua.dicoogle.plugins.webui;

import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.slf4j.LoggerFactory;
import pt.ua.dicoogle.server.users.Role;
import pt.ua.dicoogle.server.users.RolesStruct;

import java.util.HashSet;
import java.util.Set;

/** A POJO data type containing the full description of a Web UI plugin.
*
Expand All @@ -35,6 +41,7 @@ public class WebUIPlugin implements Cloneable {
private String moduleFile;
private JSONObject settings;
private boolean enabled = true;
private Set<String> roles = new HashSet();

public WebUIPlugin() {}

Expand Down Expand Up @@ -75,6 +82,18 @@ public static WebUIPlugin fromPackageJSON(JSONObject obj) throws PluginFormatExc
plugin.slotId = objDicoogle.getString("slot-id");
plugin.moduleFile = objDicoogle.optString("module-file", "module.js");
plugin.caption = objDicoogle.optString("caption", null);
if (objDicoogle.containsKey("roles"))
{
JSONArray rolesArr = objDicoogle.getJSONArray("roles");

Set<String> roles = new HashSet<>();
if (rolesArr != null)
for (Object role : rolesArr) {

roles.add((String) role);
}
plugin.roles = roles;
}

return plugin;
} catch(JSONException ex) {
Expand Down Expand Up @@ -156,5 +175,8 @@ public String getCaption() {
public void setCaption(String caption) {
this.caption = caption;
}


public Set<String> getRoles() {
return roles;
}
}
67 changes: 67 additions & 0 deletions dicoogle/src/main/java/pt/ua/dicoogle/server/users/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright (C) 2014 Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
*
* This file is part of Dicoogle/dicoogle.
*
* Dicoogle/dicoogle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dicoogle/dicoogle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dicoogle. If not, see <http://www.gnu.org/licenses/>.
*/
package pt.ua.dicoogle.server.users;

/**
* Created by bastiao on 23/01/16.
*/
public class Role {


private String name;
public Role(String name)
{
this.name = name;

}


@Override
public String toString() {
return "Role{" +
"name='" + name + '\'' +
'}';
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}



@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Role role = (Role) o;

return !(name != null ? !name.equals(role.name) : role.name != null);

}

@Override
public int hashCode() {
return name != null ? name.hashCode() : 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (C) 2014 Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
*
* This file is part of Dicoogle/dicoogle.
*
* Dicoogle/dicoogle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dicoogle/dicoogle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dicoogle. If not, see <http://www.gnu.org/licenses/>.
*/
package pt.ua.dicoogle.server.users;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
* Created by bastiao on 23/01/16.
*/
public interface RoleManager {

public boolean hasRole(User user, Role r);
public Collection<Role> getRoles();
public void addRole(Role r);
public Role getRole(String name);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (C) 2014 Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
*
* This file is part of Dicoogle/dicoogle.
*
* Dicoogle/dicoogle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dicoogle/dicoogle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dicoogle. If not, see <http://www.gnu.org/licenses/>.
*/
package pt.ua.dicoogle.server.users;

import java.util.*;

/**
* Created by bastiao on 23/01/16.
*/
public class RolesStruct implements RoleManager{

private static RolesStruct instance = null ;

private Set<Role> roles = new HashSet<>();
private Map<String, Role> rolesMap = new HashMap<String, Role>();

public static synchronized RolesStruct getInstance() {
if (instance == null) {
instance = new RolesStruct();
}

return instance;
}
private RolesStruct(){
reset();
}

public void reset(){
roles = new HashSet<>();
}

@Override
public boolean hasRole(User user, Role r) {
if (user==null||r==null)
return false;
return UsersStruct.getInstance().getUser(user.getUsername()).hasRole(r);
}

@Override
public Set<Role> getRoles() {
return this.roles;
}

@Override
public void addRole(Role r) {
this.roles.add(r);
this.rolesMap.put(r.getName(), r);

}

@Override
public Role getRole(String name) {

return this.rolesMap.get(name);
}
}
Loading

0 comments on commit c4ffe89

Please sign in to comment.