1 29 30 package com.caucho.security; 31 32 import com.caucho.log.Log; 33 import com.caucho.util.L10N; 34 35 import java.security.Principal ; 36 import java.util.logging.Logger ; 37 38 41 public class SecurityContext { 42 static final Logger log = Log.open(SecurityContext.class); 43 static final L10N L = new L10N(SecurityContext.class); 44 45 48 private static ThreadLocal <SecurityContextProvider> _providers 49 = new ThreadLocal <SecurityContextProvider>(); 50 51 54 private SecurityContext() 55 { 56 } 57 58 63 public static Principal getUserPrincipal() 64 throws SecurityContextException 65 { 66 SecurityContextProvider provider = getProvider(); 67 68 if (provider != null) 69 return provider.getUserPrincipal(); 70 else 71 return null; 72 } 73 74 79 public static boolean isUserInRole(String roleName) 80 { 81 SecurityContextProvider provider = getProvider(); 82 83 if (provider != null) 84 return provider.isUserInRole(roleName); 85 else 86 return false; 87 } 88 89 94 public static boolean isUserInRole(String []roleSet) 95 { 96 SecurityContextProvider provider = getProvider(); 97 98 if (provider != null && roleSet != null) { 99 for (int i = 0; i < roleSet.length; i++) { 100 if (provider.isUserInRole(roleSet[i])) 101 return true; 102 } 103 } 104 105 return false; 106 } 107 108 111 public static boolean isTransportSecure() 112 throws SecurityContextException 113 { 114 SecurityContextProvider provider = getProvider(); 115 116 if (provider != null) 117 return provider.isTransportSecure(); 118 else 119 return false; 120 } 121 122 125 public static void logout() 126 throws SecurityContextException 127 { 128 SecurityContextProvider provider = getProvider(); 129 130 if (provider != null) 131 provider.logout(); 132 } 133 134 139 public static SecurityContextProvider getProvider() 140 { 141 return _providers.get(); 142 } 143 144 149 public static SecurityContextProvider setProvider(SecurityContextProvider provider) 150 { 151 SecurityContextProvider oldProvider = _providers.get(); 152 153 _providers.set(provider); 154 155 return oldProvider; 156 } 157 } 158 | Popular Tags |