Example #1
0
 // regression test for JERSEY-1114
 @Test
 public void testBuildFromMapNoSlashInUri() {
   UriBuilder builder = new UriBuilderImpl().uri(URI.create("http://localhost:8080")).path("test");
   assertEquals(
       "http://localhost:8080/test",
       builder.buildFromMap(new HashMap<String, Object>()).toString());
 }
 @SuppressWarnings("unchecked")
 @Override
 public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
   GeneratedHttpRequest<?> r = GeneratedHttpRequest.class.cast(request);
   String payload = r.getJavaMethod().getAnnotation(Payload.class).value();
   if (postParams.size() > 0) {
     UriBuilder builder = uriBuilders.get();
     builder.uri(URI.create("http://test/"));
     builder.path(payload);
     URI fake = builder.buildFromMap(postParams);
     payload = fake.getPath().substring(1);
   }
   return (R) request.toBuilder().payload(Payloads.newStringPayload(payload)).build();
 }
Example #3
0
 @Override
 public Response sendError(ClientSessionModel clientSession, Error error) {
   try {
     if ("true".equals(clientSession.getClient().getAttribute(SAML_IDP_INITIATED_LOGIN))) {
       if (error == Error.CANCELLED_BY_USER) {
         UriBuilder builder =
             RealmsResource.protocolUrl(uriInfo).path(SamlService.class, "idpInitiatedSSO");
         Map<String, String> params = new HashMap<>();
         params.put("realm", realm.getName());
         params.put("protocol", LOGIN_PROTOCOL);
         params.put(
             "client", clientSession.getClient().getAttribute(SAML_IDP_INITIATED_SSO_URL_NAME));
         URI redirect = builder.buildFromMap(params);
         return Response.status(302).location(redirect).build();
       } else {
         return ErrorPage.error(session, translateErrorToIdpInitiatedErrorMessage(error));
       }
     } else {
       SAML2ErrorResponseBuilder builder =
           new SAML2ErrorResponseBuilder()
               .destination(clientSession.getRedirectUri())
               .issuer(getResponseIssuer(realm))
               .status(translateErrorToSAMLStatus(error).get());
       try {
         JaxrsSAML2BindingBuilder binding =
             new JaxrsSAML2BindingBuilder()
                 .relayState(clientSession.getNote(GeneralConstants.RELAY_STATE));
         Document document = builder.buildDocument();
         return buildErrorResponse(clientSession, binding, document);
       } catch (Exception e) {
         return ErrorPage.error(session, Messages.FAILED_TO_PROCESS_RESPONSE);
       }
     }
   } finally {
     RestartLoginCookie.expireRestartCookie(realm, session.getContext().getConnection(), uriInfo);
     session.sessions().removeClientSession(realm, clientSession);
   }
 }