Skip to content

Commit

Permalink
Merge pull request DSpace#9837 from mwoodiupui/errorprone-upgrade
Browse files Browse the repository at this point in the history
Errorprone upgrade
  • Loading branch information
kshepherd authored Sep 26, 2024
2 parents 2e5823b + 082756f commit 9845d54
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ protected String getDNOfUser(String adminUser, String adminPassword, Context con
} else {
searchName = ldap_provider_url + ldap_search_context;
}
@SuppressWarnings("BanJNDI")
NamingEnumeration<SearchResult> answer = ctx.search(
searchName,
"(&({0}={1}))", new Object[] {ldap_id_field,
Expand Down Expand Up @@ -553,7 +554,7 @@ protected String getDNOfUser(String adminUser, String adminPassword, Context con
att = atts.get(attlist[4]);
if (att != null) {
// loop through all groups returned by LDAP
ldapGroup = new ArrayList<String>();
ldapGroup = new ArrayList<>();
for (NamingEnumeration val = att.getAll(); val.hasMoreElements(); ) {
ldapGroup.add((String) val.next());
}
Expand Down Expand Up @@ -633,7 +634,8 @@ protected boolean ldapAuthenticate(String netid, String password,
ctx.addToEnvironment(javax.naming.Context.AUTHORITATIVE, "true");
ctx.addToEnvironment(javax.naming.Context.REFERRAL, "follow");
// dummy operation to check if authentication has succeeded
ctx.getAttributes("");
@SuppressWarnings("BanJNDI")
Attributes trash = ctx.getAttributes("");
} else if (!useTLS) {
// Authenticate
env.put(javax.naming.Context.SECURITY_AUTHENTICATION, "Simple");
Expand Down
16 changes: 12 additions & 4 deletions dspace-api/src/main/java/org/dspace/curate/Curation.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private long runQueue(TaskQueue queue, Curator curator) throws SQLException, Aut
* End of curation script; logs script time if -v verbose is set
*
* @param timeRun Time script was started
* @throws SQLException If DSpace contextx can't complete
* @throws SQLException If DSpace context can't complete
*/
private void endScript(long timeRun) throws SQLException {
context.complete();
Expand Down Expand Up @@ -300,9 +300,17 @@ private void initGeneralLineOptionsAndCheckIfValid() {
// scope
if (this.commandLine.getOptionValue('s') != null) {
this.scope = this.commandLine.getOptionValue('s');
if (this.scope != null && Curator.TxScope.valueOf(this.scope.toUpperCase()) == null) {
this.handler.logError("Bad transaction scope '" + this.scope + "': only 'object', 'curation' or " +
"'open' recognized");
boolean knownScope;
try {
Curator.TxScope.valueOf(this.scope.toUpperCase());
knownScope = true;
} catch (IllegalArgumentException | NullPointerException e) {
knownScope = false;
}
if (!knownScope) {
this.handler.logError("Bad transaction scope '"
+ this.scope
+ "': only 'object', 'curation' or 'open' recognized");
throw new IllegalArgumentException(
"Bad transaction scope '" + this.scope + "': only 'object', 'curation' or " +
"'open' recognized");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void initialize(final ConfigurableApplicationContext applicationContext)
* Initially look for JNDI Resource called "java:/comp/env/dspace.dir".
* If not found, use value provided in "dspace.dir" in Spring Environment
*/
@SuppressWarnings("BanJNDI")
private String getDSpaceHome(ConfigurableEnvironment environment) {
// Load the "dspace.dir" property from Spring's configuration.
// This gives us the location of our DSpace configuration, which is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.fasterxml.jackson.databind.JsonNode;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.exception.RESTAuthorizationException;
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
Expand All @@ -26,7 +25,6 @@
import org.dspace.app.rest.model.RestAddressableModel;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.service.MetadataFieldService;
import org.dspace.core.Context;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -50,17 +48,12 @@ public abstract class DSpaceRestRepository<T extends RestAddressableModel, ID ex
extends AbstractDSpaceRestRepository
implements CrudRepository<T, ID>, PagingAndSortingRepository<T, ID>, BeanNameAware {

private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(DSpaceRestRepository.class);

private String thisRepositoryBeanName;
private DSpaceRestRepository<T, ID> thisRepository;

@Autowired
private ApplicationContext applicationContext;

@Autowired
private MetadataFieldService metadataFieldService;

/**
* From BeanNameAware. Allows us to capture the name of the bean, so we can load it into thisRepository.
* See getThisRepository() method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void initialize(final ConfigurableApplicationContext applicationContext)
* Initially look for JNDI Resource called "java:/comp/env/dspace.dir".
* If not found, use value provided in "dspace.dir" in Spring Environment
*/
@SuppressWarnings("BanJNDI")
private String getDSpaceHome(ConfigurableEnvironment environment) {
// Load the "dspace.dir" property from Spring Boot's Configuration (application.properties)
// This gives us the location of our DSpace configurations, necessary to start the kernel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public class AuthorizationFeatureRestRepositoryIT extends AbstractControllerInte
@Autowired
private AuthorizationFeatureService authzFeatureService;

@Test
/**
* All the features should be returned
* All the features should be returned.
*
* @throws Exception
*/
@Test
public void findAllTest() throws Exception {
int featuresNum = authzFeatureService.findAll().size();
int expReturn = featuresNum > 20 ? 20 : featuresNum;
Expand All @@ -62,20 +62,20 @@ public void findAllTest() throws Exception {

}

@Test
/**
* The feature endpoint must provide proper pagination. Unauthorized and
* forbidden scenarios are managed in the findAllTest
*
* @throws Exception
*/
@Test
public void findAllWithPaginationTest() throws Exception {
int featuresNum = authzFeatureService.findAll().size();

String adminToken = getAuthToken(admin.getEmail(), password);
List<String> featureIDs = new ArrayList<String>();
List<String> featureIDs = new ArrayList<>();
for (int page = 0; page < featuresNum; page++) {
AtomicReference<String> idRef = new AtomicReference<String>();
AtomicReference<String> idRef = new AtomicReference<>();

getClient(adminToken)
.perform(get("/api/authz/features").param("page", String.valueOf(page)).param("size", "1"))
Expand All @@ -101,12 +101,13 @@ public void findAllWithPaginationTest() throws Exception {
}
}

@Test
/**
* The feature resource endpoint must expose the proper structure and be reserved to administrators
* The feature resource endpoint must expose the proper structure and be
* reserved to administrators.
*
* @throws Exception
*/
@Test
public void findOneTest() throws Exception {
getClient().perform(get("/api/authz/features/withdrawItem")).andExpect(status().isOk())
.andExpect(jsonPath("$.id", is("withdrawItem")))
Expand All @@ -121,12 +122,12 @@ public void findOneNotFoundTest() throws Exception {

}

@Test
/**
* It should be possible to find features by resourcetype. The endpoint is only available to administrators
*
* @throws Exception
*/
@Test
public void findByResourceTypeTest() throws Exception {
AuthorizationFeature alwaysTrueFeature = authzFeatureService.find(AlwaysTrueFeature.NAME);
String adminToken = getAuthToken(admin.getEmail(), password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public class AuthorizationFeatureServiceIT extends AbstractControllerIntegration
@Autowired
private AuthorizationFeatureService authzFeatureService;

@Test
/**
* All the features available in the Sprint Context should be returned
* All the features available in the Sprint Context should be returned.
*
* @throws Exception
*/
@Test
public void findAllTest() throws Exception {
List<AuthorizationFeature> authzFeatureServiceFindAll = authzFeatureService.findAll();

Expand All @@ -70,12 +70,13 @@ public void findAllTest() throws Exception {
equalTo(featureNames.size()));
}

@Test
/**
* The find method should return existing feature and null in the case the feature doesn't exist
* The find method should return existing feature or {@code null} in the
* case the feature doesn't exist.
*
* @throws Exception
*/
@Test
public void findTest() throws Exception {
AuthorizationFeature aFeature = authzFeatureService.find(AlwaysTrueFeature.NAME);
assertThat("check that one of our mock feature is retrieved", aFeature.getName(),
Expand All @@ -85,12 +86,12 @@ public void findTest() throws Exception {
assertThat("check that not existing feature name return null", aNotExistingFeature, equalTo(null));
}

@Test
/**
* The findByResourceType must return only features that support the specified type
* The findByResourceType must return only features that support the specified type.
*
* @throws Exception
*/
@Test
public void findByResourceTypeTest() throws Exception {
// we have at least one feature that support the Site object
final String siteUniqueType = SiteRest.CATEGORY + "." + SiteRest.NAME;
Expand Down Expand Up @@ -119,12 +120,13 @@ public void findByResourceTypeTest() throws Exception {
assertThat(notExistingTypeFeatures.size(), equalTo(0));
}

@Test
/**
* The isAuthorized must return true for authorized feature and false for not authorized feature
* The isAuthorized must return {@code true} for authorized feature and
* {@code false} for not authorized feature.
*
* @throws Exception
*/
@Test
public void isAuthorizedTest() throws Exception {
Site site = siteService.findSite(context);
SiteRest siteRest = siteConverter.convert(site, DefaultProjection.DEFAULT);
Expand Down
Loading

0 comments on commit 9845d54

Please sign in to comment.