Algorithms to hash a list of values ​​and then check if the value is in that list

I am working on a set of services and a client JAR file that is intended to be the only means of invoking these services. The JAR client will be used by multiple applications (all internal). However, we would like some services to be allowed for some client applications and not others.

I'm playing around with different approaches to achieve this, but one approach is to give each application a "context" value to pass at runtime. This value will represent the list of services allowed for this client application, and the service can quickly figure out if it is on that list.

Each service will have its own id value, probably hard-coded in the Java class as a variable static final

. For each client application, I would compile a list of allowed services, perhaps using a Groovy script or a very simple web application. A bit of Reflection based code will collect all of these ID values ​​and generate a hash representing all of them.

I would pass the hash of this context to the owners of the client applications, along with the client JAR, and they will return it during the service call. The service will use the same (or related) hash algorithm to quickly check if its ID is contained in the hash. If so, the service continues. If not, that rules out. This approach obviously won't protect against intentional abuse, but these are all internal services and we only need to block the negligent abuse.

I'm not sure which hashing algorithm to use (or if "hashing" is even the right word for it). I could just collect all the allowed IDs as String

and later check if the given ID contains in that line. However, the meaning of "context" would then be huge and cumbersome. I'm sure there are standard mathematical approaches for hashing a list of values ​​and then checking if the given original value is in that list. There are probably some of them already neatly packaged and exposed in the Java world. Any suggestions are greatly appreciated!

+3


source to share


4 answers


I think you are looking at passing a compressed flat file / XML to a service. The service will read the contents of the file (after unpacking) in HashSet

and check if its identifier is present in HashSet

.



0


source


I recommend that you implement permission and only allow apps that have the required permission.

See Android resolution details for details.



http://developer.android.com/guide/topics/security/permissions.html

0


source


You can use a hash table. I think it is even in standard libraries .

0


source


What are the boundaries of these ids that you are going to get?

You should use a hash table, but if those ids are within relatively small limits (relative to your system memory), you can simply create the lightest hash table possible.

If these ids are between n and n + m, create an array of size m and set each element to FALSE. For each identifier you want to add, set the array [ID-n] parameter to TRUE. To check if an ID passed just check if (array [ID - n])

0


source







All Articles