use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.
the class GuardProxyCatalogTest method testInvocationBlocking6.
@SuppressWarnings("unchecked")
@Test
public void testInvocationBlocking6() throws Exception {
Dictionary<String, Object> c1 = new Hashtable<>();
c1.put(Constants.SERVICE_PID, "foobar");
c1.put("service.guard", "(objectClass=" + TestServiceAPI.class.getName() + ")");
c1.put("doit", "a,b");
Dictionary<String, Object> c2 = new Hashtable<>();
c2.put(Constants.SERVICE_PID, "foobar2");
c2.put("service.guard", "(objectClass=" + TestServiceAPI2.class.getName() + ")");
c2.put("bar", "c");
BundleContext bc = mockConfigAdminBundleContext(c1, c2);
final Object proxy = testCreateProxy(bc, new Class[] { TestServiceAPI2.class }, (TestServiceAPI2) String::toUpperCase);
// Invoke the service with role 'c'.
Subject subject = new Subject();
subject.getPrincipals().add(new RolePrincipal("a"));
subject.getPrincipals().add(new RolePrincipal("b"));
subject.getPrincipals().add(new RolePrincipal("c"));
Subject.doAs(subject, (PrivilegedAction<Object>) () -> {
try {
((TestServiceAPI2) proxy).doit("hello");
fail("The invocation should not process as the 'doit' operation has no roles associated with it");
} catch (SecurityException se) {
// good
}
return null;
});
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project activemq-artemis by apache.
the class ArtemisFeatureTest method executeCommand.
protected String executeCommand(final String command, final Long timeout, final Boolean silent) {
String response;
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final PrintStream printStream = new PrintStream(byteArrayOutputStream);
final Session commandSession = sessionFactory.create(System.in, printStream, printStream);
commandSession.put("APPLICATION", System.getProperty("karaf.name", "root"));
commandSession.put("USER", USER);
FutureTask<String> commandFuture = new FutureTask<>(new Callable<String>() {
@Override
public String call() {
Subject subject = new Subject();
subject.getPrincipals().add(new UserPrincipal("admin"));
subject.getPrincipals().add(new RolePrincipal("admin"));
subject.getPrincipals().add(new RolePrincipal("manager"));
subject.getPrincipals().add(new RolePrincipal("viewer"));
return Subject.doAs(subject, new PrivilegedAction<String>() {
@Override
public String run() {
try {
if (!silent) {
System.out.println(command);
System.out.flush();
}
commandSession.execute(command);
} catch (Exception e) {
e.printStackTrace(System.err);
}
printStream.flush();
return byteArrayOutputStream.toString();
}
});
}
});
try {
executor.submit(commandFuture);
response = commandFuture.get(timeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
e.printStackTrace(System.err);
response = "SHELL COMMAND TIMED OUT: ";
}
LOG.info("Execute: " + command + " - Response:" + response);
return response;
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project fabric8 by jboss-fuse.
the class ZookeeperBackingEngine method listRoles.
private List<RolePrincipal> listRoles(String name) {
List<RolePrincipal> result = new ArrayList<RolePrincipal>();
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 fabric8 by jboss-fuse.
the class ZookeeperBackingEngine method addRole.
/**
* 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();
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project ddf by codice.
the class SecurityAssertionJwt method getPrincipals.
@Override
public Set<Principal> getPrincipals() {
Set<Principal> principals = new HashSet<>();
Principal primary = getPrincipal();
principals.add(primary);
principals.add(new RolePrincipal(primary.getName()));
for (AttributeStatement attributeStatement : getAttributeStatements()) {
for (Attribute attr : attributeStatement.getAttributes()) {
if (StringUtils.containsIgnoreCase(attr.getName(), "role")) {
for (final String attrValue : attr.getValues()) {
principals.add(new RolePrincipal(attrValue));
}
}
}
}
return principals;
}
Aggregations