Java Code Examples for org.apache.sshd.common.util.ValidateUtils#checkTrue()
The following examples show how to use
org.apache.sshd.common.util.ValidateUtils#checkTrue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From termd with Apache License 2.0 | 5 votes |
public static KeyPair getFirstKeyPair(KeyIdentityProvider provider) { ValidateUtils.checkNotNull(provider, "No key pair provider"); Iterable<? extends KeyPair> pairs = ValidateUtils.checkNotNull(provider.loadKeys(), "No loaded keys"); Iterator<? extends KeyPair> iter = ValidateUtils.checkNotNull(pairs.iterator(), "No keys iterator"); ValidateUtils.checkTrue(iter.hasNext(), "Empty loaded kyes iterator"); return ValidateUtils.checkNotNull(iter.next(), "No key pair in iterator"); }
Example 2
Source File: AsyncUserAuthService.java From aesh-readline with Apache License 2.0 | 5 votes |
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)); } }
Example 3
Source File: Utils.java From termd with Apache License 2.0 | 5 votes |
public static KeyPair getFirstKeyPair(KeyIdentityProvider provider) { ValidateUtils.checkNotNull(provider, "No key pair provider"); Iterable<? extends KeyPair> pairs = ValidateUtils.checkNotNull(provider.loadKeys(), "No loaded keys"); Iterator<? extends KeyPair> iter = ValidateUtils.checkNotNull(pairs.iterator(), "No keys iterator"); ValidateUtils.checkTrue(iter.hasNext(), "Empty loaded kyes iterator"); return ValidateUtils.checkNotNull(iter.next(), "No key pair in iterator"); }
Example 4
Source File: AsyncUserAuthService.java From termd with Apache License 2.0 | 4 votes |
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<NamedFactory<UserAuth>>(factories); // Get authentication methods authMethods = new ArrayList<List<String>>(); String mths = PropertyResolverUtils.getString(s, ServerFactoryManager.AUTH_METHODS); if (GenericUtils.isEmpty(mths)) { for (NamedFactory<UserAuth> uaf : factories) { authMethods.add(new ArrayList<String>(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<String>(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)); } }
Example 5
Source File: AsyncUserAuthService.java From termd with Apache License 2.0 | 4 votes |
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)); } }