Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement v2 TPS ActivityService without vlv #4770

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.dogtagpki.server.authentication.AuthToken;
import org.dogtagpki.server.ca.CAEngine;
import org.dogtagpki.server.ca.CAServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import org.apache.catalina.realm.GenericPrincipal;
import org.dogtagpki.server.ca.CAEngine;
import org.dogtagpki.server.ca.CAServlet;
import org.dogtagpki.util.cert.CertUtil;
import org.mozilla.jss.netscape.security.pkcs.ContentInfo;
import org.mozilla.jss.netscape.security.pkcs.PKCS7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import org.dogtagpki.common.CAInfo;
import org.dogtagpki.server.ca.CAEngine;
import org.dogtagpki.server.ca.CAServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
36 changes: 36 additions & 0 deletions base/ca/src/main/java/org/dogtagpki/server/ca/v2/CAServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright Red Hat, Inc.
//
// SPDX-License-Identifier: GPL-2.0-or-later
//
package org.dogtagpki.server.ca.v2;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dogtagpki.server.ca.CAEngine;
import org.dogtagpki.server.rest.PKIServlet;

/**
* @author Marco Fargetta {@literal <[email protected]>}
*/
public class CAServlet extends PKIServlet {
public static final long serialVersionUID = 1L;

@Override
public void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
}

@Override
public void post(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
}


public CAEngine getCAEngine() {
ServletContext servletContext = getServletContext();
return (CAEngine) servletContext.getAttribute("engine");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import javax.servlet.http.HttpSession;

import org.dogtagpki.server.ca.CAEngine;
import org.dogtagpki.server.ca.CAServlet;
import org.dogtagpki.server.ca.rest.ProfileService;
import org.mozilla.jss.netscape.security.x509.X500Name;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import javax.servlet.http.HttpSession;

import org.dogtagpki.server.ca.CAEngine;
import org.dogtagpki.server.ca.CAServlet;
import org.dogtagpki.util.cert.CertUtil;
import org.mozilla.jss.netscape.security.pkcs.ContentInfo;
import org.mozilla.jss.netscape.security.pkcs.PKCS7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.netscape.certsrv.base.DataCollection;
import com.netscape.certsrv.util.JSONSerializer;

/**
* @author Endi S. Dewata
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
public class ActivityCollection extends DataCollection<ActivityData> {
public class ActivityCollection extends DataCollection<ActivityData> implements JSONSerializer{

@Override
public Collection<ActivityData> getEntries() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

/**
* A class represents a virtual list of search results.
* @deprecated As of release 11.6.0, replaced by {@link DBPagedSearch}
*/
@Deprecated(since = "11.6.0", forRemoval = true)
public class DBVirtualList<E extends IDBObj> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package com.netscape.cmscore.dbs;

import com.netscape.certsrv.base.EBaseException;
import com.netscape.certsrv.dbs.DBException;
import com.netscape.certsrv.dbs.DBPagedSearch;
import com.netscape.certsrv.dbs.DBVirtualList;
import com.netscape.certsrv.dbs.DBException;
import com.netscape.certsrv.dbs.IDBObj;
import com.netscape.certsrv.dbs.ModificationSet;

Expand Down Expand Up @@ -251,6 +251,30 @@ public DBSearchResults pagedSearch(
int size,
int timeLimit
) throws EBaseException {
return pagedSearch(base, filter, null, start, size, timeLimit);
}

/**
* Retrieves a list of object that satifies the given
* filter.
*
* @param base starting point of the search
* @param filter search filter
* @param sortKey key used to sort the list
* @param start index of the first element
* @param size max number of element in the page
* @param timeLimit timeout limit
* @return search results
* @exception EBaseException failed to search
*/
public DBSearchResults pagedSearch(
String base,
String filter,
String [] sortKeys,
int start,
int size,
int timeLimit
) throws EBaseException {
return null;
}

Expand Down Expand Up @@ -390,6 +414,21 @@ public <T extends IDBObj> DBPagedSearch<T> createPagedSearch(Class<T> classResul
return null;
}

/**
* Retrieves a paged search of objects.
*
* @param classResults the class representing the entries in the paged list
* @param base starting point of the search
* @param filter search filter
* @param attrs selected attributes
* @param sortKeys keys used to sort the list
* @return search results in virtual list
* @exception EBaseException failed to search
*/
public <T extends IDBObj> DBPagedSearch<T> createPagedSearch(Class<T> classResults, String base, String filter, String[] attrs,
String[] sortKeys) throws EBaseException {
return null;
}
public void abandon(LDAPSearchResults results) throws EBaseException {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import com.netscape.certsrv.base.EBaseException;
import com.netscape.certsrv.dbs.DBAttrMapper;
import com.netscape.certsrv.dbs.IDBObj;
import com.netscape.certsrv.dbs.DBVirtualList;
import com.netscape.certsrv.dbs.IDBObj;
import com.netscape.certsrv.dbs.Modification;
import com.netscape.certsrv.dbs.ModificationSet;
import com.netscape.cmsutil.ldap.LDAPUtil;
Expand Down Expand Up @@ -157,6 +157,39 @@ public Collection<E> findRecords(String keyword, Map<String, String> attributes)
}
}

