3 * Copyright (C) 2015 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.
10 package eu
.etaxonomy
.cdm
.vaadin
.util
;
13 import java
.util
.HashMap
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.springframework
.security
.core
.Authentication
;
24 public class CdmVaadinAuthentication
{
25 private final static Logger logger
= Logger
.getLogger(CdmVaadinAuthentication
.class);
27 public static final String KEY
= "key_authentication";
29 Map
<String
, Authentication
> hostAuthenticationMap
= new HashMap
<String
, Authentication
>();
31 public void addAuthentication(URI requestSourceUri
, String requestSourceContext
, Authentication authentication
) {
32 addAuthentication(getRequestSource(requestSourceUri
, requestSourceContext
), authentication
);
35 public void addAuthentication(String requestSource
, Authentication authentication
) {
36 if(requestSource
== null || requestSource
.isEmpty()) {
37 throw new IllegalStateException("When setting authentication, host cannot be null or empty");
40 if(authentication
== null) {
41 throw new IllegalStateException("When setting authentication, authentication object cannot be null");
43 hostAuthenticationMap
.put(requestSource
, authentication
);
46 public boolean isAuthenticated(URI uri
, String context
) {
47 if(uri
!= null && context
!= null && !context
.isEmpty()) {
48 Authentication authentication
= hostAuthenticationMap
.get(getRequestSource(uri
, context
));
49 if(authentication
!= null) {
50 return authentication
.isAuthenticated();
56 public static String
getRequestSource(URI uri
, String context
) {
57 String source
= uri
.getHost() + ":" + String
.valueOf(uri
.getPort()) + context
;
58 logger
.warn(" request source : " + source
);