Trying to scroll a JComponent with JScrollPane but can't do it. :(

Hi, what im trying to do seems to be simple but I gave up after trying the whole day and I beg you guys help.
I created a JComponent that is my map ( the map consists only in squared cells ). but the map might be too big for the screen, so I want to be able to scroll it. If the map is smaller than the screen,
everything works perfect, i just add the map to the frame container and it shows perfect. But if I add the map to the ScrollPane and them add the ScrollPane to the container, it doesnt work.
below is the code for both classes Map and the MainWindow. Thanks in advance
package main;
import java.awt.Color;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
public class MainWindow implements WindowStateListener {
     private JFrame frame;
     private static MainWindow instance = null;
     private MenuBar menu;
     public Map map = new Map();
     public JScrollPane Scroller =
          new JScrollPane( map,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
     public JViewport viewport = new JViewport();
     private MainWindow(int width, int height) {
          frame = new JFrame("Editor de Cen�rios v1.0");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(width,height);
          frame.setVisible(true);
          menu = MenuBar.createMenuBar();
          JFrame.setDefaultLookAndFeelDecorated(false);
          frame.setJMenuBar(menu.create());
          frame.setBackground(Color.WHITE);
          frame.getContentPane().setBackground(Color.WHITE);
                                // HERE IS THE PROBLEM, THIS DOESNT WORKS   <---------------------------------------------------------------------------------------
          frame.getContentPane().add(Scroller);
          frame.addWindowStateListener(this);
public static MainWindow createMainWindow(int width, int height)
     if(instance == null)
          instance = new MainWindow(width,height);
          return instance;               
     else
          return instance;
public static MainWindow returnMainWindow()
     return instance;
public static void main(String[] args) {
     MainWindow mWindow = createMainWindow(800,600);
public JFrame getFrame() {
     return frame;
public Map getMap(){
     return map;
@Override
public void windowStateChanged(WindowEvent arg0) {
     map.repaint();
package main;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
import javax.swing.Scrollable;
public class Map extends JComponent  implements Scrollable{
     private Cell [] mapCells;
     private String mapPixels;
     private String mapAltura;
     private String mapLargura;
     public void createMap(String pixels , String altura, String largura)
          mapPixels = pixels;
          mapAltura = altura;
          mapLargura = largura;
          int cells = Integer.parseInt(altura) * Integer.parseInt(largura);
          mapCells = new Cell[cells];
          //MainWindow.returnMainWindow().getFrame().getContentPane().add(this);
          Graphics2D grafico = (Graphics2D)getGraphics();
          for(int i=0, horiz = 0 , vert = 0; i < mapCells.length; i++)
               mapCells[i] = new Cell( horiz, vert,Integer.parseInt(mapPixels));
               MainWindow.returnMainWindow().getFrame().getContentPane().add(mapCells);
               grafico.draw(mapCells[i].r);
               horiz = horiz + Integer.parseInt(mapPixels);
               if(horiz == Integer.parseInt(mapLargura)*Integer.parseInt(mapPixels))
                    horiz = 0;
                    vert = vert + Integer.parseInt(mapPixels);
          repaint();
     @Override
     protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          System.out.println("entrou");
          Graphics2D g2d = (Graphics2D)g;
          if(mapCells !=null)
               for(int i=0, horiz = 0 , vert = 0; i < mapCells.length; i++)
                    g2d.draw(mapCells[i].r);
                    horiz = horiz + Integer.parseInt(mapPixels);
                    if(horiz == Integer.parseInt(mapLargura)*Integer.parseInt(mapPixels))
                         horiz = 0;
                         vert = vert + Integer.parseInt(mapPixels);
     @Override
     public Dimension getPreferredScrollableViewportSize() {
          return super.getPreferredSize();
     @Override
     public int getScrollableBlockIncrement(Rectangle visibleRect,
               int orientation, int direction) {
          // TODO Auto-generated method stub
          return 5;
     @Override
     public boolean getScrollableTracksViewportHeight() {
          // TODO Auto-generated method stub
          return false;
     @Override
     public boolean getScrollableTracksViewportWidth() {
          // TODO Auto-generated method stub
          return false;
     @Override
     public int getScrollableUnitIncrement(Rectangle visibleRect,
               int orientation, int direction) {
          // TODO Auto-generated method stub
          return 5;

Im so sorry Darryl here are the other 3 classes
package main;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;
public class MenuActions {
     public void newMap(){
          final JTextField pixels = new JTextField(10);
          final JTextField hCells = new JTextField(10);
          final JTextField wCells = new JTextField(10);
          JButton btnOk = new JButton("OK");
          final JFrame frame = new JFrame("Escolher dimens�es do mapa");
          frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(),BoxLayout.Y_AXIS));
          btnOk.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
          String txtPixels = pixels.getText();
          String hTxtCells = hCells.getText();
          String wTxtCells = wCells.getText();
          frame.dispose();
          MainWindow.returnMainWindow().map.createMap(txtPixels,hTxtCells,wTxtCells);         
          frame.getContentPane().add(new JLabel("N�mero de pixels em cada c�lula:"));
          frame.getContentPane().add(pixels);
          frame.getContentPane().add(new JLabel("Altura do mapa (em c�lulas):"));
          frame.getContentPane().add(hCells);
          frame.getContentPane().add(new JLabel("Largura do mapa (em c�lulas):"));
          frame.getContentPane().add(wCells);
          frame.getContentPane().add(btnOk);
          frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          frame.setSize(300, 165);
          frame.setResizable(false);
         frame.setVisible(true);
     public Map openMap (){
          //Abre somente arquivos XML
          JFileChooser fc = new JFileChooser();
          FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml" );
          fc.addChoosableFileFilter(filter);
          fc.showOpenDialog(MainWindow.returnMainWindow().getFrame());
          //TO DO: manipular o mapa aberto
          return new Map();          
     public void save(){
     public void saveAs(){
          //Abre somente arquivos XML
          JFileChooser fc = new JFileChooser();
          FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml" );
          fc.addChoosableFileFilter(filter);
          fc.showSaveDialog(MainWindow.returnMainWindow().getFrame());
          //TO DO: Salvar o mapa aberto
     public void exit(){
          System.exit(0);          
     public void copy(){
     public void paste(){
package main;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
public class MenuBar implements ActionListener{
     private JMenuBar menuBar;
     private final Color color = new Color(250,255,245);
     private String []menuNames = {"Arquivo","Editar"};
     private JMenu []menus = new JMenu[menuNames.length];
     private String []arquivoMenuItemNames = {"Novo","Abrir", "Salvar","Salvar Como...","Sair" };
     private KeyStroke []arquivoMenuItemHotkeys = {KeyStroke.getKeyStroke(KeyEvent.VK_N,ActionEvent.CTRL_MASK),
                                                              KeyStroke.getKeyStroke(KeyEvent.VK_A,ActionEvent.CTRL_MASK),
                                                              KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK),
                                                              KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.SHIFT_MASK),
                                                              KeyStroke.getKeyStroke(KeyEvent.VK_F4,ActionEvent.ALT_MASK)};
     private JMenuItem []arquivoMenuItens = new JMenuItem[arquivoMenuItemNames.length];
     private String []editarMenuItemNames = {"Copiar","Colar"};
     private KeyStroke []editarMenuItemHotKeys = {KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK),
                                                             KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK)};
     private JMenuItem[]editarMenuItens = new JMenuItem[editarMenuItemNames.length];
     private static MenuBar instance = null;
     public JMenuItem lastAction;
     private MenuBar()
     public static MenuBar createMenuBar()
          if(instance == null)
               instance = new MenuBar();
               return instance;                    
          else
               return instance;
     public JMenuBar create()
          //cria a barra de menu
          menuBar = new JMenuBar();
          //adiciona items a barra de menu
          for(int i=0; i < menuNames.length ; i++)
               menus[i] = new JMenu(menuNames);
               menuBar.add(menus[i]);
          //seta a hotkey da barra como F10
          menus[0].setMnemonic(KeyEvent.VK_F10);
          //adiciona items ao menu arquivo
          for(int i=0; i < arquivoMenuItemNames.length ; i++)
               arquivoMenuItens[i] = new JMenuItem(arquivoMenuItemNames[i]);
               arquivoMenuItens[i].setAccelerator(arquivoMenuItemHotkeys[i]);
               menus[0].add(arquivoMenuItens[i]);
               arquivoMenuItens[i].setBackground(color);
               arquivoMenuItens[i].addActionListener(this);
          //adiciona items ao menu editar
          for(int i=0; i < editarMenuItemNames.length ; i++)
               editarMenuItens[i] = new JMenuItem(editarMenuItemNames[i]);
               editarMenuItens[i].setAccelerator(editarMenuItemHotKeys[i]);
               menus[1].add(editarMenuItens[i]);
               editarMenuItens[i].setBackground(color);
               editarMenuItens[i].addActionListener(this);
          menuBar.setBackground(color);
          return menuBar;                    
     @Override
     public void actionPerformed(ActionEvent e) {
          lastAction = (JMenuItem) e.getSource();
          MenuActions action = new MenuActions();
          if(lastAction.getText().equals("Novo"))
               action.newMap();
          else if(lastAction.getText().equals("Abrir"))
               action.openMap();
          else if(lastAction.getText().equals("Salvar"))
               action.save();               
          else if(lastAction.getText().equals("Salvar Como..."))
               action.saveAs();               
          else if(lastAction.getText().equals("Sair"))
               action.exit();               
          else if(lastAction.getText().equals("Copiar"))
               action.copy();               
          else if(lastAction.getText().equals("Colar"))
               action.paste();               
package main;
import java.awt.geom.Rectangle2D;
import javax.swing.JComponent;
public class Cell extends JComponent{
     public float presSub = 0;
     public double errPressInfer = 0.02;
     public double errPressSup = 0.02;
     public float profundidade = 1;
     public Rectangle2D r ;
     public Cell(double x, double y, double pixel)
          r = new Rectangle2D.Double(x,y,pixel,pixel);          
Edited by: xnunes on May 3, 2008 6:26 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Trying to install Lightroom 5 with CC but getting error code 5 on initial startup of Lightroom.

    Trying to install Lightroom 5 with CC but getting error code 5 on initial startup of Lightroom. Have uninstalled all adobe products including Creative Cloud CC.
    Followed the instructions on the forum by using the CC Cleaner App for OSX. Have restarted a number of times and even tried using disk utility to fix any permission probs. Still no luck.
    The problem started happening from upgrading the previous version of Lightroom to the most up to date version. Im hoping someone can help me with any ideas. Thanks heaps.

    Ended up fixing the problem after finding no answers. Deleted the following file
    com.adobe.acc.AdobeCreativeCloud.plist

  • Trying to sync outlook 2011 with iCal but iCal only sees Entourage cal.

    Trying to sync outlook 2011 with iCal but iCal only sees Entourage calendar.  I have selected sync in outlook 2011 and it is correctly syncing with address book. I have installed sp1.   Do i need to delete entourage cal from iCal?

    This is a forum for the MacBook Pro hardware.  As a suggestion, repost your question in the iCal forum, where questions about iCal will be quickly answered. 

  • Trying to activate newly installed Acrobat 11 but can't access internet thru program - can otherwise get online with no probs

    trying to activate newly installed Acrobat 11 but can't access internet thru program - can otherwise get online with no probs. any suggestions?

    Hey Marina Hannwacker,
    I would recommend you to Refer this link - Offline Activation and let me know if it works for you.
    Regards,
    Rahul Tyagi

  • I am trying to download photoshop presets from online but can't seem to figure out how to open them in photoshop. They download sucessfuly and then goes to my download folder on my computer, from there I double click on the file and photoshop opens and th

    I am trying to download photoshop presets from online but can't seem to figure out how to open them in photoshop. They download sucessfuly and then goes to my download folder on my computer, from there I double click on the file and photoshop opens and then nothing happens, any ideas? I am using a PC

    This video is a great step by step tutorial.
    Photoshop: How to Download & Install New Brushes & other Presets - YouTube
    Gene

  • I have a 3G iphone. I just tried to download the new itunes and lost all my itunes I had.  I tried to transfer them from my computer but can't. How can I and what do I do to get the ones I bought before and now have lost.

    I have a 3G iphone. I just tried to download the new itunes and lost all my itunes I had.  I tried to transfer them from my computer but can't. How can I and what do I do to get the ones I bought before and now have lost.

    It has always been very basic to always maintain a backup copy of your computer.
    Use your backup copy to put everything back.
    If for some reason you have failed to maintain a backup ( not good), then you can transfer itunes purchases from an ipod/iphone/ipad:  File>Transfer Purchases

  • Trying to print e-mails using iCloud but can not add my printer Epson Stylus Photo PX810FW Why not?r

    Trying to print e-mails using iCloud but can not add my printer Epson Stylus Photo PX810FW
    Why not?

    Trying to print e-mails using iCloud but can not add my printer Epson Stylus Photo PX810FW
    Why not?

  • TS3276 I can send emails with Mail but can no longer receive them. Yet I haven't altered anything.  How do I solve this problem. Thanks

    I can send emails with Mail but can no longer receive them. Yet I haven't altered anything.  How do I solve this problem. Thanks

    Who is your email provider? Have you set up your account manually or was it set up automatically?

  • Tried for many times to buy fcpx but can't?

    hi
    tried for many times to buy fcpx but can't?
    prasad

    We need more information to help you. (We, users, in this group.)
    At the Apple Store, did you submit your Apple ID / PW successfully?
    What happened after that?
    Are you trying to upgrade from a trial version?
    What kind of messages are you getting?
    Basically, take us through, step-by-step, what happened when you go to buy the software from the Apple Store.
    There's also a chance that you paid for the app, and it's waiting for you to download.

  • Trying to find the Walgreen's app but can't find it

    I am trying to find the Walgreen's app but can't find it in the search box. 

    I tried several searches but no returns for the App at the Mac App Store.
    Perhaps there is one in the works ...
    If by chance you have an Android smartphone, there's a Walgreens app available  >   http://www.walgreens.com/topic/apps/learn_about_mobile_apps.jsp
    You're welcome

  • Trying to fill out an online form but can't click on anything

    Trying to fill out an online form but can't click on anyhting

    Quit your browser then relaunch and try again.

  • I'm trying to use kerberos V5 with ActiveDirectory but get an error

    I'm trying to use kerberos V5 with ActiveDirectory im using simple code from previuos posts but
    when i try with correct username/password i get :
    Authentication attempt failedjavax.security.auth.login.LoginException: Message stream modified (41)
    when i try incorrect username/pass i get :
    Pre-authentication information was invalid (24)
    Debug info is :
    Debug is  true storeKey false useTicketCache false useKeyTab false doNotPrompt false ticketCache is null isInitiator true KeyTab is null refreshKrb5Config is false principal is null tryFirstPass is false useFirstPass is false storePass is false clearPass is false
    Kerberos username [naiden]: naiden
    Kerberos password for naiden:      naiden
              [Krb5LoginModule] user entered username: naiden
    Acquire TGT using AS Exchange
              [Krb5LoginModule] authentication failed
    Pre-authentication information was invalid (24)
    Authentication attempt failedjavax.security.auth.login.LoginException: Java code is :
    import javax.naming.*;
    import javax.naming.directory.*;
    import javax.security.auth.login.*;
    import javax.security.auth.Subject;
    import com.sun.security.auth.callback.TextCallbackHandler;
    import java.util.Hashtable;
    * Demonstrates how to create an initial context to an LDAP server
    * using "GSSAPI" SASL authentication (Kerberos v5).
    * Requires J2SE 1.4, or JNDI 1.2 with ldapbp.jar, JAAS, JCE, an RFC 2853
    * compliant implementation of J-GSS and a Kerberos v5 implementation.
    * Jaas.conf
    * racfldap.GssExample {com.sun.security.auth.module.Krb5LoginModule required client=TRUE useTicketCache=true doNotPrompt=true; };
    * 'qop' is a comma separated list of tokens, each of which is one of
    * auth, auth-int, or auth-conf. If none is supplied, the default is 'auth'.
    class KerberosExample {
    public static void main(String[] args) {
    java.util.Properties p = new java.util.Properties(System.getProperties());
    p.setProperty("java.security.krb5.realm", "ISY");
    p.setProperty("java.security.krb5.kdc", "192.168.0.101");
    p.setProperty("java.security.auth.login.config", "C:\\jaas.conf");
    System.setProperties(p);
    // 1. Log in (to Kerberos)
    LoginContext lc = null;
    try {
    lc = new LoginContext("ISY",
    new TextCallbackHandler());
    // Attempt authentication
    lc.login();
    } catch (LoginException le) {
    System.err.println("Authentication attempt failed" + le);
    System.exit(-1);
    // 2. Perform JNDI work as logged in subject
    Subject.doAs(lc.getSubject(), new LDAPAction(args));
    // 3. Perform LDAP Action
    * The application must supply a PrivilegedAction that is to be run
    * inside a Subject.doAs() or Subject.doAsPrivileged().
    class LDAPAction implements java.security.PrivilegedAction {
    private String[] args;
    private static String[] sAttrIDs;
    private static String sUserAccount = new String("Administrator");
    public LDAPAction(String[] origArgs) {
    this.args = (String[])origArgs.clone();
    public Object run() {
    performLDAPOperation(args);
    return null;
    private static void performLDAPOperation(String[] args) {
    // Set up environment for creating initial context
    Hashtable env = new Hashtable(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.ldap.LdapCtxFactory");
    // Must use fully qualified hostname
    env.put(Context.PROVIDER_URL, "ldap://192.168.0.101:389/DC=isy,DC=local");
    // Request the use of the "GSSAPI" SASL mechanism
    // Authenticate by using already established Kerberos credentials
    env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI");
    env.put("javax.security.sasl.server.authentication", "true");
    try {
    /* Create initial context */
    DirContext ctx = new InitialDirContext(env);
    /* Get the attributes requested */
    Attributes aAnswer =ctx.getAttributes( "CN="+ sUserAccount + ",CN=Users,DC=isy,DC=local");
    NamingEnumeration enumUserInfo = aAnswer.getAll();
    while(enumUserInfo.hasMoreElements()) {
    System.out.println(enumUserInfo.nextElement().toString());
    // Close the context when we're done
    ctx.close();
    } catch (NamingException e) {
    e.printStackTrace();
    }JAAS conf file is :
    ISY {
         com.sun.security.auth.module.Krb5LoginModule required
    debug=true;
    };krb5.ini file is :
    # Kerberos 5 Configuration File
    # All available options are specified in the Kerberos System Administrator's Guide.  Very
    # few are used here.
    # Determines which Kerberos realm a machine should be in, given its domain name.  This is
    # especially important when obtaining AFS tokens - in afsdcell.ini in the Windows directory
    # there should be an entry for your AFS cell name, followed by a list of IP addresses, and,
    # after a # symbol, the name of the server corresponding to each IP address.
    [libdefaults]
         default_realm = ISY
    [domain_realm]
         .isy.local = ISY
         isy.local = ISY
    # Specifies all the server information for each realm.
    #[realms]
         ISY=
              kdc = 192.168.0.101
              admin_server = 192.168.0.101
              default_domain = ISY
         }

    Now it works
    i will try to explain how i do this :
    step 1 )
    fallow this guide http://www.cit.cornell.edu/computer/system/win2000/kerberos/
    and configure AD to use kerberos and to heve Kerberos REALM
    step 2 ) try windows login to the new realm to be sure that it works ADD trusted realm if needed.
    step 3 ) create jaas.conf file for example in c:\
    it looks like this :
    ISY {
         com.sun.security.auth.module.Krb5LoginModule required
    debug=true;
    };step 4)
    ( dont forget to make mappings which are explained in step 1 ) go to Active Directory users make sure from View to check Advanced Features Right click on the user go to mappings in secound tab kerberos mapping add USERNAME@KERBEROSreaLm for example [email protected]
    step 5)
    copy+paste this code and HIT RUN :)
    import java.util.Hashtable;
    import javax.naming.Context;
    import javax.naming.NamingEnumeration;
    import javax.naming.NamingException;
    import javax.naming.directory.Attributes;
    import javax.naming.directory.DirContext;
    import javax.naming.directory.InitialDirContext;
    import javax.naming.directory.SearchControls;
    import javax.naming.directory.SearchResult;
    import javax.security.auth.Subject;
    import javax.security.auth.login.LoginContext;
    import javax.security.auth.login.LoginException;
    import com.sun.security.auth.callback.TextCallbackHandler;
    public class Main {
        public static void main(String[] args) {
        java.util.Properties p = new java.util.Properties(System.getProperties());
        p.setProperty("java.security.krb5.realm", "ISY.LOCAL");
        p.setProperty("java.security.krb5.kdc", "192.168.0.101");
        p.setProperty("java.security.auth.login.config", "C:\\jaas.conf");
        System.setProperties(p);
        // 1. Log in (to Kerberos)
        LoginContext lc = null;
        try {
                lc = new LoginContext("ISY", new TextCallbackHandler());
        // Attempt authentication
        lc.login();
        } catch (LoginException le) {
        System.err.println("Authentication attempt failed" + le);
        System.exit(-1);
        // 2. Perform JNDI work as logged in subject
        Subject.doAs(lc.getSubject(), new LDAPAction(args));
        // 3. Perform LDAP Action
        * The application must supply a PrivilegedAction that is to be run
        * inside a Subject.doAs() or Subject.doAsPrivileged().
        class LDAPAction implements java.security.PrivilegedAction {
        private String[] args;
        private static String[] sAttrIDs;
        private static String sUserAccount = new String("Administrator");
        public LDAPAction(String[] origArgs) {
        this.args = origArgs.clone();
        public Object run() {
        performLDAPOperation(args);
        return null;
        private static void performLDAPOperation(String[] args) {
        // Set up environment for creating initial context
        Hashtable env = new Hashtable(11);
        env.put(Context.INITIAL_CONTEXT_FACTORY,
        "com.sun.jndi.ldap.LdapCtxFactory");
        // Must use fully qualified hostname
        env.put(Context.PROVIDER_URL, "ldap://192.168.0.101:389");
        // Request the use of the "GSSAPI" SASL mechanism
        // Authenticate by using already established Kerberos credentials
        env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI");
    //    env.put("javax.security.sasl.server.authentication", "true");
        try {
        /* Create initial context */
        DirContext ctx = new InitialDirContext(env);
        /* Get the attributes requested */
        //Create the search controls        
        SearchControls searchCtls = new SearchControls();
        //Specify the attributes to return
        String returnedAtts[]={"sn","givenName","mail"};
        searchCtls.setReturningAttributes(returnedAtts);
        //Specify the search scope
        searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        //specify the LDAP search filter
        String searchFilter = "(&(objectClass=user)(mail=*))";
        //Specify the Base for the search
        String searchBase = "DC=isy,DC=local";
        //initialize counter to total the results
        int totalResults = 0;
        // Search for objects using the filter
        NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);
        //Loop through the search results
        while (answer.hasMoreElements()) {
                SearchResult sr = (SearchResult)answer.next();
            totalResults++;
            System.out.println(">>>" + sr.getName());
            // Print out some of the attributes, catch the exception if the attributes have no values
            Attributes attrs = sr.getAttributes();
            if (attrs != null) {
                try {
                System.out.println("   surname: " + attrs.get("sn").get());
                System.out.println("   firstname: " + attrs.get("givenName").get());
                System.out.println("   mail: " + attrs.get("mail").get());
                catch (NullPointerException e)    {
                System.err.println("Error listing attributes: " + e);
        System.out.println("RABOTIII");
            System.out.println("Total results: " + totalResults);
        ctx.close();
        } catch (NamingException e) {
        e.printStackTrace();
    }It will ask for username and password
    type for example : [email protected] for username
    and password : TheSecretPassword
    where ISY.LOCAL is the name of kerberos realm.
    p.s. it is not good idea to use Administrator as login :)
    Edited by: JOKe on Sep 14, 2007 2:23 PM

  • HT4311 Hi, I am trying to use my phone in Japan. It is a PAYG phone purchased directly from the Apple web store currently with Vodafone. Have tried to purchase a sim in Japan but can not do. Help please! I feel as if I have wasted my money! Bought 5 iPads

    Hi again,
    I have purchased 5 iPads and 1 iPhone 4S in the UK thinking if I invest in an Apple top of the range I am covered worldwide for usage. Apparently not!
    Got the phone as a PAYG and use with vodaphone, but got it direct from Apple.
    Any help to buy a microchip from Japan would be much appreciated.
    I feel as if I have wasted my money.
    David

    Hi @imobl,
    You sound like an Apple support guy who hasn't been able to answer my questions.
    To respond to some of the points you made,
    - I did not ignore Ocean20's suggestion. If you has read my post, you would have known that I took my phone to the apple service centre where they tried this restore on THEIR machines. I am assuming that Apple guys know how not to block iTunes. So I actually do not understand your point about me trying the hosts file changes on my machine. Do you not believe that apple tested this issue with the correct settings?
    - you also give a flawed logic of why the issue is a hardware issue. You mentioned that If I thought that the issue was with the software, i should try a restore and getting it to work. The problem is that my error (23), and many others comes up when the restore fails. And you would be astonished to know that not all errors are hardware errors. Sometimes even software errors prevent restores. Funnily enough Apple itself mention that 'in rare cases, error 23 could be hardware related'.
    - all Apple has done so far is replicate the issue. I don not know how anyone can conclude that the issue is a hardware issue.
    And by the way, I am not certain that this is a software bug. Again if you read my Posts, you will notice I only want a confirmation,/proof that the issue is hardware related as they mention..
    Please refrain do. Responding if there is nothing to add.

  • Trying to extend my network with express but it times out

    Trying to extend my network with an airport express, but everytime I follow the instructions it prompts me to "switch" networks and then it times out.

    What is the make & model of the wireless router that you are trying to extend with the 802.11n AirPort Express Base Station (AXn)?

  • Trying to verify my email with iCloud but never get the  email it's the same address that I use for apple so whats the problem, Ray

    Trying to verify icloud on my macbook, but I never get the email. It's the same address and password I use to order from apple, so what am I doing wrong.  Ray

    Make sure you are checking the email address you used to set up your iCloud account.  Check the spam/junk folder as well as the inbox.  If it isn't there, go to https://appleid.apple.com, click Manage your Apple ID, sign in, click on Name, ID and Email addresses on the left, then to the right click Resend under your Primary Email Address to resend the verification email.

Maybe you are looking for