@Override public List<RolePrincipal> listRoles(Principal principal) { return Arrays.asList( new RolePrincipal("admin"), new RolePrincipal("manager"), new RolePrincipal("viewer"), new RolePrincipal("systembundles") ); }
private List<String> displayGroupRoles(BackingEngine engine, String userName, GroupPrincipal group, ShellTable table) { List<String> names = new ArrayList<>(); List<RolePrincipal> roles = engine.listRoles(group); if (roles != null && roles.size() >= 1) { for (RolePrincipal role : roles) { String roleName = role.getName(); names.add(roleName); table.addRow().addContent(userName, group.getName(), roleName); } } return names; }
Set<Principal> subjectPrincipals = subject.getPrincipals(); //add the roles for (String role : userRolesList) { subjectPrincipals.add(new RolePrincipal(role)); }
private List<String> displayGroupRoles(BackingEngine engine, String userName, GroupPrincipal group, ShellTable table) { List<String> names = new ArrayList<>(); List<RolePrincipal> roles = engine.listRoles(group); if (roles != null && roles.size() >= 1) { for (RolePrincipal role : roles) { String roleName = role.getName(); names.add(roleName); table.addRow().addContent(userName, group.getName(), roleName); } } return names; }
@Override public Set<Principal> createPrincipals(final GrantedAuthority authority) { final String role = authority.getAuthority().replaceFirst("^[Rr][Oo][Ll][Ee]_", ""); final Set<Principal> principals = new HashSet<>(); principals.add(new RolePrincipal(role)); principals.add(new RolePrincipal(role.toLowerCase())); principals.add(new RolePrincipal(authority.getAuthority())); LOG.debug("created principals from authority {}: {}", authority, principals); return principals; }
/** * Add a role to a User. */ public void addRole(String username, String role) { String userInfos = users.get(username); if (userInfos != null) { for (RolePrincipal rp : listRoles(username)) { if (role.equals(rp.getName())) { return; } } for (GroupPrincipal gp : listGroups(username)) { if (role.equals(GROUP_PREFIX + gp.getName())) { return; } } String newUserInfos = userInfos + "," + role; users.put(username, newUserInfos); } saveUserProperties(); }
public void handleRoles(Subject subject,Set<Principal> principals,String discriminator) { for(Principal p:principals) { if(p instanceof RolePrincipal){ RolePrincipal rolePrincipal = new RolePrincipal(discriminator+p.getName()); subject.getPrincipals().add(rolePrincipal); } else { subject.getPrincipals().add(p); } } } },
@Override public void addRole(String username, String role) { String userInfos = users.get(username); if (userInfos != null) { for (RolePrincipal rp : listRoles(username)) { if (role.equals(rp.getName())) { return; } } String newUserInfos = userInfos + "," + role; users.put(username, newUserInfos); } try { users.save(); } catch (Exception ex) { LOGGER.error("Cannot update users file,", ex); } }
public void handleRoles(Subject subject,Set<Principal> principals,String discriminator) { for(Principal p:principals) { if(p instanceof RolePrincipal){ RolePrincipal rolePrincipal = new RolePrincipal(discriminator+p.getName()); subject.getPrincipals().add(rolePrincipal); } else { subject.getPrincipals().add(p); } } } },
@Override public void addRole(String username, String role) { String userInfos = users.get(username); if (userInfos != null) { for (RolePrincipal rp : listRoles(username)) { if (role.equals(rp.getName())) { return; } } String newUserInfos = userInfos + "," + role; users.put(username, newUserInfos); } try { users.save(); } catch (Exception ex) { LOGGER.error("Cannot update users file,", ex); } }
private List<RolePrincipal> listRoles(Connection connection, String name) throws SQLException { List<RolePrincipal> roles = new ArrayList<>(); for (String role : rawSelect(connection, selectRolesQuery, name)) { if (role.startsWith(GROUP_PREFIX)) { roles.addAll(listRoles(connection, role)); } else { roles.add(new RolePrincipal(role)); } } return roles; }
sb.append("org.apache.karaf.service.guard.roles"); sb.append('='); sb.append(escapeforFilterString(rp.getName())); sb.append(')');
private List<RolePrincipal> listRoles(Connection connection, String name) throws SQLException { List<RolePrincipal> roles = new ArrayList<>(); for (String role : rawSelect(connection, selectRolesQuery, name)) { if (role.startsWith(GROUP_PREFIX)) { roles.addAll(listRoles(connection, role)); } else { roles.add(new RolePrincipal(role)); } } return roles; }
@Override public void addRole(String username, String role) { String userInfos = users.get(username); if (userInfos != null) { for (RolePrincipal rp : listRoles(username)) { if (role.equals(rp.getName())) { return; } } for (GroupPrincipal gp : listGroups(username)) { if (role.equals(GROUP_PREFIX + gp.getName())) { return; } } String newUserInfos = userInfos + "," + role; users.put(username, newUserInfos); } try { users.save(); } catch (Exception ex) { LOGGER.error("Cannot update users file,", ex); } }
@Override public List<RolePrincipal> listRoles(Principal principal) { try { String[] userAndNameSpace = cache.getUserDnAndNamespace(principal.getName()); if (userAndNameSpace == null || userAndNameSpace.length < 2) return Collections.emptyList(); ArrayList<RolePrincipal> roles = new ArrayList<>(); for (String role : cache.getUserRoles(principal.getName(), userAndNameSpace[0], userAndNameSpace[1])) { roles.add(new RolePrincipal(role)); } return roles; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void addRole(String username, String role) { String userInfos = users.get(username); if (userInfos != null) { for (RolePrincipal rp : listRoles(username)) { if (role.equals(rp.getName())) { return; } } for (GroupPrincipal gp : listGroups(username)) { if (role.equals(GROUP_PREFIX + gp.getName())) { return; } } String newUserInfos = userInfos + "," + role; users.put(username, newUserInfos); } try { users.save(); } catch (Exception ex) { LOGGER.error("Cannot update users file,", ex); } }
private Subject createLocalKarafSubject() { String userName = System.getProperty(KARAF_LOCAL_USER); if (userName == null) { userName = "karaf"; } final Subject subject = new Subject(); subject.getPrincipals().add(new UserPrincipal(userName)); subject.getPrincipals().add(new ClientPrincipal("local", "localhost")); String roles = System.getProperty(KARAF_LOCAL_ROLES, KARAF_LOCAL_ROLES_DEFAULT); if (roles != null) { for (String role : roles.split("[,]")) { subject.getPrincipals().add(new RolePrincipal(role.trim())); } } return subject; }
@Override protected Object doExecute(BackingEngine engine) throws Exception { List<UserPrincipal> users = engine.listUsers(); ShellTable table = new ShellTable(); table.column("User Name"); table.column("Group"); table.column("Role"); for (UserPrincipal user : users) { List<String> reportedRoles = new ArrayList<>(); String userName = user.getName(); for (GroupPrincipal group : engine.listGroups(user)) { reportedRoles.addAll(displayGroupRoles(engine, userName, group, table)); } for (RolePrincipal role : engine.listRoles(user)) { String roleName = role.getName(); if (reportedRoles.contains(roleName)) { continue; } reportedRoles.add(roleName); table.addRow().addContent(userName, "", roleName); } if (reportedRoles.size() == 0) { table.addRow().addContent(userName, "", ""); } } table.print(System.out, !noFormat); return null; }
@Override public List<RolePrincipal> listRoles(Principal principal) { try { String[] userAndNameSpace = cache.getUserDnAndNamespace(principal.getName()); if (userAndNameSpace == null || userAndNameSpace.length < 2) return Collections.emptyList(); ArrayList<RolePrincipal> roles = new ArrayList<>(); for (String role : cache.getUserRoles(principal.getName(), userAndNameSpace[0], userAndNameSpace[1])) { roles.add(new RolePrincipal(role)); } return roles; } catch (Exception e) { throw new RuntimeException(e); } }
@Override protected Object doExecute(BackingEngine engine) throws Exception { List<UserPrincipal> users = engine.listUsers(); ShellTable table = new ShellTable(); table.column("User Name"); table.column("Group"); table.column("Role"); for (UserPrincipal user : users) { List<String> reportedRoles = new ArrayList<>(); String userName = user.getName(); for (GroupPrincipal group : engine.listGroups(user)) { reportedRoles.addAll(displayGroupRoles(engine, userName, group, table)); } for (RolePrincipal role : engine.listRoles(user)) { String roleName = role.getName(); if (reportedRoles.contains(roleName)) { continue; } reportedRoles.add(roleName); table.addRow().addContent(userName, "", roleName); } if (reportedRoles.size() == 0) { table.addRow().addContent(userName, "", ""); } } table.print(System.out, !noFormat); return null; }