Package org.restlet.data

Examples of org.restlet.data.ChallengeResponse


         client = new Client(new Context(Logger.getLogger(EntryClient.class.getName())),location.getSchemeProtocol());
         client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
      }
      Request request = new Request(Method.HEAD,location);
      if (identity!=null) {
         request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,identity.getName(),identity.getPassword()));
      }
      if (cookie!=null) {
         request.getCookies().add(cookie);
      }
      Response response = client.handle(request);
View Full Code Here


         client = new Client(new Context(Logger.getLogger(EntryClient.class.getName())),entryLoc.getSchemeProtocol());
         client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
      }
      Request request = new Request(Method.DELETE,entryLoc);
      if (identity!=null) {
         request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,identity.getName(),identity.getPassword()));
      }
      if (cookie!=null) {
         request.getCookies().add(cookie);
      }
      Response response = client.handle(request);
View Full Code Here

         client = new Client(new Context(Logger.getLogger(EntryClient.class.getName())),Protocol.valueOf(entryURI.getScheme()));
         client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
      }
      Request request = new Request(Method.PUT,entryURI.toString());
      if (identity!=null) {
         request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,identity.getName(),identity.getPassword()));
      }
      if (cookie!=null) {
         request.getCookies().add(cookie);
      }
      request.setEntity(new OutputRepresentation(MediaType.APPLICATION_ATOM_XML) {
View Full Code Here

                     // update media
                     Reference mediaLocation = new Reference(baseURI.resolve(src).toString());
                     Client client = new Client(mediaLocation.getSchemeProtocol());
                     Request getRequest = new Request(Method.GET,mediaLocation);
                     if (source.getIdentity()!=null) {
                        getRequest.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,source.getUsername(),source.getPassword()));
                     }
                     Response getResponse = client.handle(getRequest);
                     if (getResponse.getStatus().isSuccess()) {
                        Reference targetLocation = new Reference(targetClient.getLocation().resolve(src).toString());
                        Client targetClient = new Client(targetLocation.getSchemeProtocol());
                        Request putRequest = new Request(Method.PUT,targetLocation);
                        if (target.getIdentity()!=null) {
                           putRequest.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,target.getUsername(),target.getPassword()));
                        }
                        Representation rep = getResponse.getEntity();
                        if (contentType!=null) {
                           rep.setMediaType(contentType);
                        }
                        putRequest.setEntity(rep);
                        Response putResponse = targetClient.handle(putRequest);
                        if (!putResponse.getStatus().isSuccess()) {
                           log.severe("Cannot put media update to "+targetLocation+", status="+putResponse.getStatus().getCode());
                        }
                     } else {
                        if (!getResponse.getStatus().isSuccess()) {
                           log.severe("Cannot get media from "+mediaLocation+", status="+getResponse.getStatus().getCode());
                        }
                     }
                  }
               } else if (exists.getCode()==Status.CLIENT_ERROR_NOT_FOUND.getCode()) {
                  if (src==null) {
                     // regular entry
                     try {
                        targetClient.createEntry(entryDoc);
                     } catch (StatusException ex) {
                        log.severe("Cannot create entry "+entryClient.getLocation()+", status="+ex.getStatus().getCode());
                        errorCount++;
                     } catch (Exception ex) {
                        log.log(Level.SEVERE,"Cannot create entry "+entryClient.getLocation()+", error: "+ex.getMessage(),ex);
                        errorCount++;
                     }
                  } else {
                     // media entry
                     Reference mediaLocation = new Reference(baseURI.resolve(src).toString());
                     Client client = new Client(mediaLocation.getSchemeProtocol());
                     Request request = new Request(Method.GET,mediaLocation);
                     if (source.getIdentity()!=null) {
                        request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,source.getUsername(),source.getPassword()));
                     }
                     Response response = client.handle(request);
                     if (response.getStatus().isSuccess()) {
                        try {
                           Representation rep = response.getEntity();
View Full Code Here

            context.getLogger().info("Authorization request for "+username+" returned: "+response.getStatus().getCode());
            actor.unauthorized();
         }
      } else {
         Request request = new Request(Method.GET,service);
         request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,username,password));
         Response response = client.handle(request);
         if (response.getStatus().isSuccess()) {
            XMLRepresentationParser parser = new XMLRepresentationParser();
            try {
               Document doc = parser.load(response.getEntity());
View Full Code Here

   }
  
   protected int beforeHandle(final Request request, final Response response) {
      Identity identity = (Identity)request.getAttributes().get(Identity.IDENTITY_ATTR);
      if (identity==null) {
         ChallengeResponse authResponse = request.getChallengeResponse();
         if (authResponse!=null) {
            Reference service = ActionResource.getReferenceAttribute(request,"auth-service",confService);
            if (service==null) {
               getLogger().warning("No authentication service has been configured.");
               return Filter.CONTINUE;
            }
            String username = authResponse.getIdentifier();
            String password = new String(authResponse.getSecret());
            LoginAction.LoginActor actor = new LoginAction.LoginActor() {
               public void authenticated(Form authForm,Identity identity) {
                  String name = getCookieName(request);
                  if (name!=null) {
                     CookieSetting cookie = new CookieSetting("I",identity.getSession());
View Full Code Here

                                 if (auth.getScheme().equals("cookie")) {
                                    Cookie cookie = new Cookie(auth.getName(),auth.getPassword());
                                    cookie.setPath("/");
                                    request.getCookies().add(cookie);
                                 } else {
                                    request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,auth.getName(),auth.getPassword()));
                                 }
                              }
                              Response response = client.handle(request);
                              if (!response.getStatus().isSuccess()) {
                                 log.log(Level.SEVERE,"Failed to retrieve media, status="+response.getStatus().getCode()+", src="+srcRef);
                                 errorCount++;
                                 return;
                              }
                              if (contentType!=null) {
                                 // The entry's media type wins.  Sometimes file resources do not
                                 // report the media type correctly
                                 response.getEntity().setMediaType(contentType);
                              }
                              try {
                                 entry = app.createMediaEntry(user,feed,response.getEntity(),src,entryId);
                                 app.updateEntry(user,feed,entry,entryDoc);
                              } catch (AppException ex) {
                                 log.severe("Failed to create media entry "+index.getId()+", src="+srcRef);
                                 if (ex.getStatus()==Status.SERVER_ERROR_INTERNAL) {
                                    log.log(Level.SEVERE,ex.getMessage(),ex);
                                 } else {
                                    log.severe("Status="+ex.getStatus().getCode()+", "+ex.getMessage());
                                 }
                                 errorCount++;
                              }
                           }
                        } else {
                           try {
                              app.updateEntry(user,feed,entryId,entryDoc);
                           } catch (AppException ex) {
                              if (ex.getStatus()==Status.SERVER_ERROR_INTERNAL) {
                                 log.log(Level.SEVERE,ex.getMessage(),ex);
                              } else {
                                 log.severe("Status="+ex.getStatus().getCode()+", "+ex.getMessage());
                              }
                              errorCount++;
                              return;
                           }
                           if (src!=null) {
                              URI srcRef = baseURI.resolve(src);

                              Client client = new Client(new Context(log),Protocol.valueOf(srcRef.getScheme()));
                              client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
                              /*
                             
                              Request headRequest = new Request(Method.HEAD,new Reference(srcRef.toString()));
                              if (auth!=null) {
                                 headRequest.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,auth.getName(),auth.getPassword()));
                              }
                              Response headResponse = client.handle(headRequest);
                              if (!headResponse.getStatus().isSuccess()) {
                                 log.log(Level.SEVERE,"Failed to retrieve media head, status="+headResponse.getStatus().getCode()+", src="+srcRef);
                                 errorCount++;
                                 return;
                              }
                              boolean outOfDate = true;
                              if (headResponse.isEntityAvailable()) {
                                 outOfDate = headResponse.getEntity().getModificationDate().after(resource.getEdited());
                                 if (outOfDate) {
                                    log.info("Out of date: "+headResponse.getEntity().getModificationDate()+" > "+resource.getEdited());
                                 }
                              }
                               */
                             
                              Request request = new Request(Method.GET,new Reference(srcRef.toString()));
                              if (auth!=null) {
                                 if (auth.getScheme().equals("cookie")) {
                                    Cookie cookie = new Cookie(auth.getName(),auth.getPassword());
                                    cookie.setPath("/");
                                    request.getCookies().add(cookie);
                                 } else {
                                    request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,auth.getName(),auth.getPassword()));
                                 }
                              }
                              Date edited = new Date(resource.getEdited().getTime());
                              request.getConditions().setUnmodifiedSince(edited);
                              log.info("Attempting update media from "+srcRef.toString()+", edited="+edited);
View Full Code Here

            Request appRequest = new Request(progress.update ? Method.PUT : Method.POST,appRef);
            appRequest.setRootRef(getRequest().getRootRef());
           
            if (appUsername!=null) {
               getLogger().info("Using username "+appUsername+" for authentication for APP target.");
               appRequest.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,appUsername,appPassword));
            } else if (getRequest().getChallengeResponse()!=null) {
                // pass along authentication
               getLogger().info("Passing along authentication to APP target.");
               appRequest.setChallengeResponse(getRequest().getChallengeResponse());
            }
