1 23 24 package com.rift.coad.lib.security; 26 27 import java.util.Vector ; 29 import java.util.HashSet ; 30 import java.util.Set ; 31 32 37 public class ThreadPermissionSession { 38 39 private Long threadId = null; 41 private UserSession user = null; 42 private Vector containerList = null; 43 44 50 public ThreadPermissionSession(Long threadId, UserSession user) { 51 this.threadId = threadId; 52 this.user = user; 53 containerList = new Vector (); 54 containerList.add(user); 55 } 56 57 58 64 public Long getThreadId() throws SecurityException { 65 try { 66 user.touch(); 67 } catch (Exception ex) { 68 throw new SecurityException ("Failed to touch the users session : " + 69 ex.getMessage(),ex); 70 } 71 return threadId; 72 } 73 74 75 82 public UserSession getUser() throws SecurityException { 83 try { 84 user.touch(); 85 } catch (Exception ex) { 86 throw new SecurityException ("Failed to touch the users session : " + 87 ex.getMessage(),ex); 88 } 89 return user; 90 } 91 92 93 99 public Set getPrincipals() throws SecurityException { 100 Set principals = new HashSet (); 101 for (int i = 0; i < containerList.size(); i++) { 102 principals.addAll(((PrincipalContainer)containerList.get(i)). 103 getPrincipals()); 104 } 105 try { 106 user.touch(); 107 } catch (Exception ex) { 108 throw new SecurityException ("Failed to touch the users session : " + 109 ex.getMessage(),ex); 110 } 111 return principals; 112 } 113 114 115 121 public void addRole(Role role) throws SecurityException { 122 try { 123 user.touch(); 124 } catch (Exception ex) { 125 throw new SecurityException ("Failed to touch the users session : " + 126 ex.getMessage(),ex); 127 } 128 containerList.add(role); 129 } 130 131 132 137 public void removeRole(Role role) { 138 for (int i = 0; i < containerList.size(); i++) { 139 if (((PrincipalContainer)containerList.get(containerList.size() - 140 (i + 1))).getName().equals(role.getName())) { 141 containerList.remove(containerList.size() - (i + 1)); 142 break; 143 } 144 } 145 } 146 } 147 | Popular Tags |