001package edu.pdx.cs410J.security;
002
003import java.security.*;
004
005/**
006 * This class represents a game console that can play many games.
007 */
008public class GameConsolePriv extends GameConsole {
009
010  /**
011   * Note use of doPrivileged.  This says that we trust this code.
012   */
013  public boolean writePreferences(final Game game, 
014                                  final String prefs) {
015    Boolean b =
016      (Boolean) AccessController.doPrivileged(new PrivilegedAction() {
017          public Object run() {
018            boolean b = 
019              GameConsolePriv.super.writePreferences(game, prefs);
020            return new Boolean(b);
021          }
022        });
023    return b.booleanValue();
024  }
025
026  public String readPreferences(final Game game) {
027    String prefs = 
028      (String) AccessController.doPrivileged(new PrivilegedAction() {
029          public Object run() {
030            return GameConsolePriv.super.readPreferences(game);
031          }
032        });
033                                             
034    return prefs;
035  }
036
037
038  /**
039   * The command line contains the name of the game and a URL from
040   * where to load it.
041   */
042  public static void main(String[] args) {
043    String gameName = args[0];
044    String gameURL = args[1];
045
046    GameConsole console = new GameConsolePriv();
047
048    Game game = null;
049    try {
050      game = console.loadGame(gameName, gameURL);
051
052    } catch (Exception ex) {
053      System.err.println("** Could not load game " + gameName + 
054                         " from " + gameURL);
055      System.err.println("** " + ex);
056      ex.printStackTrace(System.err);
057      System.exit(1);
058    }
059
060    game.play(console);
061  }
062}