Skip to content

Commit

Permalink
#28: add static role names and automatic role adder
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehertwig committed Nov 22, 2018
1 parent 5c409e1 commit f51ba58
Show file tree
Hide file tree
Showing 16 changed files with 332 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.chandre.admintool.core.sec;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.springframework.stereotype.Component;

import de.chandre.admintool.core.sec.AdminToolRoles;

/**
*
* @author Andre
* @since 1.2.0
*/
@Component
public class AdminToolCoreRoles implements AdminToolRoles {

public static String ROLE_ATCORE = "ATCORE";

@Override
public Collection<String> getRoles() {
return Collections.unmodifiableList(Arrays.asList(ROLE_ATCORE));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.chandre.admintool.core.sec;

import java.util.Collection;

/**
* interface for roles of a admintool component
* (placed in core to avoid interdependencies)
* @author Andre
* @since 1.2.0
*/
public interface AdminToolRoles {

Collection<String> getRoles();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.chandre.admintool.db;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.springframework.stereotype.Component;

import de.chandre.admintool.core.sec.AdminToolRoles;

/**
*
* @author Andre
* @since 1.2.0
*/
@Component
public class AdminToolDBBrowserRoles implements AdminToolRoles {

public static String ROLE_DBBROWSER = "DBBROWSER";

@Override
public Collection<String> getRoles() {
return Collections.unmodifiableList(Arrays.asList(ROLE_DBBROWSER));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.chandre.admintool.filebrowser;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.springframework.stereotype.Component;

import de.chandre.admintool.core.sec.AdminToolRoles;

/**
*
* @author Andre
* @since 1.2.0
*/
@Component
public class AdminToolFileBrowserRoles implements AdminToolRoles {

public static String ROLE_FILEBROWSER = "FILEBROWSER";

@Override
public Collection<String> getRoles() {
return Collections.unmodifiableList(Arrays.asList(ROLE_FILEBROWSER));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.chandre.admintool.fileviewer;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.springframework.stereotype.Component;

import de.chandre.admintool.core.sec.AdminToolRoles;

/**
*
* @author Andre
* @since 1.2.0
*/
@Component
public class AdminToolFileViewerRoles implements AdminToolRoles {

public static String ROLE_FILEVIEWER = "FILEVIEWER";

@Override
public Collection<String> getRoles() {
return Collections.unmodifiableList(Arrays.asList(ROLE_FILEVIEWER));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.chandre.admintool.jminix;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.springframework.stereotype.Component;

import de.chandre.admintool.core.sec.AdminToolRoles;

/**
*
* @author Andre
* @since 1.2.0
*/
@Component
public class AdminToolJmxRoles implements AdminToolRoles {

public static String ROLE_JMX = "JMX";

@Override
public Collection<String> getRoles() {
return Collections.unmodifiableList(Arrays.asList(ROLE_JMX));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.chandre.admintool.log4j2;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.springframework.stereotype.Component;

import de.chandre.admintool.core.sec.AdminToolRoles;

/**
*
* @author Andre
* @since 1.2.0
*/
@Component
public class AdminToolLog4jRoles implements AdminToolRoles {

public static String ROLE_LOG4J = "LOG4J";

public static String ROLE_LOG4J_LOGGERS = "LOG4J_LOGGERS";
public static String ROLE_LOG4J_CONSOLE = "LOG4J_CONSOLE";

@Override
public Collection<String> getRoles() {
return Collections.unmodifiableList(Arrays.asList(ROLE_LOG4J, ROLE_LOG4J_LOGGERS, ROLE_LOG4J_CONSOLE));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.chandre.admintool.melody;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.springframework.stereotype.Component;

import de.chandre.admintool.core.sec.AdminToolRoles;

/**
*
* @author Andre
* @since 1.2.0
*/
@Component
public class AdminToolMelodyRoles implements AdminToolRoles {

public static String ROLE_MELODY = "MELODY";

@Override
public Collection<String> getRoles() {
return Collections.unmodifiableList(Arrays.asList(ROLE_MELODY));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.chandre.admintool.properties;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.springframework.stereotype.Component;

import de.chandre.admintool.core.sec.AdminToolRoles;

/**
*
* @author Andre
* @since 1.2.0
*/
@Component
public class AdminToolPropertiesRoles implements AdminToolRoles {

public static String ROLE_PROPS = "PROPS";

@Override
public Collection<String> getRoles() {
return Collections.unmodifiableList(Arrays.asList(ROLE_PROPS));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.chandre.admintool.quartz;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.springframework.stereotype.Component;

import de.chandre.admintool.core.sec.AdminToolRoles;

/**
*
* @author Andre
* @since 1.2.0
*/
@Component
public class AdminToolQuartzRoles implements AdminToolRoles {

public static String ROLE_QUARTZ = "QUARTZ";

public static String ROLE_QUARTZ_CONFIG = "QUARTZ_CONFIG";
public static String ROLE_QUARTZ_JOBS = "QUARTZ_JOBS";

@Override
public Collection<String> getRoles() {
return Collections.unmodifiableList(Arrays.asList(ROLE_QUARTZ, ROLE_QUARTZ_CONFIG, ROLE_QUARTZ_JOBS));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.chandre.admintool.security.dbuser;

import java.util.HashSet;
import java.util.Collection;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;

Expand All @@ -17,6 +18,8 @@
import de.chandre.admintool.core.component.AdminComponent;
import de.chandre.admintool.core.component.AdminComponentImpl;
import de.chandre.admintool.core.component.MenuEntry;
import de.chandre.admintool.core.sec.AdminToolRoles;
import de.chandre.admintool.security.dbuser.service.AdminToolSecDBRoleService;

/**
*
Expand All @@ -37,6 +40,11 @@ public class AdminToolSecDBLoader extends AbstractAdminToolLoader {
@Autowired
private TemplateEngine templateEngine;

@Autowired
private AdminToolSecDBRoleService roleService;

@Autowired Collection<AdminToolRoles> atRoles;

@PostConstruct
public void configureAdminTool()
{
Expand All @@ -51,13 +59,13 @@ public void configureAdminTool()
templateEngine.addDialect(timeDialect);
}

LOGGER.info("adding database user management view to admin tool");
int roleInterfaceSize = atRoles != null ? atRoles.size() : 0;
LOGGER.info("found " + roleInterfaceSize + " interfaces with roles");
if (roleInterfaceSize > 0) {
roleService.addRolesIfNotExists(atRoles.stream().flatMap(roleI -> roleI.getRoles().stream()).collect(Collectors.toSet()));
}

HashSet<String> allRoles = new HashSet<>();
allRoles.addAll(config.getSecurityRolesClients());
allRoles.addAll(config.getSecurityRolesGroups());
allRoles.addAll(config.getSecurityRolesRoles());
allRoles.addAll(config.getSecurityRolesUsers());
LOGGER.info("adding database user management view to admin tool");

AdminComponent component = new AdminComponentImpl.AdminComponentBuilder()
.displayName("User-Management")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.chandre.admintool.security.dbuser;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.springframework.stereotype.Component;

import de.chandre.admintool.core.sec.AdminToolRoles;

/**
*
* @author Andre
* @since 1.2.0
*/
@Component
public class AdminToolSecDBRoles implements AdminToolRoles {

public static String ROLE_CLIENT = "CLIENT";
public static String ROLE_ROLES = "ROLES";
public static String ROLE_USERS = "USERS";
public static String ROLE_GROUPS = "GROUPS";
public static String ROLE_ACCMGMT = "ACCMGMT";

@Override
public Collection<String> getRoles() {
return Collections.unmodifiableList(Arrays.asList(ROLE_CLIENT, ROLE_ROLES, ROLE_USERS, ROLE_GROUPS, ROLE_ACCMGMT));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public interface RoleRepository extends JpaRepository<ATRole, String> {
@Query("SELECT r.name FROM ATRole r")
List<String> findAllRoleNames();

List<ATRole> findByNameIn(Set<String> ids);

List<ATRole> findByIdIn(Set<String> ids);

void deleteByName(String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface AdminToolSecDBRoleService {

Set<ATError> updateRole(AccessRelationTO accessRelationTO);

Set<ATError> addRolesIfNotExists(Set<String> roles);

}
Loading

0 comments on commit f51ba58

Please sign in to comment.