Skip to content

Commit 8eedba2

Browse files
authored
UFAL/Clarinuserregistration nullpoint exception (#941)
* check if current user is defined * removed empty line * throw RESTAuthorizationException
1 parent cb306c2 commit 8eedba2

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceUserAllowanceServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private void authorizeClruaAction(Context context, List<ClarinLicenseResourceUse
164164
}
165165

166166
UUID userRegistrationEpersonUUID = clrua.getUserRegistration().getPersonID();
167-
if (currentUser.getID().equals(userRegistrationEpersonUUID)) {
167+
if (Objects.nonNull(currentUser) && currentUser.getID().equals(userRegistrationEpersonUUID)) {
168168
return;
169169
}
170170

dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/CLRUAUUserRegistrationLinkRepository.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import javax.annotation.Nullable;
1313
import javax.servlet.http.HttpServletRequest;
1414

15+
import org.dspace.app.rest.exception.RESTAuthorizationException;
1516
import org.dspace.app.rest.model.ClarinLicenseResourceUserAllowanceRest;
1617
import org.dspace.app.rest.model.ClarinUserRegistrationRest;
1718
import org.dspace.app.rest.projection.Projection;
@@ -39,11 +40,16 @@ public class CLRUAUUserRegistrationLinkRepository extends AbstractDSpaceRestRepo
3940
public ClarinUserRegistrationRest getUserRegistration(@Nullable HttpServletRequest request,
4041
Integer clruaID,
4142
@Nullable Pageable optionalPageable,
42-
Projection projection) throws SQLException, AuthorizeException {
43+
Projection projection)
44+
throws SQLException, RESTAuthorizationException {
4345
Context context = obtainContext();
4446

45-
ClarinLicenseResourceUserAllowance clarinLicenseResourceUserAllowance =
46-
clarinLicenseResourceUserAllowanceService.find(context, clruaID);
47+
ClarinLicenseResourceUserAllowance clarinLicenseResourceUserAllowance;
48+
try {
49+
clarinLicenseResourceUserAllowance = clarinLicenseResourceUserAllowanceService.find(context, clruaID);
50+
} catch (AuthorizeException e) {
51+
throw new RESTAuthorizationException(e);
52+
}
4753
if (Objects.isNull(clarinLicenseResourceUserAllowance)) {
4854
throw new ResourceNotFoundException("The ClarinLicenseResourceUserAllowance for id: " + clruaID +
4955
" couldn't be found");

dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/CLRUAUserMetadataLinkRepository.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import javax.servlet.http.HttpServletRequest;
1515

1616
import org.apache.commons.collections4.CollectionUtils;
17+
import org.dspace.app.rest.exception.RESTAuthorizationException;
1718
import org.dspace.app.rest.model.ClarinLicenseResourceUserAllowanceRest;
1819
import org.dspace.app.rest.model.ClarinUserMetadataRest;
1920
import org.dspace.app.rest.projection.Projection;
@@ -42,11 +43,16 @@ public class CLRUAUserMetadataLinkRepository extends AbstractDSpaceRestRepositor
4243
public Page<ClarinUserMetadataRest> getUserMetadata(@Nullable HttpServletRequest request,
4344
Integer clruaID,
4445
@Nullable Pageable optionalPageable,
45-
Projection projection) throws SQLException, AuthorizeException {
46+
Projection projection)
47+
throws SQLException, RESTAuthorizationException {
4648
Context context = obtainContext();
47-
48-
ClarinLicenseResourceUserAllowance clarinLicenseResourceUserAllowance =
49-
clarinLicenseResourceUserAllowanceService.find(context, clruaID);
49+
ClarinLicenseResourceUserAllowance clarinLicenseResourceUserAllowance;
50+
try {
51+
clarinLicenseResourceUserAllowance =
52+
clarinLicenseResourceUserAllowanceService.find(context, clruaID);
53+
} catch (AuthorizeException e) {
54+
throw new RESTAuthorizationException(e);
55+
}
5056
if (Objects.isNull(clarinLicenseResourceUserAllowance)) {
5157
throw new ResourceNotFoundException("The ClarinLicenseResourceUserAllowance for if: " + clruaID +
5258
" couldn't be found");

0 commit comments

Comments
 (0)