Showing posts with label authentication. Show all posts
Showing posts with label authentication. Show all posts

Tuesday, August 12, 2014

Download a password protected webpage with Objective C for iOS/iPhone/iPad

1) Go to http://allseeing-i.com/ASIHTTPRequest and download the latest version (the .tar tarball file)

2) In Xcode, in your project, click on the file folder icon, which is the top left button, so that you can see all the .h and .m files in your project.
3) Open the .tar file in Finder, and drag-and-drop the Classes/ASI* files to Xcode, on the left hand side, in the same directory that the rest of your .h and .m files are.  NOTE: Don't copy the files manually through the command line (Terminal) nor outside of Xcode.
4) If you are creating an iPhone app, drag-and-drop the External/Reachability/Reachability* files to Xcode, on the left hand side, in that same directory.
5) Go to http://allseeing-i.com/ASIHTTPRequest/Setup-instructions and follow the step 2 directions, which is setting up the Build Phases.
6) If you are using ARC, then you need to disable ARC for the ASI* and Reachability* files.  Click on your main project on the left hand side, then choose "Build Phases", and expand the "Compile Sources" section.  For all of the ASI* and Reachability.m files, add in the following flag for "Compiler Flags": -fno-objc-arc (Also see http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project)
7) At the top of your .m file where you want to download the webpage, paste the following line:
#import "ASIHTTPRequest.h"

8) In that same .m file, download the file by doing this:


    NSString* url = @"http://www.google.com";
    NSURL *nsurl = [NSURL URLWithString:url];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:nsurl];
    [request setUsername:@"enterUsernameHere"];
    [request setPassword:@"enterPasswordHere"];
    
    [request startSynchronous];
    NSError *error = [request error];
    if (!error) {
        NSString *response = [request responseString];
        NSLog(response);
    }

That's it!

Friday, November 8, 2013

How to require password authentication for Apache Solr 4 and Jetty

Some of the documentation in the Solr wiki is outdated, so here's what worked for me.  In the following files, you can change the highlighted fields.

Edit /opt/solr/etc/jetty.xml and add the following:

<Configure>

    <Call name="addBean">
      <Arg>
        <New class="org.eclipse.jetty.security.HashLoginService">
          <Set name="name">Test Realm</Set>
          <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
          <Set name="refreshInterval">0</Set>
        </New>
      </Arg>
    </Call>

...

</Configure>

Edit  /opt/solr/solr-webapp/webapp/WEB-INF/web.xml and add the following:

<web-app>
...
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Solr authenticated application</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>core1-role</role-name>
    </auth-constraint>
  </security-constraint>

  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Test Realm</realm-name>

  </login-config>

...
</web-app>

Create a file in /opt/solr/etc/realm.properties and put the following in it:

admin: yourPasswordHere,core1-role

You can change "admin" to whatever username you want.

For the password, you can either use the literal password, or use an OBF/MD5/CRYPT hash.  To create a hash, you can do the following:

cd /opt/solr
java -cp /lib/jetty-util-8.1.10.v20130312.jar org.eclipse.jetty.util.security.Password admin yourPasswordHere

The above utility will print out the hash to the screen, and you can chose either the OBF, MD5, or CRYPT line.  Make sure that you copy the entire line, including the "OBF:..." part.  Copy this line to the /opt/solr/etc/realm.properties file; the result will look something like this:

admin: OBF:1x1v1xmk1w9b1pyh1oq31uum1xtv1zej1zer1xtn1uvk1or71pw51w8f1xmq1x0r
,core1-role

The above is all in one line.  No line break.  Make sure you put the comma before the "core1-role".

After you've changed everything, restart the solr server.  If you're using Fedora, do this:

sudo /sbin/service jetty.sh restart

Then open up your web browser to http://localhost:8983/solr/#/collection1/query and the web browser should ask you for a password.  Enter admin for the user name and yourPasswordHere for the password.

Hint: if you get an error on the Solr admin webpage, you can check the log for warning messages.  The log file is here: /opt/solr/logs/solr.log

More info: