Search in sources :

Example 1 with Builder

use of org.opendaylight.netconf.callhome.protocol.CallHomeAuthorization.Builder in project netconf by opendaylight.

the class CallHomeAuthProviderImpl method provideAuth.

@Override
public CallHomeAuthorization provideAuth(final SocketAddress remoteAddress, final PublicKey serverKey) {
    Device deviceSpecific = deviceConfig.get(serverKey);
    String sessionName;
    Credentials deviceCred;
    if (deviceSpecific != null) {
        sessionName = deviceSpecific.getUniqueId();
        if (deviceSpecific.getTransport() instanceof Ssh) {
            final SshClientParams clientParams = ((Ssh) deviceSpecific.getTransport()).getSshClientParams();
            deviceCred = clientParams.getCredentials();
        } else {
            deviceCred = deviceSpecific.getCredentials();
        }
    } else {
        String syntheticId = fromRemoteAddress(remoteAddress);
        if (globalConfig.allowedUnknownKeys()) {
            sessionName = syntheticId;
            deviceCred = null;
            statusReporter.asForceListedDevice(syntheticId, serverKey);
        } else {
            Device opDevice = deviceOp.get(serverKey);
            if (opDevice == null) {
                statusReporter.asUnlistedDevice(syntheticId, serverKey);
            } else {
                LOG.info("Repeating rejection of unlisted device with id of {}", opDevice.getUniqueId());
            }
            return CallHomeAuthorization.rejected();
        }
    }
    final Credentials credentials = deviceCred != null ? deviceCred : globalConfig.getCredentials();
    if (credentials == null) {
        LOG.info("No credentials found for {}, rejecting.", remoteAddress);
        return CallHomeAuthorization.rejected();
    }
    Builder authBuilder = CallHomeAuthorization.serverAccepted(sessionName, credentials.getUsername());
    for (String password : credentials.getPasswords()) {
        authBuilder.addPassword(password);
    }
    return authBuilder.build();
}
Also used : SshClientParams(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams) Device(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device) Builder(org.opendaylight.netconf.callhome.protocol.CallHomeAuthorization.Builder) Ssh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh) Credentials(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.credentials.Credentials)

Aggregations

Builder (org.opendaylight.netconf.callhome.protocol.CallHomeAuthorization.Builder)1 Credentials (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.credentials.Credentials)1 Device (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device)1 Ssh (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh)1 SshClientParams (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams)1