⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginremoteapp.java

📁 Java 3D Desktop Environment旨在使用Java 3D来创建一个3D桌面环境。功能包括:分布式的应用程序
💻 JAVA
字号:
package org.j3de.application.login;
 
import java.io.IOException;      
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.rmi.RemoteException;

import javax.vecmath.Point3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

import javax.security.auth.Subject;import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.TextOutputCallback; 
import javax.security.auth.callback.UnsupportedCallbackException;

import org.j3de.exception.ExceptionHandler;import org.j3de.events.WaitForAction;import org.j3de.interfaces.Application;
import org.j3de.interfaces.ApplicationEnvironment;
import org.j3de.security.UserInfo;
import org.j3de.security.SystemSecurity;
import org.j3de.security.ConfigPrincipal;import org.j3de.server.EnvironmentWrapper;import org.j3de.ui.ActionElement;
import org.j3de.ui.Border3D;
import org.j3de.ui.Label3D;
import org.j3de.ui.PasswordField3D;
import org.j3de.ui.TextField3D;
import org.j3de.ui.UIContainer;
import org.j3de.ui.UICreationException;
import org.j3de.ui.UIElement;
import org.j3de.ui.UIFactory;
import org.j3de.ui.skin.SkinShapeButton;
import org.j3de.ui.skin.SkinLayoutManagerList;
import org.j3de.ui.skin.SkinLayoutManagerUnconstrained;
import org.j3de.util.ConfigurationException;
public class LoginRemoteApp implements Application {  
  private ApplicationEnvironment environment;
  private UIFactory              uiFactory;
  private SystemSecurity         systemSecurity;
  
  private UIContainer      loginScreen;  
  private UIContainer      loginContainer;
  private TextField3D      login;
  private PasswordField3D  password;
  private Label3D          label;
  private WaitForAction    waitForAction;
  private ActionElement    action;
  private UIElement        button;
  
  public LoginRemoteApp(ApplicationEnvironment environment, SystemSecurity systemSecurity) throws RemoteException { 
    this.environment = environment;
    this.uiFactory   = environment.getUIFactory();                                       
    this.systemSecurity = systemSecurity;
  }
  
  public void run() {
    while (true) {      UserInfo userInfo = systemSecurity.login(getCallBackHandler());
            try {          Subject subject = userInfo.getSubject();                ConfigPrincipal configPrincipal =           (ConfigPrincipal)subject.getPrincipals(ConfigPrincipal.class).iterator().next();              EnvironmentWrapper environmentWrapper =           (EnvironmentWrapper)configPrincipal.getConfiguration().getHelper().getComponent("userEnvironment");        environment.startModalEnvironment(environmentWrapper.getLocalEnvironment().getEnvironment());      } catch (ConfigurationException e) {        ExceptionHandler.handleException(e);      } catch (RemoteException e) {        ExceptionHandler.handleException(e);      } catch (Exception e) {        ExceptionHandler.handleException(e);      }            systemSecurity.logout(userInfo);    }  }
    
  public CallbackHandler getCallBackHandler() {
    return new CallbackHandler() {
      public void handle(Callback[] callbacks) throws java.io.IOException, UnsupportedCallbackException {
        
        for (int i = 0; i < callbacks.length; i++) {     
          
   
          if (callbacks[i] instanceof TextOutputCallback) {
      
              // display the message according to the specified type
              TextOutputCallback toc = (TextOutputCallback)callbacks[i];
              switch (toc.getMessageType()) {
              case TextOutputCallback.INFORMATION:
                  break;
              case TextOutputCallback.ERROR:
                  break;
              case TextOutputCallback.WARNING:
                  break;
              default:
                  throw new IOException("Unsupported message type: " +
                                      toc.getMessageType());
              }

          } else if (callbacks[i] instanceof NameCallback) {
              // prompt the user for a username  
                            
              NameCallback nc = (NameCallback)callbacks[i];
              
              try {
                loginContainer = uiFactory.createContainer();
                loginScreen    = uiFactory.createContainer();
              
                label          = uiFactory.createLabel3D(nc.getPrompt());  
                login          = uiFactory.createTextField3D();
                label.setLabeledElement(login);

                button         = uiFactory.loadShape(SkinShapeButton.class);
                action         = uiFactory.createActionElement();
                
                action.setUIElement(button);        
                
                waitForAction = new WaitForAction();
                action.addActionListener(waitForAction);
                
	            	loginScreen.setLayoutManager(SkinLayoutManagerUnconstrained.class);
		            loginScreen.add(label);
                loginScreen.add(login);  

                loginContainer.setLayoutManager(SkinLayoutManagerList.class);
                loginContainer.add(loginScreen);
                loginContainer.add(action);  
                      
              } catch (UICreationException e) { 
                throw new IOException("Cannot create UI : " + e.getMessage());
              }
              
              environment.setRootUIElement(loginContainer);

              boolean buttonPressed = waitForAction.waitForAction(0);
              environment.setRootUIElement(null);
              
              if (buttonPressed) {
                nc.setName(login.getText());   
              } else
                throw new IOException("No Username entered");
                            
          } else if (callbacks[i] instanceof PasswordCallback) {
              
              // prompt the user for sensitive information
              PasswordCallback pc = (PasswordCallback)callbacks[i];
              try {
                loginContainer = uiFactory.createContainer();
                loginScreen    = uiFactory.createContainer();
              
                label          = uiFactory.createLabel3D(pc.getPrompt());  
                password       = uiFactory.createPasswordField3D();
                label.setLabeledElement(password);

                button         = uiFactory.loadShape(SkinShapeButton.class);
                action         = uiFactory.createActionElement();
                
                action.setUIElement(button);        
                
                waitForAction = new WaitForAction();
                action.addActionListener(waitForAction);
                
                loginScreen.setLayoutManager(SkinLayoutManagerUnconstrained.class);
                loginScreen.add(label);
                loginScreen.add(password);  

                loginContainer.setLayoutManager(SkinLayoutManagerList.class);
                loginContainer.add(loginScreen);
                loginContainer.add(action);  
                      
              } catch (UICreationException e) { 
                throw new IOException("Cannot create UI : " + e.getMessage());
              }
              
              environment.setRootUIElement(loginContainer);
              boolean buttonPressed = waitForAction.waitForAction(0);
              environment.setRootUIElement(null);
             
              if (buttonPressed) {
                pc.setPassword(password.getPassword());   
              } else
                throw new IOException("No Password entered");
                            
              System.err.print(pc.getPrompt());
              System.err.flush(); 
              char[] pwd = {'t', 'e', 's', 't'};
              pc.setPassword(pwd);
          } else {
              throw new UnsupportedCallbackException
                      (callbacks[i], "Unrecognized Callback");
          }
        }
      }
    };
  } 
  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -