当前位置: 首页>>代码示例>>Java>>正文


Java UserAuth类代码示例

本文整理汇总了Java中org.apache.sshd.server.auth.UserAuth的典型用法代码示例。如果您正苦于以下问题:Java UserAuth类的具体用法?Java UserAuth怎么用?Java UserAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UserAuth类属于org.apache.sshd.server.auth包,在下文中一共展示了UserAuth类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import org.apache.sshd.server.auth.UserAuth; //导入依赖的package包/类
public static SshServer create() {

        SshServer sshd = SshServer.setUpDefaultServer();
        sshd.setPort(SpashConfig.getInstance().spashListenPort());

        AbstractGeneratorHostKeyProvider keyProvider = new SimpleGeneratorHostKeyProvider(new File(SpashConfig.getInstance().spashKeyFileName()));
        keyProvider.setAlgorithm(SpashConfig.getInstance().spashKeyAlgorithm());
        keyProvider.setKeySize(SpashConfig.getInstance().spashKeyLength());

        sshd.setKeyPairProvider(keyProvider);

        List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
        userAuthFactories.add(new UserAuthPasswordFactory());
        sshd.setUserAuthFactories(userAuthFactories);

        sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
            @Override
            public boolean authenticate(String username, String password, ServerSession serverSession) throws PasswordChangeRequiredException {
                return username!=null && username.length()>0 && username.equals(password);
            }
        });

        sshd.setShellFactory(new SpashShellFactory());

        List<NamedFactory<Command>> namedFactoryList = new ArrayList<>();
        namedFactoryList.add(new SftpSubsystemFactory());
        sshd.setSubsystemFactories(namedFactoryList);

        sshd.setCommandFactory(new ScpCommandFactory());

        sshd.setFileSystemFactory(new FileSystemFactory() {
            @Override
            public FileSystem createFileSystem(Session session) throws IOException {
                return SpashFileSystem.get().getFileSystem();
            }
        });

        return sshd;
    }
 
开发者ID:nerdammer,项目名称:spash,代码行数:40,代码来源:SshServerFactory.java

示例2: AsyncUserAuthService

import org.apache.sshd.server.auth.UserAuth; //导入依赖的package包/类
public AsyncUserAuthService(Session s) throws SshException {
    ValidateUtils.checkTrue(s instanceof ServerSession, "Server side service used on client side");
    if (s.isAuthenticated()) {
        throw new SshException("Session already authenticated");
    }

    this.session = (ServerSession) s;
    maxAuthRequests = session.getIntProperty(ServerFactoryManager.MAX_AUTH_REQUESTS, DEFAULT_MAX_AUTH_REQUESTS);

    ServerFactoryManager manager = getFactoryManager();
    userAuthFactories = new ArrayList<>(manager.getUserAuthFactories());
    // Get authentication methods
    authMethods = new ArrayList<>();

    String mths = FactoryManagerUtils.getString(manager, ServerFactoryManager.AUTH_METHODS);
    if (GenericUtils.isEmpty(mths)) {
        for (NamedFactory<UserAuth> uaf : manager.getUserAuthFactories()) {
            authMethods.add(new ArrayList<>(Collections.singletonList(uaf.getName())));
        }
    }
    else {
        for (String mthl : mths.split("\\s")) {
            authMethods.add(new ArrayList<>(Arrays.asList(mthl.split(","))));
        }
    }
    // Verify all required methods are supported
    for (List<String> l : authMethods) {
        for (String m : l) {
            NamedFactory<UserAuth> factory = NamedResource.Utils.findByName(m, String.CASE_INSENSITIVE_ORDER, userAuthFactories);
            if (factory == null) {
                throw new SshException("Configured method is not supported: " + m);
            }
        }
    }

    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine("Authorized authentication methods: "+ NamedResource.Utils.getNames(userAuthFactories));
    }
}
 
开发者ID:aeshell,项目名称:aesh-readline,代码行数:40,代码来源:AsyncUserAuthService.java

