Package loginservice

Source Code of loginservice.AuthenticationService

package loginservice;

import loginservice.model.Session;

import org.apache.log4j.Logger;

import de.bamberg.ha.api.cluster.ClusterManager;
import de.bamberg.ha.api.cluster.ClusterManagerFactory;
import de.bamberg.ha.api.cluster.DistributedExecution;
import de.bamberg.ha.api.cluster.DistributedExecution.DistributedExecutionTarget;

/**
* A Test service implementing simple authentication features
* @author erik.bamberg
*
*/
public class AuthenticationService {
  private static final Logger log = Logger
      .getLogger(AuthenticationService.class);
 
  private ClusterManagerFactory clusterManagerFactory;

  public AuthenticationService(ClusterManagerFactory clusterManagerFactory) {
    super();
    this.clusterManagerFactory = clusterManagerFactory;
  }

//  public AuthenticationService(ServiceRegistry registry) {
//    super();   
//  }


  public String login() {
    log.debug("trying to login");
    ClusterManager clusterManager=clusterManagerFactory.getClusterManager();
    Session newSession=new Session();
    newSession=(Session) clusterManager.distribute(newSession);
    String sessionid=newSession.getId();
    return sessionid;
  }
 
  @DistributedExecution (DistributedExecutionTarget.KEY_OWNER)
  public void logout(String sessionID) {
    ClusterManager clusterManager=clusterManagerFactory.getClusterManager();
    System.out.println(clusterManager.getLocalMember()+":"+sessionID);
    Session session=(Session) clusterManager.get(sessionID, Session.class);
    if (session!=null) {
      clusterManager.remove(session);
    } else {
      throw new IllegalArgumentException("session not found");
    }
  }

}
TOP

Related Classes of loginservice.AuthenticationService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.