View Full Code Here

   protected boolean feedExists(URI location)
   {
      Client client = new Client(new Context(log),Protocol.valueOf(location.getScheme()));
      client.getContext                                                                                                                                                             ().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
      Request request = new Request(Method.HEAD,location.toString());
      request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,username,password));
      Response response = client.handle(request);
      return response.getStatus().isSuccess();

   }
View Full Code Here

               Request remoteRequest = new Request(request.getMethod(),resource);
               if (request.isEntityAvailable()) {
                  remoteRequest.setEntity(request.getEntity());
               }
               if (base.getUsername()!=null) {
                  remoteRequest.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,base.getUsername(),base.getPassword()));
               }

               Response remoteResponse = client.handle(remoteRequest);

               response.setStatus(remoteResponse.getStatus());
               response.setEntity(remoteResponse.getEntity());
            } else {
               ScriptManager.ScriptContext releaseScript = null;
               try {
                  final ScriptManager.ScriptContext script = manager.findScript(request,path);
                  if (script==null) {
                     response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                     return;
                  }
                  releaseScript = script;

                  Response remoteResponse = null;
                  if (resourceName!=null) {
                     if (isFineLog) {
                        getLogger().fine("Using resource "+resourceName);
                     }
                     ResourceManager manager = (ResourceManager)getContext().getAttributes().get(ResourceManager.ATTR);
                     ResourceManager.Retriever retriever = manager.findResource(resourceName);
                     if (retriever!=null) {
                        remoteResponse = retriever.get();
                     } else {
                        getLogger().warning("No resource named "+resourceName);
                     }
                  } else {
                     Client client = getContext().getClientDispatcher();
                     //Client client = new Client(getContext().createChildContext(),resource.getSchemeProtocol());
                     client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
                     Request remoteRequest = new Request(Method.GET,new Reference(resource.toString()));
                     if (base.getUsername()!=null) {
                        remoteRequest.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,base.getUsername(),base.getPassword()));
                     }
                     Cookie cookie = request.getCookies().getFirst("I");
                     if (cookie!=null) {
                        remoteRequest.getCookies().add(cookie);
                     }
View Full Code Here

TOP

Related Classes of org.restlet.data.ChallengeResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.