Difference Between URI, URL and URN

What is a URI?

URI (Uniform Resource Identifier) is a series of characters to identify a resource. It has the following format:

scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]

Here the “scheme” is mistaken for protocols. Schemes are not protocols. Many schemes have been designed to work with protocols, yes, bu it is not true for all schemes. Scheme part tells us how the read and interpret the rest of the identifier string.

file://usr/share/doc

The example above has the scheme “file”, and there is no “file” protocol as you know. File scheme is typically used to retrieve files from within one’s own computer.

Not all parts of the URI format defined above are mandatory. Below are the optional parts of a URI:

-User information
-Port
-Query
-Fragment

What is a URL?

Uniform Resource Locator is a special type of URI. Which means URLs are actually URIs. A URL points to a resource on the web. While doing that, a URL tells us where the resource is and which mechanism to use to access it (protocol).

What is a URN?

A URN (Uniform Resource Name) is a special type of URI just like a URL. URNs define a unique resource in the context of a namespace, they don’t tell anything about the location or the access mechanism for this resource.

Below are 2 sample URIs from Wikipedia:

 

bitnami-godaddy

How to Remove Bitnami Banner from Your Discourse Forum Site on GoDaddy

I recently created a cloud server instance on GoDaddy and installed a Bitnami application (Discourse) on it for one of my domains. Then I realized this Bitnami banner on the lower right corner. After some research and trials, I was able to remove this banner from my Discourse forum site. Here is how you can remove Bitnami banner from your website or web application on GoDaddy.

Click Manage next to Cloud Servers

Click Actions and Manage Server

Now click Console and click Connect

If you can’t see the console load, click Console and click Reconnect

Once connected go to /apps/your_app_name in this case /apps/discourse

Type “ls” and hit enter. You will see the bnconfig daemon listed

Now type the command below and hit enter. Bitnami banner will be gone from your website/ web application. In this case from your Discourse forum software.

Hope this helps.
Good Luck,
Serdar

how kerberos works

How Kerberos Works

Kerberos is a computer network authentication protocol that was developed by MIT. An open source, free implementation is available from MIT as well as commercial implementations from other vendors. Kerberos is the native authentication protocol in Active Directory.

Here is how the protocol works:

how kerberos works

In Kerberos, there is no communication between the resource (server) and the KDC. Client takes on the majority of the processing burden in Kerberos, which distributes the authentication workload across the network.

1- Client attempts to log on to the network

Client constructs and authenticator. This includes day and time data, so the authenticators are valid for only a certain period of time. So, they can’t be captured and re-used by an attacker. Some portion of the authenticator is un-encrypted (like who the client is) and some portion of it is encrypted using the client’s key. Kerberos does not transmit your password(key) across the network, password is used as shared secret.

2- KDC receives the authenticator from the client. It tries to decrypt the authenticator with the password it has (KDC has) for that user. If it can’t decrypt the authenticator this means this user (client) is not who they say they are. If it can be decrypted this means the user is who he claims to be and has the correct password.

3- KDC creates a TGT (Ticket Granting Ticket) for the client. This TGT includes the user information and is encrypted by KDC’s own key that only KDC knows about. This TGT is transmitted back to the client and saved on the client machine inside Kerberos Tray. This area is always in the memory and can’t be swapped out to the disk which means If the client computer crashes, this information will be lost. Now the client is logged on and ready to go.

4- Now client computer looks at the Kerberos Tray and sees there is no ticket for the server (resource). Now client sends the TGT back to the KDC and says “I need a ticket for the server”. KDC uses his key to decrypt the TGT. If it can be decrypted then KDC know that this information was generated by him previously. TGTs are generally valid for 8 hours so that KDC will get to re-validate the users but this doesn’t happen every time to save effort. Since KDC was able to decrypt the TGT, now it generates a ticket for the client. This ticket is generated by the server’s key (the resource that client is trying to access) and sent to the client. This ticket is also stored in Kerberos Tray.

5- Now, anytime the client needs to access the server, a copy of this ticket is sent to the server. Server tries to decrypt this ticket with his own key. If it can be decrypted then server knows that this information was generated by the KDC because it is the only other node that knows about server’s password which means this is a legitimate ticket. Once the server decrypts the user information (username, roles, groups etc.) he decides which content client can access. This tickets are not stored in server’s memory. Every time client needs access, he needs to re-send this ticket to the server. Considering how many users the server could be serving to, it makes sense not to store all this ticked data in server’s memory.

 

Hope this helps.
Good Luck,
Serdar

django-int object has no attribute keys

django – ‘int’ object has no attribute ‘keys’

Being new to Django, sometimes I face interesting problems. If it is very late and you are very tired, It may not always be easy to see the problem looking at the displayed error message like this int’ object has no attribute ‘keys’ error message I got in cursor.execute() method 🙂

This error was thrown on the line below:

cursor.execute(“select col1,col2 from table_name where col3 = %s”, integer_value)

The reason I got this error was that I had provided the integer directly as an argument but according to the documentation the second argument must be a sequence or mapping. Below solved the issue:

