mirror of
https://github.com/LamGC/Oracle-Sentry.git
synced 2025-04-30 06:37:42 +00:00
fix: 通过 Constants 类获取首次认证策略类型.
通过 Constants 类获取首次认证策略类型, 以修复类型无法获取的问题.
This commit is contained in:
parent
3287a139d0
commit
12d32737f2
28
src/main/java/net/lamgc/oracle/sentry/Constants.java
Normal file
28
src/main/java/net/lamgc/oracle/sentry/Constants.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package net.lamgc.oracle.sentry;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author LamGC
|
||||||
|
*/
|
||||||
|
@Component("sentry.constants")
|
||||||
|
public final class Constants {
|
||||||
|
|
||||||
|
public static Constants instance;
|
||||||
|
|
||||||
|
private Constants() {
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Value("${oracle.ssh.firstConnection.authenticationPolicy}")
|
||||||
|
@NonNull
|
||||||
|
private String firstConnectionPolicy;
|
||||||
|
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public String getFirstConnectionPolicy() {
|
||||||
|
return firstConnectionPolicy;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package net.lamgc.oracle.sentry.oci.compute.ssh;
|
package net.lamgc.oracle.sentry.oci.compute.ssh;
|
||||||
|
|
||||||
|
import net.lamgc.oracle.sentry.Constants;
|
||||||
import net.lamgc.oracle.sentry.oci.compute.ComputeInstance;
|
import net.lamgc.oracle.sentry.oci.compute.ComputeInstance;
|
||||||
import org.apache.sshd.client.keyverifier.RequiredServerKeyVerifier;
|
import org.apache.sshd.client.keyverifier.RequiredServerKeyVerifier;
|
||||||
import org.apache.sshd.client.keyverifier.ServerKeyVerifier;
|
import org.apache.sshd.client.keyverifier.ServerKeyVerifier;
|
||||||
@ -7,8 +8,6 @@ import org.apache.sshd.client.session.ClientSession;
|
|||||||
import org.apache.sshd.common.config.keys.KeyUtils;
|
import org.apache.sshd.common.config.keys.KeyUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.lang.NonNull;
|
|
||||||
|
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
@ -21,10 +20,6 @@ public class OracleInstanceServerKeyVerifier implements ServerKeyVerifier {
|
|||||||
|
|
||||||
private final static Logger log = LoggerFactory.getLogger(OracleInstanceServerKeyVerifier.class);
|
private final static Logger log = LoggerFactory.getLogger(OracleInstanceServerKeyVerifier.class);
|
||||||
|
|
||||||
@Value("${oracle.ssh.firstConnection.authenticationPolicy}")
|
|
||||||
@NonNull
|
|
||||||
private static String firstConnectionPolicy;
|
|
||||||
|
|
||||||
private final ComputeInstance instance;
|
private final ComputeInstance instance;
|
||||||
private final SshAuthInfo info;
|
private final SshAuthInfo info;
|
||||||
|
|
||||||
@ -53,11 +48,12 @@ public class OracleInstanceServerKeyVerifier implements ServerKeyVerifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean usePolicyConfirm(SocketAddress address, PublicKey serverKey) {
|
private boolean usePolicyConfirm(SocketAddress address, PublicKey serverKey) {
|
||||||
|
String policyName = Constants.instance.getFirstConnectionPolicy().toUpperCase();
|
||||||
FirstConnectionPolicy policy;
|
FirstConnectionPolicy policy;
|
||||||
try {
|
try {
|
||||||
policy = FirstConnectionPolicy.valueOf(firstConnectionPolicy.toUpperCase());
|
policy = FirstConnectionPolicy.valueOf(policyName);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IllegalArgumentException("Unsupported policy: " + firstConnectionPolicy);
|
throw new IllegalArgumentException("Unsupported policy: " + policyName);
|
||||||
}
|
}
|
||||||
return policy.confirmFunction.confirm(this.instance, address, serverKey);
|
return policy.confirmFunction.confirm(this.instance, address, serverKey);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user