public JetspeedPrincipalQueryContext(String nameFilter, long offset, long length, String order, List<String> roles, List<String> groups, List<String> users, Map<String, String> attributes) { put(NAME_FILTER, nameFilter); put(OFFSET, Long.valueOf(offset)); put(LENGTH, Long.valueOf(length)); put(ORDER, order); put(ASSOCIATED_ROLES, roles); put(ASSOCIATED_GROUPS, groups); put(ASSOCIATED_USERS, users); put(SECURITY_ATTRIBUTES, attributes); }
/** * Return the filter for the principals name. The name can contain a * wildcard at the right end. * * @return the nameFilter */ public String getNameFilter() { return (String) this.get(NAME_FILTER); }
/** * Add limit operator if we are on MySql. This is much faster than * paging via JDBC and also is a work around because the MySQL driver * retrieves the complete result set. This would result in a very high * memory consumption with large result sets. * * See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference- * implementation-notes.html -> Resultset * * @see org.apache.jetspeed.security.spi.impl.JetspeedPrincipalLookupManagerAbstract#getPagingSql(java.lang.String, org.apache.jetspeed.security.JetspeedPrincipalQueryContext) */ @Override protected String getPagingSql(String sql, JetspeedPrincipalQueryContext queryContext) { return sql + " LIMIT " + queryContext.getOffset() + "," + queryContext.getLength(); }
String attributeConstraint = null; String fromPart = "SECURITY_PRINCIPAL"; if (queryContext.getSecurityAttributes() != null) { int cnt = 1; for (Map.Entry<String, String> attribute : queryContext.getSecurityAttributes().entrySet()) { if (attributeConstraint == null) { attributeConstraint = "a" + cnt + ".PRINCIPAL_ID=SECURITY_PRINCIPAL.PRINCIPAL_ID AND a" + cnt if (queryContext.getNameFilter() != null && queryContext.getNameFilter().length() > 0) { constraint = "SECURITY_PRINCIPAL.PRINCIPAL_NAME LIKE '" + queryContext.getNameFilter().replace('*', '%') + "'"; if (queryContext.getAssociatedRoles() != null && queryContext.getAssociatedRoles().size() > 0 && queryContext.getAssociatedRoles().get(0).length() > 0) { int cnt = 1; for (String roleName : queryContext.getAssociatedRoles()) { if (roleConstraints == null) { roleConstraints = "r" + cnt + ".ASSOC_NAME='" + JetspeedPrincipalAssociationType.IS_MEMBER_OF if (queryContext.getAssociatedGroups() != null && queryContext.getAssociatedGroups().size() > 0 && queryContext.getAssociatedGroups().get(0).length() > 0) { int cnt = 1; for (String groupName : queryContext.getAssociatedGroups()) { if (groupConstraints == null) { groupConstraints = "r" + cnt + ".ASSOC_NAME='" + JetspeedPrincipalAssociationType.IS_MEMBER_OF if (queryContext.getAssociatedUsers() != null && queryContext.getAssociatedUsers().size() > 0) { int cnt = 1; for (String userName : queryContext.getAssociatedGroups()) {
JetspeedPrincipalQueryContext ctx = new JetspeedPrincipalQueryContext(userName, startIndex, results, sortDirection, roles, groups, null, attributeMap);
if (queryContext.getSecurityAttributes() != null) { for (Map.Entry<String, String> attribute : queryContext.getSecurityAttributes().entrySet()) { if (attributeConstraint == null) { _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, attribute.getKey()); if (queryContext.getNameFilter() != null && queryContext.getNameFilter().length() > 0) { _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, convertWildcardsForLike(queryContext.getNameFilter())); constraint = "SECURITY_PRINCIPAL.PRINCIPAL_NAME LIKE " + _paramPlaceHolderName; if (queryContext.getAssociatedRoles() != null && queryContext.getAssociatedRoles().size() > 0 && queryContext.getAssociatedRoles().get(0).length() > 0) { for (String roleName : queryContext.getAssociatedRoles()) { _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, convertWildcardsForLike(roleName)); if (queryContext.getAssociatedGroups() != null && queryContext.getAssociatedGroups().size() > 0 && queryContext.getAssociatedGroups().get(0).length() > 0) { for (String groupName : queryContext.getAssociatedGroups()) { _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, convertWildcardsForLike(groupName)); if (queryContext.getAssociatedUsers() != null && queryContext.getAssociatedUsers().size() > 0) { for (String userName : queryContext.getAssociatedGroups()) { _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, convertWildcardsForLike(userName)); + " WHERE SECURITY_PRINCIPAL.PRINCIPAL_TYPE='" + queryContext.getJetspeedPrincipalType()
/** * @return the length */ public Long getLength() { return (Long) this.get(LENGTH); }
public JetspeedPrincipalResultList getPrincipals(JetspeedPrincipalQueryContext queryContext, JetspeedPrincipalType type, Long securityDomain) { // paged principal queries not cached: used only for UI purposes where // results should reflect exact set of principals in database JetspeedPrincipalLookupManager jppm = jpplf.getJetspeedPrincipalLookupManager(); queryContext.put(JetspeedPrincipalQueryContext.JETSPEED_PRINCIPAL_TYPE, type.getName()); queryContext.put(JetspeedPrincipalQueryContext.SECURITY_DOMAIN, securityDomain); return jppm.getPrincipals(queryContext); }
/** * Returns all users the principal must contain. * * @return the associatedUsers */ @SuppressWarnings("unchecked") public List<String> getAssociatedUsers() { return (List<String>) this.get(ASSOCIATED_USERS); }
/** * @return the offset */ public Long getOffset() { return (Long) this.get(OFFSET); }
/** * Returns all roles the principal must be member of. * * @return the associatedRoles */ @SuppressWarnings("unchecked") public List<String> getAssociatedRoles() { return (List<String>) this.get(ASSOCIATED_ROLES); }
/** * Returns all groups the principal must be member of. * * @return the associatedGroups */ @SuppressWarnings("unchecked") public List<String> getAssociatedGroups() { return (List<String>) this.get(ASSOCIATED_GROUPS); }
/** * Returns the sort order for the principals name. If it is 'desc' the * principals are sorted backwards according to their names, all other * values result in normal order. * * @return the orderDesc */ public String getOrder() { return (String) this.get(ORDER); }
/** * @return the JetspeedPrincipalType name */ public String getJetspeedPrincipalType() { return (String) this.get(JETSPEED_PRINCIPAL_TYPE); }
/** * Returns all security attributes for the principal. All security * attributes MUST exist for the principal. * * @return the securityAttributes */ @SuppressWarnings("unchecked") public Map<String, String> getSecurityAttributes() { return (Map<String, String>) this.get(SECURITY_ATTRIBUTES); }
/** * @return the security domain id */ public Long getSecurityDomain() { return (Long) this.get(SECURITY_DOMAIN); }