use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.
the class ConfigManagedServiceFactoryTest method CheckEditByArbitraryAttribute.
private void CheckEditByArbitraryAttribute() throws IOException, InvalidSyntaxException {
executeCommand("config:edit '(test2=data2)'\n" + "config:property-set test1 data1new2\n" + "config:update", new RolePrincipal("manager"));
Configuration config = readConfig();
assertEquals("data1new2", config.getProperties().get("test1"));
assertEquals("data2", config.getProperties().get("test2"));
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.
the class JdbcLoginModuleTest method testLoginModuleWithGroups.
@Test
public void testLoginModuleWithGroups() throws Exception {
JDBCBackingEngine engine = new JDBCBackingEngine(dataSource);
engine.addGroupRole("group1", "role2");
engine.addUser("abc", "xyz");
engine.addRole("abc", "role1");
engine.addGroup("abc", "group1");
JDBCLoginModule module = new JDBCLoginModule();
Subject subject = new Subject();
module.initialize(subject, new NamePasswordCallbackHandler("abc", "xyz"), null, options);
module.login();
module.commit();
assertTrue(subject.getPrincipals().contains(new UserPrincipal("abc")));
assertTrue(subject.getPrincipals().contains(new GroupPrincipal("group1")));
assertTrue(subject.getPrincipals().contains(new RolePrincipal("role1")));
assertTrue(subject.getPrincipals().contains(new RolePrincipal("role2")));
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.
the class PropertiesBackingEngine 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;
}
}
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);
}
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project ddf by codice.
the class Security method javaSubjectHasAdminRole.
/**
* Determines if the current Java {@link Subject} has the admin role.
*
* @return {@code true} if the Java {@link Subject} exists and has the admin role, {@code false} otherwise
*/
public boolean javaSubjectHasAdminRole() {
javax.security.auth.Subject subject = javax.security.auth.Subject.getSubject(AccessController.getContext());
if (subject != null) {
String localRoles = System.getProperty(KARAF_LOCAL_ROLE, "");
Collection<RolePrincipal> principals = new ArrayList<>();
for (String role : localRoles.split(",")) {
principals.add(new RolePrincipal(role));
}
return subject.getPrincipals().containsAll(principals);
}
return false;
}
use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project ddf by codice.
the class Security method getAdminJavaSubject.
private static javax.security.auth.Subject getAdminJavaSubject() {
Set<Principal> principals = new HashSet<>();
String localRoles = System.getProperty(KARAF_LOCAL_ROLE, "");
for (String role : localRoles.split(",")) {
principals.add(new RolePrincipal(role));
}
return new javax.security.auth.Subject(true, principals, new HashSet(), new HashSet());
}
Aggregations