3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.store
;
13 import java
.util
.Observable
;
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
;
20 import eu
.etaxonomy
.cdm
.model
.common
.User
;
27 public class LoginManager
extends Observable
{
28 private static final Logger logger
= Logger
.getLogger(LoginManager
.class);
33 public void authenticate(UsernamePasswordAuthenticationToken token
){
34 Authentication authentication
= CdmStore
.getAuthenticationManager().authenticate(token
);
35 SecurityContextHolder
.getContext().setAuthentication(authentication
);
38 this.notifyObservers();
45 public User
getAuthenticatedUser(){
46 Authentication authentication
= SecurityContextHolder
.getContext().getAuthentication();
48 if(authentication
!= null
49 && authentication
.getPrincipal() != null
50 && authentication
.getPrincipal() instanceof User
){
51 return (User
)authentication
.getPrincipal();