示例3: initUserAuth

import org.apache.sshd.server.auth.UserAuth; //导入依赖的package包/类
private void initUserAuth(
    final PublickeyAuthenticator pubkey,
    final GSSAuthenticator kerberosAuthenticator,
    String kerberosKeytab,
    String kerberosPrincipal) {
  List<NamedFactory<UserAuth>> authFactories = new ArrayList<>();
  if (kerberosKeytab != null) {
    authFactories.add(UserAuthGSSFactory.INSTANCE);
    log.info("Enabling kerberos with keytab " + kerberosKeytab);
    if (!new File(kerberosKeytab).canRead()) {
      sshDaemonLog.error(
          "Keytab "
              + kerberosKeytab
              + " does not exist or is not readable; further errors are possible");
    }
    kerberosAuthenticator.setKeytabFile(kerberosKeytab);
    if (kerberosPrincipal == null) {
      try {
        kerberosPrincipal = "host/" + InetAddress.getLocalHost().getCanonicalHostName();
      } catch (UnknownHostException e) {
        kerberosPrincipal = "host/localhost";
      }
    }
    sshDaemonLog.info("Using kerberos principal " + kerberosPrincipal);
    if (!kerberosPrincipal.startsWith("host/")) {
      sshDaemonLog.warn(
          "Host principal does not start with host/ "
              + "which most SSH clients will supply automatically");
    }
    kerberosAuthenticator.setServicePrincipalName(kerberosPrincipal);
    setGSSAuthenticator(kerberosAuthenticator);
  }
  authFactories.add(UserAuthPublicKeyFactory.INSTANCE);
  setUserAuthFactories(authFactories);
  setPublickeyAuthenticator(pubkey);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:37,代码来源:SshDaemon.java

示例4: ApacheSSHDServer

import org.apache.sshd.server.auth.UserAuth; //导入依赖的package包/类
private ApacheSSHDServer() {
		sshd = SshServer.setUpDefaultServer();
		LOG.info("Starting SSHd Server");
		port = ConfigurationHelper.getIntSystemThenEnvProperty("heliosapm.sshd.port", 0);
		sshd.setPort(port);
		sshd.setHost("0.0.0.0");
		//LOG.info("Listening Port [" + port + "]");
		Provider provider = new BouncyCastleProvider();
		Security.addProvider(provider);
		List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
		
		userAuthFactories.add(new UserAuthPasswordFactory());		
		userAuthFactories.add(new UserAuthPublicKeyFactory());
		//sshd.setUserAuthFactories(userAuthFactories);
		
		final File hostKeySerFile = new File(new File(System.getProperty("java.io.tmpdir")),"hostkey-" + System.currentTimeMillis() + ".ser");
		hostKeySerFile.deleteOnExit();
		//final SimpleGeneratorHostKeyProvider hostKeyProvider = new SimpleGeneratorHostKeyProvider(hostKeySerFile);
		final AbstractGeneratorHostKeyProvider hostKeyProvider = SecurityUtils.createGeneratorHostKeyProvider(hostKeySerFile.toPath());
		hostKeyProvider.setAlgorithm("RSA");
		sshd.setKeyPairProvider(hostKeyProvider);
//		sshd.setPasswordAuthenticator(NO_AUTH);
//		sshd.setPublickeyAuthenticator(NO_KEY_AUTH);
		sshd.setPasswordAuthenticator(PW_AUTH);
		sshd.setPublickeyAuthenticator(KEY_AUTH);
		
        sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
        
//		sshd.setPasswordAuthenticator(new PropFilePasswordAuthenticator("./src/test/resources/auth/password/credentials.properties"));
//		sshd.setPublickeyAuthenticator(new KeyDirectoryPublickeyAuthenticator("./src/test/resources/auth/keys"));
		
		
		
		if (System.getProperty("os.name").toLowerCase().contains("windows")) {
			boolean useBash = false;
			if(System.getenv().containsKey("Path")) {
				for(String pathEntry: System.getenv().get("Path").split(";")) {
					File bashFile = new File(pathEntry + File.separator + "bash.exe");
					if(bashFile.exists() && bashFile.canExecute()) {
						useBash = true;
						break;
					}
				}
			}
			if(useBash) {
				LOG.info("shell is bash");
				sshd.setShellFactory(new ProcessShellFactory(new String[] { "bash.exe", "-i", "-l"})); //EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr)
			} else {
				LOG.info("shell is cmd");
				sshd.setShellFactory(new ProcessShellFactory(new String[] { "cmd.exe"})); // EnumSet.of(ProcessShellFactory.TtyOptions.Echo, ProcessShellFactory.TtyOptions.ICrNl, ProcessShellFactory.TtyOptions.ONlCr)
			}
			
		} else {
			sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-l" })); //EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr)
		}
		
		try {
			sshd.start();
			port = sshd.getPort();
			System.setProperty("heliosapm.sshd.port", "" + port);
			LOG.info("Server started on port [" + sshd.getPort() + "]");			
		} catch (Exception e) {
			LOG.error("Failed to start SSHD server", e);
			try { sshd.stop(true); } catch (Exception x) {/* No Op */}
			instance = null;
		}
		
	}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:69,代码来源:ApacheSSHDServer.java

示例5: create

import org.apache.sshd.server.auth.UserAuth; //导入依赖的package包/类
@Override
public UserAuth create() {
    return new MockedGSSAuth(users);
}
 
开发者ID:intropro,项目名称:prairie,代码行数:5,代码来源:MockedGSSAuthFactory.java

示例6: AsyncUserAuthService

import org.apache.sshd.server.auth.UserAuth; //导入依赖的package包/类
public AsyncUserAuthService(Session s) throws SshException {
  ValidateUtils.checkTrue(s instanceof ServerSession, "Server side service used on client side");
  if (s.isAuthenticated()) {
    throw new SshException("Session already authenticated");
  }

  serverSession = (ServerSession) s;
  maxAuthRequests = PropertyResolverUtils.getIntProperty(s, ServerAuthenticationManager.MAX_AUTH_REQUESTS, ServerAuthenticationManager.DEFAULT_MAX_AUTH_REQUESTS);

  List<NamedFactory<UserAuth>> factories = ValidateUtils.checkNotNullAndNotEmpty(
      serverSession.getUserAuthFactories(), "No user auth factories for %s", s);
  userAuthFactories = new ArrayList<>(factories);
  // Get authentication methods
  authMethods = new ArrayList<>();

  String mths = PropertyResolverUtils.getString(s, ServerFactoryManager.AUTH_METHODS);
  if (GenericUtils.isEmpty(mths)) {
    for (NamedFactory<UserAuth> uaf : factories) {
      authMethods.add(new ArrayList<>(Collections.singletonList(uaf.getName())));
    }
  } else {
    if (log.isDebugEnabled()) {
      log.debug("ServerUserAuthService({}) using configured methods={}", s, mths);
    }
    for (String mthl : mths.split("\\s")) {
      authMethods.add(new ArrayList<>(Arrays.asList(GenericUtils.split(mthl, ','))));
    }
  }
  // Verify all required methods are supported
  for (List<String> l : authMethods) {
    for (String m : l) {
      NamedFactory<UserAuth> factory = NamedResource.Utils.findByName(m, String.CASE_INSENSITIVE_ORDER, userAuthFactories);
      if (factory == null) {
        throw new SshException("Configured method is not supported: " + m);
      }
    }
  }

  if (log.isDebugEnabled()) {
    log.debug("ServerUserAuthService({}) authorized authentication methods: {}",
        s, NamedResource.Utils.getNames(userAuthFactories));
  }
}
 
开发者ID:termd,项目名称:termd,代码行数:44,代码来源:AsyncUserAuthService.java


注:本文中的org.apache.sshd.server.auth.UserAuth类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。