cursor.execute(“select col1,col2 from table_name where col3 = %s”, [integer_value])

Hope this helps.
Good Luck,
Serdar

Django NoReverseMatch Error

Django NoReverseMatch Error

Django’s reverse method can be found under django.core.urlresolvers (new versions: django.urls). To be able to use it you should import it like so:

reverse method is used to generate urls so that you can use them in your template files, model methods, view methods etc.

Why do we use them? We use them not to hard code our urls to adhere to DRY (Don’t Repeat Yourself) principle.

Why am I talking about reverse? Because reverse method is where I encountered this NoReverseMatch error. Error message was something like this:

Reverse for ‘xx’ with arguments ‘()’ and keyword arguments ‘{‘xx’: ‘xx’}’ not found. 1 pattern(s) tried: [‘(?P<xx>[-\\w]+)/(?P<xx>[-\\w]+)/$’]

I replaced the variable names with “xx” above.

Let’s see the bits of code that led to this error:

Above is a method that gets the url for a model that is created in the system. To display the model, I browse to this absolute url address. myapp is the namespace as you will see down below.

As you can see, I am using name spaced  urls. Anyways..

Above is the url patter from my application’s urls.py.

Above is the url from my main (project) urls file.

As you can see, ultimately the url I am trying to reach is formed by joining these 2 url definition. What you must pay attention for is that there are 2 variables in this structure that needs to be passed to reverse method. And as you can see there is only one variable being passed to the reverse method above, and that is where the problem is.

All I had to do was to see this mistake and provide both variables as kwargs to the reverse method and the problem was gone. Like so:

 

Hope this helps.
Good Luck,
Serdar

django related_name

What is “related_name” used for in Django

related_name is an attribute you use while defining relations like many-to-one, many-to-many, one-to-one etc.

The value of this attribute is used as the name of the reverse relation between models.

Example:

Here we define a many-to-one relation using a Foreign Key. A Site can have many Pages. The relation from a Site to its pages can be expressed as such:

A reverse relation can be defined from the Site to Pages as you see above. It is important to understand the importance of related_name attribute. related_name can save you from many headaches by preventing clashes from ever happening in your applications. Different models having a Foreign Key relation to the same “X” model could have clashes for using the same default related_name values.

Explicitly specifying related_name values for your relations will save you a lot of troubles later.

Hope this helps.
Good Luck,
Serdar

RedHat JBOSS BPM Suite Installation Error – No ‘jar’ binary detected in PATH

No ‘jar’ binary detected in PATH. I encountered this error message when I was trying to install RedHat JBoss BMP Suite for the first time.

no-jar-binary-detected-in-path

At first, I thought I needed to install JRE and include the bin folder in the path. Apparently, that was not the solution. What you need to do is install the JDK and include the bin folder of JDK in your “Path” system variable.

It would look like this:

Right Click “Computer” -> “Properties” -> “Advanced System Settings” -> “Environment Variables”. There you will find “Path” under System Variables.

computer-properties

computer-environment-variables

Append the above line into this variable. Now JBOSS BMP Suite Installation jar should work.

Hope this helps.
Good Luck,
Serdar

Python – Difference between “.append()” and “+= []”

In my new Django project, I was trying to append a list of tuples (which contained more than 1 tuple in it) into another list of tuples.

Then I got this error: ValueError: too many values to unpack (expected 2)

I was using .append() method to perform this operation and apparently that is exactly where the problem was.

Result: You cannot append a list of tuples with more than one item into another list of tuples using .append(). You need to use “+=” operator to do this.

Hope this helps.
Good Luck,
Serdar

django-no-such-table

Django Error – django.db.utils.OperationalError: no such table

Django “no such table” error of death..

I recently encountered this “no such table” error while trying to run makemigrations command on PyCharm.

I dropped database tables related to my app, cleaned django_migrations table for this app, cleared migrations folder as described in this post: http://big.info/2016/07/django-clear-migrations-re-migrate.html. Then I ran makemigrations… No such table..

I did lots of googling but none of the solutions I found was applicable to my case. After some inspection of the error messages generated, I found out that one of the forms in my forms.py was trying to access a database that I had deleted. I commented out this form’s code and re-run makemigrations command. This time it was successful.

Hope this helps.
Good Luck,
Serdar

difference-library-framework

Difference between a Framework and a Library

Recently, I heard 2 of my friends talking about the difference between a framework and a library, and I thought some may need a clear explanation to see the difference. Check out the simple diagram below.

difference-library-framework

Library

A library is essentially a set of functions that you can call, these days usually organised into classes. Each call does some work and returns control to the client. The defining characteristic of a library is that you are in control, you call the library.

Framework

A framework embodies some abstract design, with more behaviours built in. In order to use it you need to insert your behaviour into various places in the framework either by subclassing or by plugging in your own classes. The framework’s code then calls your code at these points. The defining characteristic of a framework is Inversion of Control. The framework calls you, not the other way round. (This is known as the Hollywood Principle: “Don’t call us, we’ll call you.”) The framework is in control. The flow of control and the flow of data is managed by the framework.

Hope this helps.
Good Luck,
Serdar