summaryrefslogblamecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/serversession/ServerAuthenticator.java
blob: b0fd72fa4c9159d66c84ca29ff3e8151e2411c64 (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                                    
                                                  






                                                                                                     






                                                                        








                                                  










                                                                                             
package org.openslx.imagemaster.serversession;

import java.util.HashMap;

import org.apache.thrift.TException;
import org.openslx.imagemaster.thrift.iface.AuthenticationException;
import org.openslx.imagemaster.util.RandomString;

public class ServerAuthenticator {
	// map of currently authenticating servers
	private static HashMap<String, String> authenticatingServers = new HashMap<String, String>();
	/**
	 * Start the server authentification.
	 * @param organization the organization of the server
	 * @return encrypted random string
	 */
	public static String startServerAuthentication(String organization) {
		String secret = RandomString.generate(100, false);
		synchronized (authenticatingServers) {
			authenticatingServers.put(organization, secret);
		}
		return secret;
	}
	
	/**
	 * Authenticate with the challengeResponse
	 * @param organization
	 * @param address
	 * @param challengeResponse
	 * @return
	 * @throws AuthenticationException
	 * @throws TException
	 */
	public static ServerUser serverAuthenticate(String organization, String address, 
			String challengeResponse) throws AuthenticationException,
			TException {
		/*
		 * TODO:
		 * Decrypt the given challengeResponse and check whether it was right or not.
		 * Authenticate server if so.
		 */
		return new ServerUser(organization, address);
	}
}