endnote and excel import added. fixes #779
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / LoginManager.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.store;
12
13 import java.util.Observable;
14
15 import org.apache.log4j.Logger;
16 import org.springframework.security.Authentication;
17 import org.springframework.security.context.SecurityContextHolder;
18 import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
19
20 import eu.etaxonomy.cdm.model.common.User;
21
22 /**
23 * @author n.hoffmann
24 * @created 03.07.2009
25 * @version 1.0
26 */
27 public class LoginManager extends Observable{
28 private static final Logger logger = Logger.getLogger(LoginManager.class);
29
30 /**
31 * @param token
32 */
33 public void authenticate(UsernamePasswordAuthenticationToken token){
34 Authentication authentication = CdmStore.getAuthenticationManager().authenticate(token);
35 SecurityContextHolder.getContext().setAuthentication(authentication);
36
37 this.setChanged();
38 this.notifyObservers();
39 }
40
41 /**
42 *
43 * @return
44 */
45 public User getAuthenticatedUser(){
46 Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
47
48 if(authentication != null
49 && authentication.getPrincipal() != null
50 && authentication.getPrincipal() instanceof User){
51 return (User)authentication.getPrincipal();
52 }
53 return null;
54 }
55 }