/**
* Search for LDAP records with the specified keyword and attributes.
* The keyword parameter will be used to search with wildcards on certain attributes.
* The attributes parameter will be used to find exact matches of the specified attributes.
*/
public Collection<E> findRecords(String keyword, Map<String, String> attributes, String[] sortKeys, int start, int pageSize) throws Exception {

logger.debug("LDAPDatabase: findRecords()");

try (DBSSession session = dbSubsystem.createSession()) {

logger.debug("LDAPDatabase: LDAP search on {}", baseDN);

String ldapFilter = createFilter(keyword, attributes);
logger.debug("LDAPDatabase: - filter {}", ldapFilter);

DBSearchResults results = session.pagedSearch(baseDN, ldapFilter, sortKeys, start, pageSize, -1);

Collection<E> list = new ArrayList<>();
while (results.hasMoreElements()) {
@SuppressWarnings("unchecked")
E result = (E)results.nextElement();
list.add(result);
}

return list;
}
}

/**
* @deprecated As of release 11.6.0, replaced by {@link #findPagedCertRecords(String, String[], String)}
*/
@Deprecated(since = "11.6.0", forRemoval = true)
public DBVirtualList<E> findRecords(String keyword, Map<String, String> attributes,
String[] sortKeys, int pageSize) throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.netscape.cmscore.dbs;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.netscape.certsrv.base.EBaseException;
Expand Down Expand Up @@ -50,7 +51,7 @@ public class LDAPPagedSearch<E extends IDBObj> extends DBPagedSearch<E> {
private String base = null;
private String filter = null;
private String[] attrs = null;
private String sortKey = null;
private String[] sortKeys = null;
private LDAPSearchResults res = null;

public LDAPPagedSearch(Class<E> contentClassType, DBRegistry registry, LDAPConnection conn, String base, String filter, String[] attrs,
Expand All @@ -60,7 +61,26 @@ public LDAPPagedSearch(Class<E> contentClassType, DBRegistry registry, LDAPConne
this.base = base;
this.filter = filter;
this.attrs = attrs;
this.sortKey = sortKey;
if (sortKey != null) {
this.sortKeys = new String[1];
this.sortKeys[0] = sortKey;
}
try {
this.conn = (LDAPConnection) conn.clone();
} catch (Exception e) {
throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
e.toString()), e);
}
}

public LDAPPagedSearch(Class<E> contentClassType, DBRegistry registry, LDAPConnection conn, String base, String filter, String[] attrs,
String[] sortKeys) throws EBaseException {
this.contentClassType = contentClassType;
this.registry = registry;
this.base = base;
this.filter = filter;
this.attrs = attrs;
this.sortKeys = sortKeys;
try {
this.conn = (LDAPConnection) conn.clone();
} catch (Exception e) {
Expand All @@ -81,15 +101,11 @@ public List<E> getPage(int size)
try {
LDAPSearchConstraints cons = new LDAPSearchConstraints();
LDAPPagedResultsControl pageCtrl = null;
LDAPSortControl sortCtrl = null;
LDAPSortControl sortCtrl = generateSortControl(sortKeys);
String[] ldapattrs = null;
if (attrs != null) {
ldapattrs = registry.getLDAPAttributes(attrs);
}
if(sortKey != null) {
LDAPSortKey sortOrder = new LDAPSortKey( sortKey );
sortCtrl = new LDAPSortControl(sortOrder,true);
}
String ldapfilter = registry.getFilter(filter);
logger.info("LDAPSession.continuousPagedSearch(): Searching {} for {}", base, ldapfilter);
byte[] cookie = null;
Expand Down Expand Up @@ -128,4 +144,24 @@ public List<E> getPage(int size)
throw LDAPExceptionConverter.toDBException(e);
}
}

private LDAPSortControl generateSortControl(String[] sortKeys) throws EBaseException {

if (sortKeys == null || sortKeys.length == 0)
return null;

LDAPSortKey[] mKeys = new LDAPSortKey[sortKeys.length];
String[] la = null;
synchronized (this) {
la = registry.getLDAPAttributes(sortKeys);
}
if (la == null) {
logger.debug("LDAPPagedSearch.generateSortControl: cannot convert search keys {}", Arrays.toString(sortKeys));
throw new EBaseException("sort keys cannot be null");
}
for (int i = 0; i < la.length; i++) {
mKeys[i] = new LDAPSortKey(la[i]);
}
return new LDAPSortControl(mKeys, true);
}
}
Loading
Loading