Class SecurePingResource
- java.lang.Object
-
- info.ejava.examples.secureping.rs.SecurePingResource
-
@Path("ping") public class SecurePingResource extends Object
This JAX-RS resource class acts as a HTTP facade for calls to the EJB tier. Declarative encryption and authentication requirements are specified by the web.xml. This class primarily implements the structural URIs and proxies the user calls/responses to/from the EJBs. Note we could have made this a stateless session EJB and added @RolesAllowed to be enfored here. A pure JAX-RS resource class does not honor those declarative annotations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SecurePingResource.Pinger
-
Field Summary
Fields Modifier and Type Field Description private javax.ws.rs.core.SecurityContext
ctx
private static org.slf4j.Logger
logger
private SecurePing
secureService
private javax.ws.rs.core.UriInfo
uriInfo
-
Constructor Summary
Constructors Constructor Description SecurePingResource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SecurePingResource.Pinger
anonymous()
This method will return a sub-resource that is the same as the "secure" path except this path is configured to not require any identity or encryption.SecurePingResource.Pinger
authenticated()
This method returns a sub-resource and will require that sub-resource to be envoked with HTTPS and an authenticated user in either the "admin" or "user" role base on the web.xml.javax.ws.rs.core.Response
isCallerInRole(String role)
private javax.ws.rs.core.Response.ResponseBuilder
makeExceptionResponse(Exception ex)
This method is used to report an unexpected error condition in the endpoints.private PingResult
makeResourcePayload(String ejbResponse)
This helper method builds a DTO to be marshaled back to the caller.javax.ws.rs.core.Response
whoAmI()
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
secureService
private SecurePing secureService
-
ctx
@Context private javax.ws.rs.core.SecurityContext ctx
-
uriInfo
@Context private javax.ws.rs.core.UriInfo uriInfo
-
-
Method Detail
-
whoAmI
@Path("whoAmI") @GET @Produces("text/plain") public javax.ws.rs.core.Response whoAmI()
-
isCallerInRole
@Path("roles/{role}") @GET @Produces("text/plain") public javax.ws.rs.core.Response isCallerInRole(@PathParam("role") String role)
-
anonymous
@Path("unsecured") public SecurePingResource.Pinger anonymous()
This method will return a sub-resource that is the same as the "secure" path except this path is configured to not require any identity or encryption.- Returns:
-
authenticated
@Path("secured") public SecurePingResource.Pinger authenticated()
This method returns a sub-resource and will require that sub-resource to be envoked with HTTPS and an authenticated user in either the "admin" or "user" role base on the web.xml.- Returns:
-
makeExceptionResponse
private javax.ws.rs.core.Response.ResponseBuilder makeExceptionResponse(Exception ex)
This method is used to report an unexpected error condition in the endpoints.- Parameters:
ex
-- Returns:
- error message
-
makeResourcePayload
private PingResult makeResourcePayload(String ejbResponse)
This helper method builds a DTO to be marshaled back to the caller.- Parameters:
ejbResponse
-- Returns:
- dto filled in
-
-