All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.binggl.ninja.mongodb.MongoAuthMechanism Maven / Gradle / Ivy

Go to download

This is an easly plugable module for the Ninja web framework to work with MongoDB and optional moprhia (a MongoDB ORM) by providing convinent services, all required dependencies and some testing utilities. The original author is Sven Kubiak (https://github.com/svenkubiak). This is a recreation of the module because the orginal module/github repository was deleted.

There is a newer version: 1.0.7
Show newest version
package net.binggl.ninja.mongodb;

import org.apache.commons.lang.StringUtils;

/**
 * define the possible mongoDB authentication mechanisms
 * @author henrik
 */
public enum MongoAuthMechanism {
	SCRAM_SHA_1("SCRAM-SHA-1"), MONGODB_CR("MONGODB-CR"), MONGO_X509("MONGO-X509");

	private String text;

	MongoAuthMechanism(String text) {
		this.text = text;
	}

	public String getText() {
		return this.text;
	}

	public static MongoAuthMechanism fromString(String text) {
		if(StringUtils.isNotEmpty(text)) {
			String t = replaceUnwantedChars(text);
			for (MongoAuthMechanism b : MongoAuthMechanism.values()) {
				String enumText = replaceUnwantedChars(b.text);
				if (t.equalsIgnoreCase(enumText)) {
					return b;
				}
			}
		}
		throw new IllegalArgumentException("No constant with text " + text + " found");
	}
	
	private static String replaceUnwantedChars(String text) {
		String t = text;
		for(String s : new String[]{"_", "-"}) {
			t = t.replace(s, "");
		}
		return t;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy