Package anvil.server

Examples of anvil.server.Realm


  {
    if (!_prefs.getRequired()) {
      return true;
    }

    Realm realm = getRealm();
    if (realm == null) {
      context.log().error("Couldn't get realm named '"+_prefs.getRealm()+"'");
      try {
        String contentType = MimeTypes.guessContentType(context.getRequest());
        Templates.message(context, contentType, 500);
      } catch(IOException e) {
        context.log().error("Error while writing '500 Internal Server Error' response", e);
      }
      return false;
    }
   
    String auth = context.getRequest().getHeader("Authorization");
    context.log().info("basic: Authorization="+auth);
    boolean authenticated = false;
    if ((auth != null) && (auth.length()>0)) {
      int i = auth.indexOf(' ');
      if (i > -1) {
        String authType = auth.substring(0, i);
        String authCode = auth.substring(i + 1);
        String decoded = new String(new sun.misc.BASE64Decoder().decodeBuffer(authCode));
        i = decoded.indexOf(':');
        if (i > -1) {
          String username = decoded.substring(0, i);
          String password = decoded.substring(i + 1);
          Citizen citizen = context.getCitizen();
          if (citizen != null) {
            if (!citizen.getRealm().equals(realm)) {
              citizen = null;
            } else if (!citizen.getName().equals(username)) {
              citizen = null;
            }
          }
          if (citizen == null) {
            context.log().info("basic: login="+username);
            citizen = realm.getCitizen(username);
          }
          if (citizen != null) {
            if (citizen.verifyCredentials(password)) {
              context.setCitizen(citizen);
              context.log().info("basic: authentication ok");
View Full Code Here


  /// @synopsis Realm getRealm() ;
  /// @synopsis Realm getRealm(string name)
  public static final Object[] p_getRealm = { null, "*name", null };
  public Any m_getRealm(Context context, String name)
  {
    Realm realm = null;
    if (_conf.getType() == Configurable.REALM) {
      RealmPreferences rp = (RealmPreferences)_conf;
      realm = _conf.getParent().getRealm(rp.getName());
     
    } else if (_conf instanceof Zone) {
View Full Code Here

  {
    if (!_prefs.getRequired()) {
      return true;
    }

    Realm realm = getRealm();
    Session session = context.getSession();
   
    if (realm == null) {
      context.log().error("Couldn't get realm named '"+_prefs.getRealm()+"'");
      try {
        String contentType = MimeTypes.guessContentType(context.getRequest());
        Templates.message(context, contentType, 500);
      } catch(IOException e) {
        context.log().error("Error while writing '500 Internal Server Error' response", e);
      }
      return false;
    }
   
    if (session == null) {
      //cannot authorize if there's no session
     
      return false;
    }
   
    String citizenName = session.getCitizen();
    Citizen citizen = null;

    if (citizenName != null) {
      citizen = realm.getCitizen(citizenName);
    }
   
    if (citizen != null && citizen.getRealm().equals(realm)) {
      return true;
   
    } else {
      HttpServletRequest request = context.getRequest();

      String clientIp = request.getRemoteAddr();
      context.log().info("client ip: "+clientIp);
      Citizen[] searchResult = realm.searchCitizenByVariable("ctz.ip", clientIp);
      if (searchResult != null && searchResult.length > 0) {
        context.setCitizen(searchResult[0]);
        context.log().info("web: ipauthentication ok");
       
        if (context.getOriginalPathinfo().equals(loginPath)) {
          throw new RedirectException(context.getSession().getId(), forwardPath);
        }
        return true;
      }

      String username = request.getParameter("webauth.username");
      String password = request.getParameter("webauth.password");
     
      context.getSession().removeAttribute("webauth.failedUser");
     
      if (username != null && password != null && username.length() > 0) {
        citizen = realm.getCitizen(username);
        context.log().info("username: '"+username+"' citizen: "+citizen);
        if (citizen != null && citizen.verifyCredentials(password)) {
          context.setCitizen(citizen);
          context.log().info("web: authentication ok");
         
View Full Code Here

    }
    if (name == null) {
      return UNDEFINED;
    }
    context.checkRealm(name);
    Realm realm = zone.getRealm(name);
    if (realm != null) {
      return new AnyRealm(realm);
    }
    return UNDEFINED;
  }
View Full Code Here

    Zone zone = _context.getZone();
    AccessPreferences access = zone.getAccessPreferences();
    if (access != null) {
      String realmName = access.getRealm();
      context.checkRealm(realmName);
      Realm realm = zone.getRealm(realmName);
      if (realm != null) {
        Citizen citizen = realm.getCitizen(name);
        if (citizen != null) {
          if (credentials != null) {     
            if (citizen.verifyCredentials(credentials)) {
              return new AnyCitizen(citizen);
            }
View Full Code Here

    Zone zone = _context.getZone();
    AccessPreferences access = zone.getAccessPreferences();
    if (access != null) {
      String realmName = access.getRealm();
      context.checkRealm(realmName);
      Realm realm = zone.getRealm(realmName);
      if (realm != null) {
        Tribe tribe = realm.getTribe(name);
        if (tribe != null) {
          return new AnyTribe(tribe);
        }
      }
    }
View Full Code Here

TOP

Related Classes of anvil.server.Realm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.