1
|
/**
|
2
|
* Copyright (C) 2015 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.presenter;
|
10
|
|
11
|
import java.net.URI;
|
12
|
import java.net.URISyntaxException;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.junit.Assert;
|
16
|
import org.junit.Test;
|
17
|
import org.springframework.security.authentication.BadCredentialsException;
|
18
|
import org.unitils.spring.annotation.SpringBeanByType;
|
19
|
|
20
|
import com.vaadin.server.VaadinSession;
|
21
|
|
22
|
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
|
23
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinAuthentication;
|
24
|
|
25
|
/**
|
26
|
* @author cmathew
|
27
|
* @date 28 Apr 2015
|
28
|
*
|
29
|
*/
|
30
|
public class AuthenticationPresenterTest extends CdmVaadinBaseTest {
|
31
|
|
32
|
private static final Logger logger = Logger.getLogger(AuthenticationPresenterTest.class);
|
33
|
|
34
|
@SpringBeanByType
|
35
|
private AuthenticationPresenter ap = null;
|
36
|
|
37
|
@Test
|
38
|
public void testLogin() throws URISyntaxException {
|
39
|
URI uri = new URI("http://localhost:8080/cdm-vaadin/app/authtest");
|
40
|
String context = "/cdm-vaadin";
|
41
|
boolean isAuthenticated = false;
|
42
|
try {
|
43
|
isAuthenticated = ap.login(uri, context, "admin", "000");
|
44
|
Assert.fail("BadCredentialsException should be thrown here");
|
45
|
} catch(BadCredentialsException e){
|
46
|
|
47
|
}
|
48
|
|
49
|
isAuthenticated = ap.login(uri, context, "admin", "00000");
|
50
|
Assert.assertTrue(isAuthenticated);
|
51
|
|
52
|
CdmVaadinAuthentication authentication = (CdmVaadinAuthentication) VaadinSession.getCurrent().getAttribute(CdmVaadinAuthentication.KEY);
|
53
|
Assert.assertTrue(authentication.isAuthenticated(uri, context));
|
54
|
|
55
|
URI anotherUri = new URI("http://localhost:8081/cdm-edit/app/authtest");
|
56
|
Assert.assertFalse(authentication.isAuthenticated(anotherUri, context));
|
57
|
|
58
|
String anotherContext = "/cdm-edit";
|
59
|
Assert.assertFalse(authentication.isAuthenticated(uri, anotherContext));
|
60
|
|
61
|
isAuthenticated = ap.login(anotherUri, anotherContext, "admin", "00000");
|
62
|
Assert.assertTrue(isAuthenticated);
|
63
|
|
64
|
Assert.assertTrue(authentication.isAuthenticated(anotherUri, anotherContext));
|
65
|
|
66
|
}
|
67
|
|
68
|
}
|