}
}
<<<<<<< HEAD
/*
* (non-Javadoc)
*
* @see org.picketlink.idm.spi.IdentityStore#executeQuery(org.picketlink.idm.query.UserQuery,
* org.picketlink.idm.query.Range)
*/
/*
* @Override public List executeQuery(IdentityStoreInvocationContext invocationContext, UserQuery query, Range range)
* { // TODO: Deal with range List users = new ArrayList(); Map filters =
* query.getAttributeFilters(); if (filters != null) { // we are dealing with attributes // Get all the managed attributes
* first to do the search Attributes matchAttrs = getManagedAttributes(filters); if (matchAttrs.size() == 0) { // go for
* custom attributes List allUsers = getAllUsers(); for (User theUser : allUsers) { if
* (userHasRequiredAttributes((LDAPUser) theUser, filters)) { users.add(theUser); } } return users; }
*
* // Perform the search try { NamingEnumeration answer = ctx.search(userDNSuffix, matchAttrs); while
* (answer.hasMore()) { SearchResult sr = answer.next(); Attributes attributes = sr.getAttributes();
*
* LDAPUser user = new LDAPUser(); user.setLookup(this); user.setUserDNSuffix(userDNSuffix);
* user.addAllLDAPAttributes(attributes);
*
* user.setLDAPChangeNotificationHandler(this);
*
* // Get the custom attributes String customDN = user.getCustomAttributes().getDN() + COMMA + user.getDN(); try {
* LDAPUserCustomAttributes lca = (LDAPUserCustomAttributes) ctx.lookup(customDN); if (lca != null) {
* user.setCustomAttributes(lca); } } catch (Exception ignore) { } if (userHasRequiredAttributes(user, filters)) {
* users.add(user); } } } catch (NamingException e) { throw new RuntimeException("Error executing user query.", e); } }
*
* return users; }
*/
/*
* (non-Javadoc)
*
* @see org.picketlink.idm.spi.IdentityStore#executeQuery(org.picketlink.idm.query.GroupQuery,
* org.picketlink.idm.query.Range)
*/
/*
* @Override public List executeQuery(IdentityStoreInvocationContext invocationContext, GroupQuery query, Range
* range) { List groups = new ArrayList();
*
* try { BasicAttributes groupAttributeFilter = new BasicAttributes(true);
*
* if (query.getId() != null) { groupAttributeFilter.put(CN, query.getId()); }
*
* if (query.getName() != null) { groupAttributeFilter.put(CN, query.getName()); }
*
* if (query.getRelatedUser() != null) { LDAPUser ldapUser = (LDAPUser) getUser(invocationContext,
* query.getRelatedUser().getId());
*
* groupAttributeFilter.put(MEMBER, ldapUser.getDN()); }
*
* if (query.getRole() != null) { LDAPRole ldapRole = (LDAPRole) getRole(invocationContext, query.getRole().getName());
*
* groupAttributeFilter.put(MEMBER, ldapRole.getDN()); }
*
* NamingEnumeration groupSearchResult = ctx.search(groupDNSuffix, groupAttributeFilter);
*
* // iterate over the returned roles while (groupSearchResult.hasMore()) { boolean isGroupSelected = true;
*
* SearchResult groupResult = groupSearchResult.next(); Attributes groupAttributes = groupResult.getAttributes();
*
* LDAPGroup childGroup = new LDAPGroup(groupAttributes, groupDNSuffix);
*
* if (query.getParentGroup() != null) { Group parentGroup = getParentGroup(invocationContext, childGroup);
*
* if (parentGroup == null || !query.getParentGroup().getId().equals(parentGroup.getId())) { isGroupSelected = false; }
*
* }
*
* if (isGroupSelected) { groups.add(childGroup); } } } catch (NamingException e) { throw new
* RuntimeException("Error executing group query.", e); }
*
* return groups; }
*/
/*
* (non-Javadoc)
*
* @see org.picketlink.idm.spi.IdentityStore#executeQuery(org.picketlink.idm.query.RoleQuery,
* org.picketlink.idm.query.Range)
*/
/*
* @Override public List executeQuery(IdentityStoreInvocationContext invocationContext, RoleQuery query, Range range)
* { List roles = new ArrayList();
*
* try { BasicAttributes roleAttributeFilter = new BasicAttributes(true);
*
* if (query.getName() != null) { roleAttributeFilter.put(CN, query.getName()); }
*
* NamingEnumeration roleSearchResult = ctx.search(roleDNSuffix, roleAttributeFilter);
*
* // iterate over the returned roles while (roleSearchResult.hasMore()) { boolean isRoleSelected = true;
*
* SearchResult roleResult = roleSearchResult.next(); Attributes roleAttributes = roleResult.getAttributes();
*
* LDAPRole ldapRole = new LDAPRole(roleAttributes, roleDNSuffix);
*
* // checks if the role has a member mapped to the owner if (query.getOwner() != null) { Attribute memberAttribute =
* roleAttributes.get(MEMBER);
*
* LDAPUser ldapUser = (LDAPUser) query.getOwner();
*
* if (!(memberAttribute != null && memberAttribute.contains(ldapUser.getDN()))) { isRoleSelected = false; } }
*
* // checks if the role is a member of the group if (query.getGroup() != null) { LDAPGroup ldapGroup = (LDAPGroup)
* getGroup(invocationContext, query.getGroup().getName());
*
* Attributes groupAttributes = ldapGroup.getLDAPAttributes(); Attribute memberAttribute = groupAttributes.get(MEMBER);
*
* // if the role is a group member then select it. Otherwise the role is not a member of the provided group. if
* (!(memberAttribute != null && memberAttribute.contains(ldapRole.getDN()))) { isRoleSelected = false; } }
*
* if (isRoleSelected) { roles.add(ldapRole); } } } catch (NamingException e) { throw new
* RuntimeException("Error executing role query.", e); }
*
* return roles; }
*/
// private Attributes getManagedAttributes(Map filters) {
// Attributes attr = new BasicAttributes(true);
// Set keys = filters.keySet();
// for (String key : keys) {
// if (isManaged(key)) {
// attr.put(key, filters.get(key));
// }
// }
// return attr;
//}
//
//private boolean userHasRequiredAttributes(LDAPUser user, Map filters) {
// Set keys = filters.keySet();
//
// for (String key : keys) {
// String[] values = filters.get(key);
// String[] attValues = user. getAttribute(key).getValue();
// if (IDMUtil.arraysEqual(values, attValues) == false) {
// return false;
// }
// }
// return true;
//}
//
//private List getAllUsers() {
// List users = new ArrayList();
// // Perform the search
// try {
// Attributes attr = new BasicAttributes(true);
// NamingEnumeration answer = ctx.search(userDNSuffix, attr);
//
// while (answer.hasMore()) {
// SearchResult sr = answer.next();
// Attributes attributes = sr.getAttributes();
// LDAPUser user = new LDAPUser(attributes);
//
// LDAPUserCustomAttributes customAttributes = getCustomAttributes(user);
// // user.setLookup(this);
//
// user.setCustomAttributes(customAttributes);
//
// // user.setLDAPChangeNotificationHandler(this);
//
// users.add(user);
// }
// } catch (NamingException e) {
// throw new RuntimeException(e);
// }
//
// return users;
//}
// TODO method no longer required?
/*
* @Override public String[] getAttributeValues(IdentityStoreInvocationContext invocationContext, IdentityType identity,
* String name) { if (identity instanceof User) { if (identity instanceof LDAPUser == false) { throw new
* RuntimeException("Wrong type:" + identity); } LDAPUser ldapUser = (LDAPUser) identity; return
* ldapUser.getAttributeValues(name); } else if (identity instanceof Group) { LDAPGroup ldapGroup = null; if (identity
* instanceof LDAPGroup) { ldapGroup = (LDAPGroup) identity; } else { ldapGroup = (LDAPGroup) getGroup(invocationContext,
* ((Group) identity).getName()); } return ldapGroup.getAttributeValues(name); } else if (identity instanceof Role) {
* LDAPRole ldapRole = null; if (identity instanceof LDAPGroup) { ldapRole = (LDAPRole) identity; } else { ldapRole =
* (LDAPRole) getRole(invocationContext, ((Role) identity).getName()); } return ldapRole.getAttributeValues(name); } else {
* throw new IllegalArgumentException("identity parameter must be an instance of User, Group or Role"); } }
*/
/*
* (non-Javadoc)
*
* @see org.picketlink.idm.spi.IdentityStore#getAttributes(org.picketlink.idm.model.User)
*/
// TODO method no longer required?
/*
* @Override public Map getAttributes(IdentityStoreInvocationContext invocationContext, IdentityType
* identity) { if (identity instanceof User) { if (identity instanceof LDAPUser == false) { throw new
* RuntimeException("Wrong type:" + identity); } LDAPUser ldapUser = (LDAPUser) identity; return ldapUser.getAttributes(); }
* else if (identity instanceof Group) { LDAPGroup ldapGroup = null; if (identity instanceof LDAPGroup) { ldapGroup =
* (LDAPGroup) identity; } else { ldapGroup = (LDAPGroup) getGroup(invocationContext, ((Group) identity).getName()); }
* return ldapGroup.getAttributes(); } else if (identity instanceof Role) { LDAPRole ldapRole = null; if (ldapRole
* instanceof LDAPRole) { ldapRole = (LDAPRole) identity; } else { ldapRole = (LDAPRole) getRole(invocationContext, ((Role)
* identity).getName()); } return ldapRole.getAttributes(); } else { throw new
* IllegalArgumentException("identity parameter must be an instance of User, Group or Role"); } }
*/
// @Override
// public void handle(LDAPObjectChangedNotification notification) {
// DirContext object = notification.getLDAPObject();
// if (object instanceof LDAPUser) {
// LDAPUser user = (LDAPUser) object;
// LDAPUserCustomAttributes ldapUserCustomAttributes = user.getCustomAttributes();
// try {
// String userDN = getUserDN(user);
// if (notification.getNtype() == NType.ADD_ATTRIBUTE) {
// Attribute attrib = notification.getAttribute();
// if (attrib == null)
// throw new RuntimeException("attrib is null");
// ModificationItem[] mods = new ModificationItem[] { new ModificationItem(DirContext.ADD_ATTRIBUTE, attrib) };
// ctx.modifyAttributes(userDN, mods);
// }
// if (notification.getNtype() == NType.REPLACE_ATTRIBUTE) {
// Attribute attrib = notification.getAttribute();
// if (attrib == null)
// throw new RuntimeException("attrib is null");
// ModificationItem[] mods = new ModificationItem[] { new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
// attrib) };
// ctx.modifyAttributes(userDN, mods);
// }
// if (notification.getNtype() == NType.REMOVE_ATTRIBUTE) {
// Attribute attrib = notification.getAttribute();
// if (attrib == null)
// throw new RuntimeException("attrib is null");
// ModificationItem[] mods = new ModificationItem[] { new ModificationItem(DirContext.REMOVE_ATTRIBUTE, attrib) };
// ctx.modifyAttributes(userDN, mods);
// }
// // ctx.rebind(userDN, object);
// ctx.rebind(getCustomAttributesDN(user), ldapUserCustomAttributes);
// } catch (NamingException e) {
// throw new RuntimeException(e);
// }
// }
// }
=======
@Override
public void setup(LDAPConfiguration config, IdentityStoreInvocationContext context) {
// TODO Auto-generated method stub
}
@Override
public LDAPConfiguration getConfig() {
// TODO Auto-generated method stub
return null;
}
@Override
public IdentityStoreInvocationContext getContext() {
// TODO Auto-generated method stub
return null;
}
>>>>>>> 1bc3279cfdc78783181d1d560b9b1a0389ac4ec9
} |