001/** 002 * GRANITE DATA SERVICES 003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S. 004 * 005 * This file is part of the Granite Data Services Platform. 006 * 007 * *** 008 * 009 * Community License: GPL 3.0 010 * 011 * This file is free software: you can redistribute it and/or modify 012 * it under the terms of the GNU General Public License as published 013 * by the Free Software Foundation, either version 3 of the License, 014 * or (at your option) any later version. 015 * 016 * This file is distributed in the hope that it will be useful, but 017 * WITHOUT ANY WARRANTY; without even the implied warranty of 018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 019 * GNU General Public License for more details. 020 * 021 * You should have received a copy of the GNU General Public License 022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 023 * 024 * *** 025 * 026 * Available Commercial License: GraniteDS SLA 1.0 027 * 028 * This is the appropriate option if you are creating proprietary 029 * applications and you are not prepared to distribute and share the 030 * source code of your application under the GPL v3 license. 031 * 032 * Please visit http://www.granitedataservices.com/license for more 033 * details. 034 */ 035package org.granite.client.tide.spring; 036 037import javax.inject.Named; 038 039import org.granite.client.messaging.RemoteAlias; 040import org.granite.client.tide.BaseIdentity; 041import org.granite.client.tide.security.TidePermissionCache; 042import org.granite.client.tide.security.TideRoleCache; 043import org.granite.client.tide.server.ServerSession; 044import org.granite.client.tide.server.TideResponder; 045 046/** 047 * @author William DRAI 048 */ 049@RemoteAlias("org.granite.tide.spring.security.Identity") 050@Named 051public class Identity extends BaseIdentity { 052 053 public Identity(final ServerSession serverSession) { 054 super(serverSession); 055 } 056 057 058 private final TideRoleCache ifAllGrantedCache = new TideRoleCache(this, "ifAllGranted"); 059 private final TideRoleCache ifAnyGrantedCache = new TideRoleCache(this, "ifAnyGranted"); 060 private final TideRoleCache ifNotGrantedCache = new TideRoleCache(this, "ifNotGranted"); 061 private final TidePermissionCache hasPermissionCache = new TidePermissionCache(this); 062 063 064 public boolean hasRole(String roleName, final TideResponder<Boolean> tideResponder) { 065 return ifAllGranted(roleName, tideResponder); 066 } 067 068 public boolean ifAllGranted(final String roleName, final TideResponder<Boolean> tideResponder) { 069 return ifAllGrantedCache.get(roleName, tideResponder); 070 } 071 072 public boolean ifAnyGranted(final String roleName, final TideResponder<Boolean> tideResponder) { 073 return ifAnyGrantedCache.get(roleName, tideResponder); 074 } 075 076 public boolean ifNotGranted(final String roleName, final TideResponder<Boolean> tideResponder) { 077 return ifNotGrantedCache.get(roleName, tideResponder); 078 } 079 080 public boolean hasPermission(final Object object, final String action, final TideResponder<Boolean> tideResponder) { 081 return hasPermissionCache.get(object, action, tideResponder); 082 } 083 084 085 protected void initSecurityCache() { 086 ifAllGrantedCache.clear(); 087 ifAnyGrantedCache.clear(); 088 ifNotGrantedCache.clear(); 089 hasPermissionCache.clear(); 090 } 091 092 /** 093 * Clear the security cache 094 */ 095 @Override 096 public void clearSecurityCache() { 097 super.clearSecurityCache(); 098 099 ifAllGrantedCache.clear(); 100 ifAnyGrantedCache.clear(); 101 ifNotGrantedCache.clear(); 102 hasPermissionCache.clear(); 103 } 104 105}