001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2012 GRANITE DATA SERVICES S.A.S.
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.client.tide.javafx.cdi;
022
023 import java.util.HashMap;
024 import java.util.Map;
025
026 import javax.inject.Named;
027
028 import org.granite.client.tide.javafx.BaseIdentity;
029 import org.granite.client.tide.javafx.ObservableRole;
030 import org.granite.client.tide.server.ServerSession;
031 import org.granite.messaging.amf.RemoteClass;
032
033 /**
034 * @author William DRAI
035 */
036 @RemoteClass("org.granite.tide.cdi.Identity")
037 @Named
038 public class Identity extends BaseIdentity {
039
040 protected Identity() {
041 // CDI proxying...
042 }
043
044 public Identity(final ServerSession serverSession) {
045 super(serverSession);
046 }
047
048
049 private Map<String, ObservableRole> hasRoleCache = new HashMap<String, ObservableRole>();
050
051
052 public ObservableRole hasRole(String roleName) {
053 ObservableRole role = hasRoleCache.get(roleName);
054 if (role == null) {
055 role = new ObservableRole(this, getContext(), getServerSession(), "hasRole", roleName);
056 hasRoleCache.put(roleName, role);
057 }
058 return role;
059 }
060
061
062 @Override
063 protected void initSecurityCache() {
064 for (ObservableRole role : hasRoleCache.values())
065 role.clear();
066 }
067
068 /**
069 * Clear the security cache
070 */
071 @Override
072 public void clearSecurityCache() {
073 for (ObservableRole role : hasRoleCache.values())
074 role.clear();
075 hasRoleCache.clear();
076 }
077 }
078