use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.
the class LDAPBackingEngine method listRoles.
@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);
}
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.
the class SyncopeBackingEngine method listRoles.
public List<RolePrincipal> listRoles(Principal principal) {
List<RolePrincipal> roles = new ArrayList<>();
HttpGet request = new HttpGet(address + "/users?username=" + principal.getName());
request.setHeader("Content-Type", "application/xml");
try {
HttpResponse response = client.execute(request);
String responseTO = EntityUtils.toString(response.getEntity());
if (responseTO != null && !responseTO.isEmpty()) {
int index = responseTO.indexOf("<roleName>");
while (index != 1) {
responseTO = responseTO.substring(index + "<roleName>".length());
int end = responseTO.indexOf("</roleName>");
if (end == -1) {
index = -1;
break;
}
String role = responseTO.substring(0, end);
roles.add(new RolePrincipal(role));
responseTO = responseTO.substring(end + "</roleName>".length());
index = responseTO.indexOf("<roleName>");
}
}
} catch (Exception e) {
throw new RuntimeException("Error listing roles", e);
}
return roles;
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.
the class PropertiesBackingEngine method listRoles.
private List<RolePrincipal> listRoles(String name) {
List<RolePrincipal> result = new ArrayList<>();
String userInfo = users.get(name);
String[] infos = userInfo.split(",");
for (int i = 1; i < infos.length; i++) {
String roleName = infos[i];
if (roleName.startsWith(GROUP_PREFIX)) {
for (RolePrincipal rp : listRoles(roleName)) {
if (!result.contains(rp)) {
result.add(rp);
}
}
} else {
RolePrincipal rp = new RolePrincipal(roleName);
if (!result.contains(rp)) {
result.add(rp);
}
}
}
return result;
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.
the class PublickeyBackingEngine method listRoles.
private List<RolePrincipal> listRoles(String name) {
List<RolePrincipal> result = new ArrayList<>();
String userInfo = users.get(name);
String[] infos = userInfo.split(",");
for (int i = 1; i < infos.length; i++) {
String roleName = infos[i];
if (roleName.startsWith(GROUP_PREFIX)) {
for (RolePrincipal rp : listRoles(roleName)) {
if (!result.contains(rp)) {
result.add(rp);
}
}
} else {
RolePrincipal rp = new RolePrincipal(roleName);
if (!result.contains(rp)) {
result.add(rp);
}
}
}
return result;
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.
the class PublickeyBackingEngine method addRole.
@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);
}
}
Aggregations