/**
 * Copyright 2014 by Eclettica s.r.l. All Rights Reserved.
 *
 * This file is part of eSecurePlay1 project.
 *
 * The contents of this file are subject to the Eclettica Private License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.eclettica.net/
 * 
 * Original file name: PlaySessionService.java
 * Created by gannunziata at 27/mag/2014 11:23:43 
 */
package services;

import play.mvc.Scope.Session;
import net.eclettica.esecure.services.ISessionService;

/**
 * 
 * @author gannunziata
 */
public class PlaySessionService implements ISessionService {

	private static final String ESECURE_SESSION_ENTRY = "___esecure_session_id";
	/**
	 * 
	 */
	@Override
	public String checkSession(String sessionId) {
		String uuid = Session.current().get(ESECURE_SESSION_ENTRY);
		return uuid;
	}

	/**
	 * Non fa nulla. La sessione scade da sola (play).
	 * 
	 * @see net.eclettica.esecure.services.ISessionService#cleanup()
	 */
	@Override
	public void cleanup() {		
	}

	/**
	 * crea entry in sessione
	 * @see net.eclettica.esecure.services.ISessionService#createSession(java.lang.String)
	 */
	@Override
	public String createSession(String uuid) {
		Session.current().put(ESECURE_SESSION_ENTRY, uuid);
		return uuid;
	}

	/* (non-Javadoc)
	 * @see net.eclettica.esecure.services.ISessionService#removeSession(java.lang.String)
	 */
	@Override
	public void removeSession(String uuid) {
		String id = checkSession(uuid);
		if (id == null)
			return;
		Session.current().remove(ESECURE_SESSION_ENTRY);
	}
	
}
