use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class UserDAO method getAssignedUsers.
/**
* @param role
* @return
* @throws FinderException
*/
List<User> getAssignedUsers(AdminRole role) throws FinderException {
List<User> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(role.getContextId(), GlobalIds.USER_ROOT);
try {
String roleVal = encodeSafeText(role.getName(), GlobalIds.USERID_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(USERS_AUX_OBJECT_CLASS_NAME);
filterbuf.append(")(");
filterbuf.append(GlobalIds.USER_ADMINROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), defaultAtrs, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
userList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, role.getContextId()));
}
} catch (LdapException e) {
String warning = "getAssignedUsers admin role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_USER_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "getAssignedUsers admin role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_USER_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class UserDAO method getAuthorizedUsers.
/**
* @param role
* @param limit
* @return
* @throws FinderException
*/
List<String> getAuthorizedUsers(Role role, int limit) throws FinderException {
List<String> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(role.getContextId(), GlobalIds.USER_ROOT);
try {
String roleVal = encodeSafeText(role.getName(), GlobalIds.USERID_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(USERS_AUX_OBJECT_CLASS_NAME);
filterbuf.append(")(");
filterbuf.append(GlobalIds.USER_ROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), USERID, false, limit);
while (searchResults.next()) {
Entry entry = searchResults.getEntry();
userList.add(getAttribute(entry, SchemaConstants.UID_AT));
}
} catch (LdapException e) {
String warning = "getAuthorizedUsers role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "getAuthorizedUsers role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class UserDAO method getUserRoles.
List<UserRole> getUserRoles(Role role, RCType rcType, String paSetName) throws FinderException {
List<UserRole> userRoleList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(role.getContextId(), GlobalIds.USER_ROOT);
try {
String roleVal = encodeSafeText(role.getName(), GlobalIds.ROLE_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(USERS_AUX_OBJECT_CLASS_NAME);
filterbuf.append(")(");
filterbuf.append(GlobalIds.USER_ROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append(")");
filterbuf.append("(");
filterbuf.append(GlobalIds.USER_ROLE_DATA);
filterbuf.append("=");
filterbuf.append(this.getFilterForRoleConstraint(role.getName(), rcType, paSetName));
filterbuf.append(")");
filterbuf.append(")");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), defaultAtrs, false, GlobalIds.BATCH_SIZE);
while (searchResults.next()) {
userRoleList.addAll(this.unloadUserRoles(searchResults.getEntry(), getAttribute(searchResults.getEntry(), SchemaConstants.UID_AT), role.getContextId(), role.getName()));
}
} catch (LdapException e) {
String warning = "getAssignedUsers role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "getAssignedUsers role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userRoleList;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class UserDAO method checkPassword.
/**
* @param user
* @return
* @throws org.apache.directory.fortress.core.FinderException, org.apache.directory.fortress.core.PasswordException
*/
Session checkPassword(User user) throws FinderException, PasswordException {
Session session = null;
LdapConnection ld = null;
String userDn = getDn(user.getUserId(), user.getContextId());
try {
session = new ObjectFactory().createSession();
session.setAuthenticated(false);
session.setUserId(user.getUserId());
ld = getUserConnection();
BindResponse bindResponse = bind(ld, userDn, user.getPassword());
String info;
if (bindResponse.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS) {
info = "PASSWORD INVALID for userId [" + user.getUserId() + "], resultCode [" + bindResponse.getLdapResult().getResultCode() + "]";
session.setMsg(info);
session.setErrorId(GlobalErrIds.USER_PW_INVLD);
}
PasswordPolicy respCtrl = getPwdRespCtrl(bindResponse);
if (respCtrl != null) {
// check IETF password policies here
checkPwPolicies(session, respCtrl);
}
if (session.getErrorId() == 0) {
session.setAuthenticated(true);
} else {
// pw invalid or pw policy violation:
throw new PasswordException(session.getErrorId(), session.getMsg());
}
} catch (LdapAuthenticationException e) {
String info = "checkPassword INVALID PASSWORD for userId [" + user.getUserId() + "] exception [" + e + "]";
throw new PasswordException(GlobalErrIds.USER_PW_INVLD, info);
} catch (LdapException e) {
String error = "checkPassword userId [" + user.getUserId() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_READ_FAILED, error, e);
} finally {
closeUserConnection(ld);
}
return session;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class PermDAO method findPermissions.
/**
* @param user
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<Permission> findPermissions(User user) throws FinderException {
List<Permission> permList = new ArrayList<>();
LdapConnection ld = null;
String permRoot = getRootDn(user.getContextId(), GlobalIds.PERM_ROOT);
try {
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(PERM_OP_OBJECT_CLASS_NAME);
filterbuf.append(")(|");
Set<String> roles = RoleUtil.getInstance().getInheritedRoles(user.getRoles(), user.getContextId());
if (CollectionUtils.isNotEmpty(roles)) {
for (String uRole : roles) {
filterbuf.append("(");
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(encodeSafeText(uRole, GlobalIds.ROLE_LEN));
filterbuf.append(")");
}
}
filterbuf.append("(");
filterbuf.append(USERS);
filterbuf.append("=");
filterbuf.append(user.getUserId());
filterbuf.append(")))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, permRoot, SearchScope.SUBTREE, filterbuf.toString(), PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
permList.add(unloadPopLdapEntry(searchResults.getEntry(), sequence++, false));
}
} catch (LdapException e) {
String error = "findPermissions user [" + user.getUserId() + "] caught LdapException in PermDAO.findPermissions=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_USER_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findPermissions user [" + user.getUserId() + "] caught CursorException in PermDAO.findPermissions=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_USER_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return permList;
}
Aggregations