1
|
/**
|
2
|
* Copyright (C) 2018 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.api.utility;
|
10
|
|
11
|
import org.springframework.security.core.Authentication;
|
12
|
|
13
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
|
14
|
|
15
|
/**
|
16
|
* @author a.kohlbecker
|
17
|
* @since Jul 25, 2018
|
18
|
*
|
19
|
*/
|
20
|
public class RoleProber implements RoleProbe {
|
21
|
|
22
|
Role role;
|
23
|
|
24
|
public RoleProber(Role role){
|
25
|
this.role = role;
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* {@inheritDoc}
|
30
|
*/
|
31
|
@Override
|
32
|
public boolean checkForRole(Authentication authentication) {
|
33
|
if(authentication != null) {
|
34
|
return authentication.getAuthorities().stream().anyMatch(a -> {
|
35
|
return a.equals(role);
|
36
|
});
|
37
|
}
|
38
|
return false;
|
39
|
}
|
40
|
|
41
|
}
|