1 25 26 package com.rift.coad.lib.security; 28 29 import java.util.Map ; 31 import java.util.HashMap ; 32 33 import org.apache.log4j.Logger; 35 36 37 44 public class ThreadsPermissionContainer { 45 46 private Logger log = 48 Logger.getLogger(ThreadsPermissionContainer.class.getName()); 49 50 51 private Map permissions = null; 53 54 57 public ThreadsPermissionContainer() { 58 permissions = new HashMap (); 59 } 60 61 62 68 public synchronized void putSession(Long threadId, 69 ThreadPermissionSession session) { 70 permissions.put(threadId,session); 71 } 72 73 74 82 public synchronized ThreadPermissionSession getSession(Long threadId) 83 throws SecurityException { 84 return (ThreadPermissionSession)permissions.get(threadId); 85 } 86 87 88 94 public synchronized void removeSession(Long threadId) 95 throws SecurityException { 96 permissions.remove(threadId); 97 } 98 99 100 107 public ThreadPermissionSession getSession() 108 throws SecurityException { 109 Long threadId = new Long (Thread.currentThread().getId()); 110 log.debug("Get session for [" + threadId + "]"); 111 ThreadPermissionSession session = getSession(threadId); 112 if (session == null) { 113 throw new SecurityException ( 114 "No session can be found for current thread."); 115 } 116 return session; 117 } 118 119 120 126 public void pushRole(String roleName) throws SecurityException { 127 ThreadPermissionSession session = getSession(); 128 Role role = RoleManager.getInstance().getRole(roleName); 129 if (role.canAccessRole(session.getPrincipals()) == false) { 130 throw new SecurityException ( 131 "The session does not have the rights to these permissions"); 132 } 133 session.addRole(role); 134 } 135 136 137 143 public void popRole(String roleName) throws SecurityException { 144 ThreadPermissionSession session = getSession(); 145 Role role = RoleManager.getInstance().getRole(roleName); 146 session.removeRole(role); 147 } 148 149 } 150 | Popular Tags |