diff options
Diffstat (limited to 'base/common/src/com/netscape/certsrv')
10 files changed, 185 insertions, 27 deletions
diff --git a/base/common/src/com/netscape/certsrv/acls/ACLInterceptor.java b/base/common/src/com/netscape/certsrv/acls/ACLInterceptor.java index bcb0b80a2..c30740260 100644 --- a/base/common/src/com/netscape/certsrv/acls/ACLInterceptor.java +++ b/base/common/src/com/netscape/certsrv/acls/ACLInterceptor.java @@ -24,9 +24,7 @@ import java.security.Principal; import java.util.Properties; import javax.servlet.ServletContext; -import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; import javax.ws.rs.ext.Provider; @@ -44,6 +42,7 @@ import com.netscape.certsrv.authorization.AuthzToken; import com.netscape.certsrv.authorization.EAuthzAccessDenied; import com.netscape.certsrv.authorization.IAuthzSubsystem; import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.ForbiddenException; import com.netscape.cmscore.realm.PKIPrincipal; @@ -76,7 +75,7 @@ public class ACLInterceptor implements PreProcessInterceptor { public ServerResponse preProcess( HttpRequest request, ResourceMethod resourceMethod - ) throws Failure, WebApplicationException { + ) throws Failure, ForbiddenException { // Get ACL mapping for the method. Method method = resourceMethod.getMethod(); @@ -95,12 +94,12 @@ public class ACLInterceptor implements PreProcessInterceptor { // If unauthenticated, reject request. if (principal == null) { - throw new WebApplicationException(Response.Status.FORBIDDEN); + throw new ForbiddenException("No user principal provided."); } // If unrecognized principal, reject request. if (!(principal instanceof PKIPrincipal)) { - throw new WebApplicationException(Response.Status.FORBIDDEN); + throw new ForbiddenException("Invalid user principal"); } PKIPrincipal pkiPrincipal = (PKIPrincipal)principal; @@ -108,7 +107,7 @@ public class ACLInterceptor implements PreProcessInterceptor { // If missing auth token, reject request. if (authToken == null) { - throw new WebApplicationException(Response.Status.FORBIDDEN); + throw new ForbiddenException("No authorization token present."); } try { @@ -124,7 +123,7 @@ public class ACLInterceptor implements PreProcessInterceptor { // If invalid mapping, reject request. if (values.length != 2) { - throw new WebApplicationException(Response.Status.FORBIDDEN); + throw new ForbiddenException("Invalid ACL mapping."); } // Check authorization. @@ -137,11 +136,11 @@ public class ACLInterceptor implements PreProcessInterceptor { // If not authorized, reject request. if (authzToken == null) { - throw new WebApplicationException(Response.Status.FORBIDDEN); + throw new ForbiddenException("No authorization token present."); } } catch (EAuthzAccessDenied e) { - throw new WebApplicationException(Response.Status.FORBIDDEN); + throw new ForbiddenException(e.toString()); } catch (IOException|EBaseException e) { e.printStackTrace(); diff --git a/base/common/src/com/netscape/certsrv/base/ConflictingOperationException.java b/base/common/src/com/netscape/certsrv/base/ConflictingOperationException.java new file mode 100644 index 000000000..8b17caa04 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ConflictingOperationException.java @@ -0,0 +1,20 @@ +package com.netscape.certsrv.base; + +import javax.ws.rs.core.Response; + +public class ConflictingOperationException extends PKIException { + + private static final long serialVersionUID = -5780172673428115193L; + + public ConflictingOperationException(String message) { + super(Response.Status.CONFLICT, message); + } + + public ConflictingOperationException(String message, Throwable cause) { + super(Response.Status.CONFLICT, message, cause); + } + + public ConflictingOperationException(Data data) { + super(data); + } +} diff --git a/base/common/src/com/netscape/certsrv/base/ForbiddenException.java b/base/common/src/com/netscape/certsrv/base/ForbiddenException.java new file mode 100644 index 000000000..218dc9c38 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ForbiddenException.java @@ -0,0 +1,19 @@ +package com.netscape.certsrv.base; + +import javax.ws.rs.core.Response; + +public class ForbiddenException extends PKIException { + private static final long serialVersionUID = 3199015969025638546L; + + public ForbiddenException(String message) { + super(Response.Status.FORBIDDEN, message); + } + + public ForbiddenException(String message, Throwable cause) { + super(Response.Status.FORBIDDEN, message, cause); + } + + public ForbiddenException(Data data) { + super(data); + } +} diff --git a/base/common/src/com/netscape/certsrv/base/HTTPGoneException.java b/base/common/src/com/netscape/certsrv/base/HTTPGoneException.java new file mode 100644 index 000000000..7b8f0d371 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/HTTPGoneException.java @@ -0,0 +1,20 @@ +package com.netscape.certsrv.base; + +import javax.ws.rs.core.Response; + +public class HTTPGoneException extends PKIException { + + private static final long serialVersionUID = 1256191208802745690L; + + public HTTPGoneException(String message) { + super(Response.Status.GONE, message); + } + + public HTTPGoneException(String message, Throwable cause) { + super(Response.Status.GONE, message, cause); + } + + public HTTPGoneException(Data data) { + super(data); + } +} diff --git a/base/common/src/com/netscape/certsrv/base/ResourceNotFoundException.java b/base/common/src/com/netscape/certsrv/base/ResourceNotFoundException.java new file mode 100644 index 000000000..f41e9e654 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ResourceNotFoundException.java @@ -0,0 +1,24 @@ +package com.netscape.certsrv.base; + +import javax.ws.rs.core.Response; + +public class ResourceNotFoundException extends PKIException { + + private static final long serialVersionUID = 2283994502912462263L; + + public ResourceNotFoundException(String message) { + super(Response.Status.NOT_FOUND, message); + } + + public ResourceNotFoundException(String message, Throwable cause) { + super(Response.Status.NOT_FOUND, message, cause); + } + + public ResourceNotFoundException(Data data) { + super(data); + } + + public Data getData() { + return super.getData(); + } +} diff --git a/base/common/src/com/netscape/certsrv/base/UserNotFoundException.java b/base/common/src/com/netscape/certsrv/base/UserNotFoundException.java new file mode 100644 index 000000000..63df7067a --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/UserNotFoundException.java @@ -0,0 +1,40 @@ +package com.netscape.certsrv.base; + + +public class UserNotFoundException extends ResourceNotFoundException { + private static final long serialVersionUID = -3446066672148673666L; + public String userId; + + public UserNotFoundException(String userId) { + this(userId, "User " + userId + " not found"); + } + + public UserNotFoundException(String userId, String message) { + super(message); + this.userId = userId; + } + + public UserNotFoundException(String userId, String message, Throwable cause) { + super(message, cause); + this.userId = userId; + } + + public UserNotFoundException(Data data) { + super(data); + userId = data.getAttribute("userId"); + } + + public Data getData() { + Data data = super.getData(); + data.setAttribute("userId", userId); + return data; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } +} diff --git a/base/common/src/com/netscape/certsrv/cert/CertNotFoundException.java b/base/common/src/com/netscape/certsrv/cert/CertNotFoundException.java index ce0962a84..171c2763d 100644 --- a/base/common/src/com/netscape/certsrv/cert/CertNotFoundException.java +++ b/base/common/src/com/netscape/certsrv/cert/CertNotFoundException.java @@ -17,12 +17,10 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.certsrv.cert; -import javax.ws.rs.core.Response; - -import com.netscape.certsrv.base.PKIException; +import com.netscape.certsrv.base.ResourceNotFoundException; import com.netscape.certsrv.dbs.certdb.CertId; -public class CertNotFoundException extends PKIException { +public class CertNotFoundException extends ResourceNotFoundException { private static final long serialVersionUID = -4784839378360933483L; @@ -33,12 +31,12 @@ public class CertNotFoundException extends PKIException { } public CertNotFoundException(CertId certId, String message) { - super(Response.Status.NOT_FOUND, message); + super(message); this.certId = certId; } public CertNotFoundException(CertId certId, String message, Throwable cause) { - super(Response.Status.NOT_FOUND, message, cause); + super(message, cause); this.certId = certId; } diff --git a/base/common/src/com/netscape/certsrv/group/GroupNotFoundException.java b/base/common/src/com/netscape/certsrv/group/GroupNotFoundException.java new file mode 100644 index 000000000..3bd9241b6 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/group/GroupNotFoundException.java @@ -0,0 +1,42 @@ +package com.netscape.certsrv.group; + +import com.netscape.certsrv.base.ResourceNotFoundException; + +public class GroupNotFoundException extends ResourceNotFoundException { + + private static final long serialVersionUID = 2283994502912462263L; + public String groupId; + + public GroupNotFoundException(String groupId) { + this(groupId, "Group " + groupId + " not found"); + } + + public GroupNotFoundException(String groupId, String message) { + super(message); + this.groupId = groupId; + } + + public GroupNotFoundException(String groupId, String message, Throwable cause) { + super(message, cause); + this.groupId = groupId; + } + + public GroupNotFoundException(Data data) { + super(data); + groupId = data.getAttribute("groupId"); + } + + public Data getData() { + Data data = super.getData(); + data.setAttribute("groupId", groupId); + return data; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } +} diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileNotFoundException.java b/base/common/src/com/netscape/certsrv/profile/ProfileNotFoundException.java index 7a1c9ea62..c6a549b07 100644 --- a/base/common/src/com/netscape/certsrv/profile/ProfileNotFoundException.java +++ b/base/common/src/com/netscape/certsrv/profile/ProfileNotFoundException.java @@ -17,11 +17,9 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.certsrv.profile; -import javax.ws.rs.core.Response; +import com.netscape.certsrv.base.ResourceNotFoundException; -import com.netscape.certsrv.base.PKIException; - -public class ProfileNotFoundException extends PKIException { +public class ProfileNotFoundException extends ResourceNotFoundException { private static final long serialVersionUID = -4784839378360933483L; @@ -32,12 +30,12 @@ public class ProfileNotFoundException extends PKIException { } public ProfileNotFoundException(String profileId, String message) { - super(Response.Status.NOT_FOUND, message); + super(message); this.profileId = profileId; } public ProfileNotFoundException(String profileId, String message, Throwable cause) { - super(Response.Status.NOT_FOUND, message, cause); + super(message, cause); this.profileId = profileId; } diff --git a/base/common/src/com/netscape/certsrv/request/RequestNotFoundException.java b/base/common/src/com/netscape/certsrv/request/RequestNotFoundException.java index 3db10dd3a..478675ab0 100644 --- a/base/common/src/com/netscape/certsrv/request/RequestNotFoundException.java +++ b/base/common/src/com/netscape/certsrv/request/RequestNotFoundException.java @@ -1,10 +1,8 @@ package com.netscape.certsrv.request; -import javax.ws.rs.core.Response; +import com.netscape.certsrv.base.ResourceNotFoundException; -import com.netscape.certsrv.base.PKIException; - -public class RequestNotFoundException extends PKIException { +public class RequestNotFoundException extends ResourceNotFoundException { private static final long serialVersionUID = -4784839378360933483L; @@ -15,12 +13,12 @@ public class RequestNotFoundException extends PKIException { } public RequestNotFoundException(RequestId requestId, String message) { - super(Response.Status.NOT_FOUND, message); + super(message); this.requestId = requestId; } public RequestNotFoundException(RequestId requestId, String message, Throwable cause) { - super(Response.Status.NOT_FOUND, message, cause); + super(message, cause); this.requestId = requestId; } |