use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.
the class AuthorizationDAO method getUserAuthorizations.
@Override
public List<Authorization> getUserAuthorizations(String username, Map<String, Group> groups, Map<String, Role> roles) {
Connection conn = null;
List<Authorization> authorizations = new ArrayList<Authorization>();
PreparedStatement stat = null;
ResultSet res = null;
try {
conn = this.getConnection();
stat = conn.prepareStatement(GET_USER_AUTHORIZATIONS);
stat.setString(1, username);
res = stat.executeQuery();
while (res.next()) {
String groupname = res.getString(1);
Group group = (null != groupname) ? groups.get(groupname) : null;
String rolename = res.getString(2);
Role role = (null != rolename) ? roles.get(rolename) : null;
Authorization authorization = new Authorization(group, role);
if (!authorizations.contains(authorization)) {
authorizations.add(authorization);
}
}
} catch (Throwable t) {
_logger.error("Error loading user authorization", t);
throw new RuntimeException("Error loading user authorization", t);
} finally {
closeDaoResources(res, stat, conn);
}
return authorizations;
}
use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.
the class AuthorizationManager method isAuthOnGroupAndRole.
@Override
public boolean isAuthOnGroupAndRole(UserDetails user, String groupName, String roleName, boolean chechAdmin) {
if (null == user || (null == groupName && null == roleName)) {
return false;
}
List<Authorization> userAuths = user.getAuthorizations();
for (int i = 0; i < userAuths.size(); i++) {
Authorization userAuth = userAuths.get(i);
if (null == userAuth) {
continue;
}
Group group = userAuth.getGroup();
if ((null == group && null != groupName) || (null != group && null == groupName)) {
continue;
} else if (null != group && null != groupName) {
if (!chechAdmin && !groupName.equals(group.getName())) {
continue;
} else if (chechAdmin && !Group.ADMINS_GROUP_NAME.equals(group.getName())) {
continue;
}
}
Role role = userAuth.getRole();
if (null == roleName) {
return true;
} else {
boolean isSuper = role.hasPermission(Permission.SUPERUSER);
if (role.getName().equals(roleName) || (chechAdmin && isSuper)) {
return true;
}
}
}
return false;
}
use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.
the class TestUserAuthorizationAction method addTestUserAndAuthorities.
private void addTestUserAndAuthorities() throws ApsSystemException {
Group groupForTest = new Group();
groupForTest.setName(TEST_GROUP_NAME);
groupForTest.setDescription("group test description");
this._groupManager.addGroup(groupForTest);
Role roleForTest = new Role();
roleForTest.setName(TEST_ROLE_NAME);
roleForTest.setDescription("role test description");
this._roleManager.addRole(roleForTest);
User user = new User();
user.setUsername(TEST_USER_NAME);
user.setPassword(TEST_USER_PASSWORD);
this._userManager.addUser(user);
this._authorizationManager.addUserAuthorization(TEST_USER_NAME, Group.FREE_GROUP_NAME, TEST_ROLE_NAME);
this._authorizationManager.addUserAuthorization(TEST_USER_NAME, TEST_GROUP_NAME, "admin");
}
use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.
the class TestUserAuthorizationAction method removeTestUserAndAuthorities.
private void removeTestUserAndAuthorities() throws ApsSystemException {
this._userManager.removeUser(TEST_USER_NAME);
Group groupForTest = this._groupManager.getGroup(TEST_GROUP_NAME);
this._groupManager.removeGroup(groupForTest);
Role roleForTest = this._roleManager.getRole(TEST_ROLE_NAME);
this._roleManager.removeRole(roleForTest);
}
use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.
the class TestGroupAction method addGroup.
private void addGroup(String name, String descr) throws ApsSystemException {
Group group = new Group();
group.setName(name);
group.setDescr(descr);
this._groupManager.addGroup(group);
}
Aggregations