Ejemplo n.º 1
0
 public void init(File jsonFile) throws StorageException {
   try {
     JsonConfig config = new JsonConfig(jsonFile);
     homeDir = new File(config.get("storage/file-system/home", DEFAULT_HOME_DIR));
     if (!homeDir.exists()) {
       homeDir.mkdirs();
     }
   } catch (IOException ioe) {
     throw new StorageException(ioe);
   }
 }
  /** Basic constructor, should be run automatically by Tapestry. */
  public PortalSecurityManagerImpl() throws IOException {
    // Get system configuration
    JsonConfigHelper config = new JsonConfigHelper(JsonConfig.getSystemFile());

    // For all SSO providers configured
    sso = new LinkedHashMap();
    List<Object> ssoProviders = config.getList("sso/plugins");
    for (Object ssoId : ssoProviders) {
      // Instantiate from the ServiceLoader
      SSOInterface valid = getSSOProvider((String) ssoId);
      if (valid == null) {
        log.error("Invalid SSO Implementation requested: '{}'", (String) ssoId);
      } else {
        // Store valid implementations
        sso.put((String) ssoId, valid);
        log.info("SSO Provider instantiated: '{}'", ssoId);
      }
    }

    defaultPortal = config.get("portal/defaultView", PortalManager.DEFAULT_PORTAL_NAME);
    serverUrlBase = config.get("urlBase");
    ssoLoginUrl = serverUrlBase + defaultPortal + SSO_LOGIN_PAGE;

    // Get exclusions Strings from config
    excStarts = castList(config.getList("sso/urlExclusions/startsWith"));
    excEnds = castList(config.getList("sso/urlExclusions/endsWith"));
    excEquals = castList(config.getList("sso/urlExclusions/equals"));

    // Trust tokens
    Map<String, JsonConfigHelper> tokenMap = config.getJsonMap("sso/trustTokens");
    tokens = new HashMap();
    tokenExpiry = new HashMap();
    for (String key : tokenMap.keySet()) {
      String publicKey = tokenMap.get(key).get("publicKey");
      String privateKey = tokenMap.get(key).get("privateKey");
      String expiry = tokenMap.get(key).get("expiry", TRUST_TOKEN_EXPIRY);
      if (publicKey != null && privateKey != null) {
        // Valid key
        tokens.put(publicKey, privateKey);
        tokenExpiry.put(publicKey, Long.valueOf(expiry));
      } else {
        log.error("Invalid token data: '{}'", key);
      }
    }
  }