public static Subject jmacLogin(Subject subject, String identityAssertion, String realm) throws LoginException { if (subject == null) { subject = new Subject(); } final Subject fs = subject; String userName = identityAssertion; try { if (realm == null || "".equals(realm)) { realm = Realm.getDefaultRealm(); } Realm realmInst = Realm.getInstance(realm); final Enumeration groups = realmInst.getGroupNames(userName); if (groups != null && groups.hasMoreElements()) { AppservAccessController.doPrivileged(new PrivilegedAction() { public java.lang.Object run() { while (groups.hasMoreElements()) { String grp = (String) groups.nextElement(); fs.getPrincipals().add(new Group(grp)); } return fs; } }); } } catch (Exception ex) { if (_logger.isLoggable(Level.FINE)) { _logger.log(Level.FINE, "Exception when trying to populate groups for CallerPrincipal " + identityAssertion, ex); } } return subject; }
/** * Instantiate a Realm with the given name and properties using the * Class name given. This method is used by iAS and not RI. * * @param name Name of the new realm. * @param className Java Class name of the realm to create. * @param props Properties containing values of the Property element * from server.xml * @returns Reference to the new Realm. The Realm class keeps an internal * list of all instantiated realms. * @throws BadRealmException If the requested realm cannot be instantiated. * */ public static synchronized Realm instantiate(String name, String className, Properties props) throws BadRealmException { //Register the realm provider registerRealmStatsProvier(); Realm realmClass = _getInstance(name); if(realmClass == null) { realmClass = doInstantiate(name, className, props); RealmsManager mgr = getRealmsManager(); mgr.putIntoLoadedRealms(name, realmClass); } return realmClass; }
/** * Compares a realm to another. The comparison first considers the * authentication type, so that realms supporting the same kind of * user authentication are grouped together. Then it compares realm * realm names. Realms compare "before" other kinds of objects (i.e. * there's only a partial order defined, in the case that those other * objects compare themselves "before" a realm object). */ public int compareTo (Object realm) { if (!(realm instanceof Realm)) { return 1; } Realm r = (Realm) realm; String str = r.getAuthType (); int temp; if ((temp = getAuthType ().compareTo (str)) != 0) { return temp; } str = r.getName (); return getName ().compareTo (str); }
/** * Convenience method which returns the Realm object representing * the current default realm. Equivalent to * getInstance(getDefaultRealm()). * * @return Realm representing default realm. * @exception NoSuchRealmException if default realm does not exist */ public static synchronized Realm getDefaultInstance() throws NoSuchRealmException { return getInstance(getDefaultRealm()); }
public static void refreshRealm(String configName, String realmName) { if (realmName != null && realmName.length() > 0) { try { Realm realm = Realm.getInstance(configName, realmName); if (realm != null) { realm.refresh(configName); } } catch (com.sun.enterprise.security.auth.realm.NoSuchRealmException nre) { // _logger.fine("Realm: "+realmName+" is not configured"); } catch (com.sun.enterprise.security.auth.realm.BadRealmException bre) { // _logger.fine("Realm: "+realmName+" is not configured"); } } } static void handleAdminGroup(String lr, List<String> lg) {
props.setProperty(realmProp.getName(), realmProp.getValue()); Realm.instantiate(realmName, realmClass, props, configName); if (logger.isLoggable(Level.FINE)) { logger.fine("Configured realm: " + realmName); Realm.getInstance(defaultRealm); } catch (Exception e) { defaultRealm = goodRealm; Realm.setDefaultRealm(defaultRealm); if (logger.isLoggable(Level.FINE)) { logger.fine("Default realm is set to: " + defaultRealm);
throws LoginException { if(realmName == null || !(Realm.isValidRealm(realmName))){ realmName = Realm.getDefaultRealm(); jaasCtx = Realm.getInstance(realmName).getJAASContext(); } catch(Exception ex) { if( ex instanceof LoginException )
String jaasCtx = null; try { jaasCtx = Realm.getInstance(asrtCred.getRealmName()).getJAASContext(); } catch (Exception ex) { if (ex instanceof LoginException) {
/** * Replace a Realm instance. Can be used by a Realm subclass to * replace a previously initialized instance of itself. Future * getInstance requests will then obtain the new instance. * * <P>Minimal error checking is done. The realm being replaced must * already exist (instantiate() was previously called), the new * instance must be fully initialized properly and it must of course * be of the same class as the previous instance. * * @param realm The new realm instance. * @param name The (previously instantiated) name for this realm. * */ protected static synchronized void updateInstance(String configName, Realm realm, String name) { RealmsManager mgr = getRealmsManager(); if (mgr == null) { throw new RuntimeException("Unable to locate RealmsManager Service"); } Realm oldRealm = mgr.getFromLoadedRealms(configName, name); if (!oldRealm.getClass().equals(realm.getClass())) { // would never happen unless bug in realm subclass throw new Error("Incompatible class " + realm.getClass() + " in replacement realm " + name); } realm.setName(oldRealm.getName()); mgr.putIntoLoadedRealms(configName, name, realm); _logger.log(Level.INFO, SecurityLoggerInfo.realmUpdated, new Object[]{realm.getName()}); }
/** * Returns the realm with which this user is associated * * @return Realm name. * @exception NoSuchRealmException if the realm associated this user * no longer exist * */ @Override public Realm getRealm() throws NoSuchRealmException { return Realm.getInstance(realm); }
RealmsManager mgr = null; try { mgr = getRealmsManager(); Class realmClass = null; r.setName(name); r.init(props); if (mgr == null) { throw new BadRealmException("Unable to locate RealmsManager Service");
Realm realm = Realm.getInstance(CertificateRealm.AUTH_TYPE); realm_name = realm.getName(); setSecurityContext(user, s, realm_name);
if(_getInstance(realmName) != null) { throw new BadRealmException( localStrings.getLocalString("realm.already_exists", assert (classname != null); return doInstantiate(realmName, classname, props); } catch (IOException e) { throw new BadRealmException(e.toString());
/** * Remove realm with given name from cache. * @param realmName * @exception NoSuchRealmException */ public static synchronized void unloadInstance(String realmName) throws NoSuchRealmException { //make sure instance exist getInstance(realmName); RealmsManager mgr = getRealmsManager(); if (mgr != null) { mgr.removeFromLoadedRealms(realmName); } else { throw new RuntimeException("Unable to locate RealmsManager Service"); } _logger.log(Level.INFO, "Realm " + realmName + " successfully deleted."); }
/** * This method is just a convenience wrapper for * <i>login(Subject, Class)</i> method. It will construct a * PasswordCredential class. * * @param String username * @param String password * @param String realmName the name of the realm to login into, if realmName * is null, we login into the default realm */ public static void login(String username, char[] password, String realmName){ if(realmName == null || !(Realm.isValidRealm(realmName))){ realmName = Realm.getDefaultRealm(); } final Subject fs = new Subject(); final PasswordCredential pc = new PasswordCredential(username, password, realmName); AppservAccessController.doPrivileged(new PrivilegedAction(){ public java.lang.Object run(){ fs.getPrivateCredentials().add(pc); return fs; } }); LoginContextDriver.login(fs, PasswordCredential.class); }
protected Enumeration getGroups(String username) { try { return this.getRealm().getGroupNames(username); } catch (InvalidOperationException ex) { Logger.getLogger("global").log(Level.SEVERE, null, ex); } catch (NoSuchUserException ex) { Logger.getLogger("global").log(Level.SEVERE, null, ex); } return null; } }
/** * This method will create or replace existing realm with a new one * in cache. * @param event * @exception for instance, BadRealmException, ConfigException, * SynchronizationException */ private static void createRealm(AuthRealm authRealm) throws Exception { //authRealm cannot be null here String className = authRealm.getClassname(); List<Property> elementProps = authRealm.getProperty(); Properties props = new Properties(); if (elementProps != null) { for (Property p : elementProps) { props.setProperty(p.getName(), p.getValue()); } } Realm.instantiate(authRealm.getName(), className, props); Configuration.getConfiguration().refresh(); }
byte[] _realm = null; if (target_name == null || target_name.length == 0) { _realm = Realm.getDefaultRealm().getBytes(); } else { _realm = GSSUtils.importName(GSSUtils.GSSUP_MECH_OID, target_name);
/** * Returns the realm identified by the name which is passed * as a parameter. This function knows about all the realms * which exist; it is not possible to store (or create) one * which is not accessible through this routine. * * @param name identifies the realm * @return the requested realm * @exception NoSuchRealmException if the realm is invalid * @exception BadRealmException if realm data structures are bad */ public static synchronized Realm getInstance(String configName, String name) throws NoSuchRealmException { Realm retval = _getInstance(configName, name); if (retval == null) { throw new NoSuchRealmException( localStrings.getLocalString("realm.no_such_realm", name + " realm does not exist.", new Object[] { name })); } return retval; }