use of org.apache.karaf.jaas.boot.principal.GroupPrincipal in project fabric8 by jboss-fuse.
the class ZookeeperBackingEngine method listGroups.
private List<GroupPrincipal> listGroups(String userName) {
List<GroupPrincipal> result = new ArrayList<GroupPrincipal>();
String userInfo = (String) users.get(userName);
if (userInfo != null) {
String[] infos = userInfo.split(",");
for (int i = 1; i < infos.length; i++) {
String name = infos[i];
if (name.startsWith(GROUP_PREFIX)) {
result.add(new GroupPrincipal(name.substring(GROUP_PREFIX.length())));
}
}
}
return result;
}
use of org.apache.karaf.jaas.boot.principal.GroupPrincipal in project fabric8 by jboss-fuse.
the class ZookeeperBackingEngine method deleteUser.
/**
* Delete a User.
*/
public void deleteUser(String username, boolean withoutGroupDeletionOnLastUser) {
// delete all its groups first, for garbage collection of the groups
for (GroupPrincipal gp : listGroups(username)) {
deleteGroup(username, gp.getName(), withoutGroupDeletionOnLastUser);
}
users.remove(username);
saveUserProperties();
}
use of org.apache.karaf.jaas.boot.principal.GroupPrincipal 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.GroupPrincipal 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.GroupPrincipal in project karaf by apache.
the class PublickeyLoginModule method login.
public boolean login() throws LoginException {
File f = new File(usersFile);
Properties users;
try {
users = new Properties(f);
} catch (IOException ioe) {
throw new LoginException("Unable to load user properties file " + f);
}
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("Username: ");
callbacks[1] = new PublickeyCallback();
try {
callbackHandler.handle(callbacks);
} catch (IOException ioe) {
throw new LoginException(ioe.getMessage());
} catch (UnsupportedCallbackException uce) {
throw new LoginException(uce.getMessage() + " not available to obtain information from user");
}
String user = ((NameCallback) callbacks[0]).getName();
if (user == null) {
throw new FailedLoginException("Unable to retrieve user name");
}
PublicKey key = ((PublickeyCallback) callbacks[1]).getPublicKey();
if (key == null) {
throw new FailedLoginException("Unable to retrieve public key");
}
// user infos container read from the users properties file
String userInfos = null;
try {
userInfos = users.get(user);
} catch (NullPointerException e) {
// error handled in the next statement
}
if (userInfos == null) {
if (!this.detailedLoginExcepion) {
throw new FailedLoginException("login failed");
} else {
throw new FailedLoginException("User " + user + " does not exist");
}
}
// the password is in the first position
String[] infos = userInfos.split(",");
String storedKey = infos[0];
// check the provided password
if (!getString(key).equals(storedKey)) {
if (!this.detailedLoginExcepion) {
throw new FailedLoginException("login failed");
} else {
throw new FailedLoginException("Public key for " + user + " does not match");
}
}
principals = new HashSet<>();
principals.add(new UserPrincipal(user));
for (int i = 1; i < infos.length; i++) {
if (infos[i].trim().startsWith(PropertiesBackingEngine.GROUP_PREFIX)) {
// it's a group reference
principals.add(new GroupPrincipal(infos[i].trim().substring(PropertiesBackingEngine.GROUP_PREFIX.length())));
String groupInfo = users.get(infos[i].trim());
if (groupInfo != null) {
String[] roles = groupInfo.split(",");
for (int j = 1; j < roles.length; j++) {
principals.add(new RolePrincipal(roles[j].trim()));
}
}
} else {
// it's an user reference
principals.add(new RolePrincipal(infos[i].trim()));
}
}
users.clear();
if (debug) {
LOG.debug("Successfully logged in " + user);
}
return true;
}
Aggregations