1 7 8 package com.sun.security.auth.module; 9 10 import java.util.*; 11 import java.io.IOException ; 12 import javax.security.auth.*; 13 import javax.security.auth.callback.*; 14 import javax.security.auth.login.*; 15 import javax.security.auth.spi.*; 16 import com.sun.security.auth.SolarisPrincipal; 17 import com.sun.security.auth.SolarisNumericUserPrincipal; 18 import com.sun.security.auth.SolarisNumericGroupPrincipal; 19 20 38 @Deprecated 39 public class SolarisLoginModule implements LoginModule { 40 41 private Subject subject; 43 private CallbackHandler callbackHandler; 44 private Map sharedState; 45 private Map options; 46 47 private boolean debug = true; 49 50 private SolarisSystem ss; 52 53 private boolean succeeded = false; 55 private boolean commitSucceeded = false; 56 57 private SolarisPrincipal userPrincipal; 59 private SolarisNumericUserPrincipal UIDPrincipal; 60 private SolarisNumericGroupPrincipal GIDPrincipal; 61 private LinkedList supplementaryGroups = new LinkedList(); 62 63 80 public void initialize(Subject subject, CallbackHandler callbackHandler, 81 Map<String ,?> sharedState, 82 Map<String ,?> options) 83 { 84 85 this.subject = subject; 86 this.callbackHandler = callbackHandler; 87 this.sharedState = sharedState; 88 this.options = options; 89 90 debug = "true".equalsIgnoreCase((String )options.get("debug")); 92 } 93 94 109 public boolean login() throws LoginException { 110 111 long[] solarisGroups = null; 112 113 ss = new SolarisSystem(); 114 115 if (ss == null) { 116 succeeded = false; 117 throw new FailedLoginException 118 ("Failed in attempt to import " + 119 "the underlying system identity information"); 120 } else { 121 userPrincipal = new SolarisPrincipal(ss.getUsername()); 122 UIDPrincipal = new SolarisNumericUserPrincipal(ss.getUid()); 123 GIDPrincipal = new SolarisNumericGroupPrincipal(ss.getGid(), true); 124 if (ss.getGroups() != null && ss.getGroups().length > 0) 125 solarisGroups = ss.getGroups(); 126 for (int i = 0; i < solarisGroups.length; i++) { 127 SolarisNumericGroupPrincipal ngp = 128 new SolarisNumericGroupPrincipal 129 (solarisGroups[i], false); 130 if (!ngp.getName().equals(GIDPrincipal.getName())) 131 supplementaryGroups.add(ngp); 132 } 133 if (debug) { 134 System.out.println("\t\t[SolarisLoginModule]: " + 135 "succeeded importing info: "); 136 System.out.println("\t\t\tuid = " + ss.getUid()); 137 System.out.println("\t\t\tgid = " + ss.getGid()); 138 solarisGroups = ss.getGroups(); 139 for (int i = 0; i < solarisGroups.length; i++) { 140 System.out.println("\t\t\tsupp gid = " + solarisGroups[i]); 141 } 142 } 143 succeeded = true; 144 return true; 145 } 146 } 147 148 171 public boolean commit() throws LoginException { 172 if (succeeded == false) { 173 if (debug) { 174 System.out.println("\t\t[SolarisLoginModule]: " + 175 "did not add any Principals to Subject " + 176 "because own authentication failed."); 177 } 178 return false; 179 } 180 if (subject.isReadOnly()) { 181 throw new LoginException ("Subject is Readonly"); 182 } 183 if (!subject.getPrincipals().contains(userPrincipal)) 184 subject.getPrincipals().add(userPrincipal); 185 if (!subject.getPrincipals().contains(UIDPrincipal)) 186 subject.getPrincipals().add(UIDPrincipal); 187 if (!subject.getPrincipals().contains(GIDPrincipal)) 188 subject.getPrincipals().add(GIDPrincipal); 189 for (int i = 0; i < supplementaryGroups.size(); i++) { 190 if (!subject.getPrincipals().contains 191 ((SolarisNumericGroupPrincipal)supplementaryGroups.get(i))) 192 subject.getPrincipals().add((SolarisNumericGroupPrincipal) 193 supplementaryGroups.get(i)); 194 } 195 196 if (debug) { 197 System.out.println("\t\t[SolarisLoginModule]: " + 198 "added SolarisPrincipal,"); 199 System.out.println("\t\t\t\tSolarisNumericUserPrincipal,"); 200 System.out.println("\t\t\t\tSolarisNumericGroupPrincipal(s),"); 201 System.out.println("\t\t\t to Subject"); 202 } 203 204 commitSucceeded = true; 205 return true; 206 } 207 208 209 228 public boolean abort() throws LoginException { 229 if (debug) { 230 System.out.println("\t\t[SolarisLoginModule]: " + 231 "aborted authentication attempt"); 232 } 233 234 if (succeeded == false) { 235 return false; 236 } else if (succeeded == true && commitSucceeded == false) { 237 238 succeeded = false; 240 ss = null; 241 userPrincipal = null; 242 UIDPrincipal = null; 243 GIDPrincipal = null; 244 supplementaryGroups = new LinkedList(); 245 } else { 246 logout(); 249 } 250 return true; 251 } 252 253 266 public boolean logout() throws LoginException { 267 if (debug) { 268 System.out.println("\t\t[SolarisLoginModule]: " + 269 "Entering logout"); 270 } 271 if (subject.isReadOnly()) { 272 throw new LoginException ("Subject is Readonly"); 273 } 274 subject.getPrincipals().remove(userPrincipal); 276 subject.getPrincipals().remove(UIDPrincipal); 277 subject.getPrincipals().remove(GIDPrincipal); 278 for (int i = 0; i < supplementaryGroups.size(); i++) { 279 subject.getPrincipals().remove 280 ((SolarisNumericGroupPrincipal)supplementaryGroups.get(i)); 281 } 282 283 ss = null; 285 succeeded = false; 286 commitSucceeded = false; 287 userPrincipal = null; 288 UIDPrincipal = null; 289 GIDPrincipal = null; 290 supplementaryGroups = new LinkedList(); 291 292 if (debug) { 293 System.out.println("\t\t[SolarisLoginModule]: " + 294 "logged out Subject"); 295 } 296 return true; 297 } 298 } 299 | Popular Tags |