Revision 320ad9d6
Added by Andreas Kohlbecker almost 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/permission/PermissionDebugUtils.java | ||
---|---|---|
12 | 12 |
import java.util.EnumSet; |
13 | 13 |
import java.util.UUID; |
14 | 14 |
|
15 |
import org.apache.log4j.Logger; |
|
15 |
import javax.annotation.PostConstruct; |
|
16 |
|
|
16 | 17 |
import org.springframework.context.annotation.Profile; |
17 | 18 |
|
18 | 19 |
import com.vaadin.server.FontAwesome; |
19 |
import com.vaadin.server.VaadinSession; |
|
20 | 20 |
import com.vaadin.spring.annotation.SpringComponent; |
21 |
import com.vaadin.spring.annotation.UIScope; |
|
22 | 21 |
import com.vaadin.ui.AbstractComponentContainer; |
23 | 22 |
import com.vaadin.ui.Button; |
24 | 23 |
import com.vaadin.ui.themes.ValoTheme; |
25 | 24 |
|
26 | 25 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
27 | 26 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD; |
27 |
import eu.etaxonomy.cdm.service.UserHelperAccess; |
|
28 | 28 |
|
29 | 29 |
/** |
30 | 30 |
* PermissionDebugUtils provide the following tools: |
... | ... | |
34 | 34 |
* </ul> |
35 | 35 |
* |
36 | 36 |
* |
37 |
* |
|
38 | 37 |
* To enable the PermissionDebugUtils you need to activate the spring profile <code>debug</code>. You can add |
39 | 38 |
* <code>-Dspring.profiles.active=debug</code> to the command starting the jvm |
40 | 39 |
* or set this as an environment variable. |
... | ... | |
44 | 43 |
* |
45 | 44 |
*/ |
46 | 45 |
@SpringComponent |
47 |
@UIScope |
|
48 | 46 |
@Profile("debug") |
49 | 47 |
public class PermissionDebugUtils implements Serializable { |
50 | 48 |
|
51 | 49 |
private static final long serialVersionUID = -210079304170235459L; |
52 | 50 |
|
53 |
private final static Logger logger = Logger.getLogger(PermissionDebugUtils.class); |
|
54 |
|
|
55 |
public static final String VADDIN_SESSION_KEY = "PERMISSION_DEBUG_UTILS"; |
|
56 |
|
|
57 |
public static final String SYSTEM_PROP_KEY = "GainPerEntityPermissionButtons"; |
|
58 |
|
|
51 |
private static PermissionDebugUtils bean; |
|
59 | 52 |
|
60 |
public PermissionDebugUtils() { |
|
61 |
VaadinSession.getCurrent().setAttribute(VADDIN_SESSION_KEY, this); |
|
53 |
@PostConstruct |
|
54 |
public void registerBean() { |
|
55 |
PermissionDebugUtils.bean = this; |
|
62 | 56 |
} |
63 | 57 |
|
64 |
public static PermissionDebugUtils fromSession() {
|
|
65 |
return (PermissionDebugUtils)VaadinSession.getCurrent().getAttribute(VADDIN_SESSION_KEY);
|
|
58 |
public static PermissionDebugUtils bean() {
|
|
59 |
return bean;
|
|
66 | 60 |
} |
67 | 61 |
|
68 | 62 |
public static Button addGainPerEntityPermissionButton(AbstractComponentContainer toContainer, Class<? extends CdmBase> cdmType, |
69 | 63 |
UUID entitiyUuid, EnumSet<CRUD> crud, String property){ |
70 | 64 |
|
71 |
PermissionDebugUtils pu = PermissionDebugUtils.fromSession();
|
|
65 |
PermissionDebugUtils pu = PermissionDebugUtils.bean();
|
|
72 | 66 |
if(pu != null){ |
73 | 67 |
Button button = pu.gainPerEntityPermissionButton(cdmType, entitiyUuid, crud, property); |
74 | 68 |
if(button != null){ |
... | ... | |
82 | 76 |
public Button gainPerEntityPermissionButton(Class<? extends CdmBase> cdmType, UUID entitiyUuid, EnumSet<CRUD> crud, String property){ |
83 | 77 |
|
84 | 78 |
Button button = new Button(FontAwesome.BOLT); |
85 |
button.addClickListener(e -> VaadinUserHelper.fromSession().createAuthorityFor(VaadinUserHelper.fromSession().userName(), cdmType, entitiyUuid, crud, property));
|
|
79 |
button.addClickListener(e -> UserHelperAccess.userHelper().createAuthorityFor(UserHelperAccess.userHelper().userName(), cdmType, entitiyUuid, crud, property));
|
|
86 | 80 |
button.addStyleName(ValoTheme.BUTTON_DANGER); |
87 | 81 |
return button; |
88 | 82 |
|
Also available in: Unified diff
ref #7550 replacing the selfregisration of the VaadinUserHelper to the vaadin session by a UserHelperAccess bean