1 23 24 package com.sun.enterprise.security.auth.realm.certificate; 25 26 import java.lang.*; 27 import java.util.*; 28 import java.util.logging.Logger ; 29 import java.io.*; 30 import java.security.*; 31 32 import javax.security.auth.login.*; 33 import javax.security.auth.Subject ; 34 35 import com.sun.enterprise.deployment.Group; 36 import com.sun.enterprise.security.SecurityContext; 37 import com.sun.enterprise.security.auth.Privilege; 38 import com.sun.enterprise.security.auth.PrivilegeImpl; 39 import com.sun.enterprise.security.auth.realm.User; 40 import com.sun.enterprise.security.auth.realm.Realm; 41 import com.sun.enterprise.security.auth.realm.BadRealmException; 42 import com.sun.enterprise.security.auth.realm.NoSuchUserException; 43 import com.sun.enterprise.security.auth.realm.NoSuchRealmException; 44 import com.sun.enterprise.security.auth.realm.AuthenticationHandler; 45 import com.sun.enterprise.security.auth.realm.InvalidOperationException; 46 47 import com.sun.enterprise.server.*; 48 import com.sun.enterprise.security.util.*; 49 import com.sun.enterprise.security.auth.realm.IASRealm; 50 51 import sun.security.x509.X500Name; 52 53 54 83 84 85 public final class CertificateRealm extends IASRealm 86 { 87 public static final String AUTH_TYPE = "certificate"; 89 90 93 99 public static final String PARAM_GROUPS = "assign-groups"; 101 private static final String GROUPS_SEP = ","; 102 private Vector defaultGroups = null; 103 private Group[] groupsAsPrincipals = null; 106 107 108 120 protected void init(Properties props) 121 { 122 140 141 151 152 defaultGroups = new Vector(); 154 String groupList = props.getProperty(PARAM_GROUPS); 155 156 if (groupList != null) { 157 _logger.fine("CertificateRealm : groups: " + groupList); 158 StringTokenizer st = new StringTokenizer(groupList, GROUPS_SEP); 159 while (st.hasMoreTokens()) { 160 String grp = (String )st.nextToken(); 161 defaultGroups.add(grp); 162 } 163 164 int groups = defaultGroups.size(); 167 175 groupsAsPrincipals = new Group[groups]; 176 for (int i = 0; i < groups; i++) { 177 groupsAsPrincipals[i] = new Group((String )defaultGroups.get(i)); 178 } 179 } else { 180 181 groupsAsPrincipals = new Group[0]; 184 } 185 } 186 187 188 195 public String getAuthType() 196 { 197 return AUTH_TYPE; 198 } 199 200 201 212 public Enumeration getGroupNames(String username) 213 throws NoSuchUserException, InvalidOperationException 214 { 215 218 return defaultGroups.elements(); 221 } 222 223 224 234 public String getJAASContext() 235 { 236 _logger.warning("certrealm.nojaas"); 237 return null; 238 } 239 240 241 258 public void authenticate(Subject subject, X500Name x500name) 259 { 260 264 String name = x500name.getName(); 265 266 _logger.finest("Certificate realm setting up security context for: "+ 267 name); 268 269 int gsize = groupsAsPrincipals.length; 272 Set principalSet = subject.getPrincipals(); 273 for (int i = 0; i < gsize; i++) { 274 principalSet.add(groupsAsPrincipals[i]); 275 } 276 SecurityContext securityContext = 277 new SecurityContext(name, subject); 278 279 SecurityContext.setCurrent(securityContext); 280 } 281 282 283 } 284 | Popular Tags |