if (!(s instanceof ServerSession)) {
throw new IllegalStateException("Server side service used on client side");
}
this.session = (ServerSession) s;
if (session.isAuthenticated()) {
throw new SshException("Session already authenticated");
}
maxAuthRequests = session.getIntProperty(ServerFactoryManager.MAX_AUTH_REQUESTS, maxAuthRequests);
userAuthFactories = new ArrayList<NamedFactory<UserAuth>>(getFactoryManager().getUserAuthFactories());
// Get authentication methods
authMethods = new ArrayList<List<String>>();
String mths = getFactoryManager().getProperties().get(SshServer.AUTH_METHODS);
if (mths == null) {
for (NamedFactory<UserAuth> uaf : getFactoryManager().getUserAuthFactories()) {
authMethods.add(new ArrayList<String>(Collections.singletonList(uaf.getName())));
}
} else {
for (String mthl : mths.split("\\s")) {
authMethods.add(new ArrayList<String>(Arrays.asList(mthl.split(","))));
}
}
// Verify all required methods are supported
for (List<String> l : authMethods) {
for (String m : l) {
if (NamedFactory.Utils.get(userAuthFactories, m) == null) {
throw new SshException("Configured method is not supported: " + m);
}
}
}
log.debug("Authorized authentication methods: {}", NamedFactory.Utils.getNames(userAuthFactories));
}