@Test public void testFromCurrentSubject() { final String username = "username"; final String password = "********"; final String hostName = "host"; final BackendNodePrincipal principal = mock(BackendNodePrincipal.class); when(principal.getUsername()).thenReturn(username); when(principal.getHostname()).thenReturn(hostName); final BackendNodePasswordCredential credential = mock(BackendNodePasswordCredential.class); when(credential.getPassword()).thenReturn(password); mockStatic(JaasUtils.class); when(JaasUtils.getPrincipal(BackendNodePrincipal.class)).thenReturn(principal); when(JaasUtils.getPrivateCredential(BackendNodePasswordCredential.class)).thenReturn(credential); final UserPassBuilder builder = mock(UserPassBuilder.class); when(builder.setServerAddress(URI.create(hostName))).thenReturn(builder); when(builder.setPassword(password)).thenReturn(builder); when(builder.setUsername(username)).thenReturn(builder); mockStatic(UserPassBuilder.class); when(UserPassBuilder.getBuilder()).thenReturn(builder); final UserPassProduct product = mock(UserPassProduct.class); when(builder.build()).thenReturn(product); assertThat(AuthHelper.fromCurrentSubject()).isEqualTo(product); verify(builder).setPassword(password); verify(builder).setServerAddress(URI.create(hostName)); verify(builder).setUsername(username); }
public static FtpProduct fromCurrentSubject() { final BackendNodePrincipal principal = JaasUtils.getPrincipal(BackendNodePrincipal.class); final BackendNodePasswordCredential credential = JaasUtils .getPrivateCredential(BackendNodePasswordCredential.class); if (JaasUtils.hasPrincipal(PrivateKeyPrincipal.class)) { PrivateKeyPrincipal keyPrincipal = JaasUtils.getPrincipal(PrivateKeyPrincipal.class); return KeyCryptoBuilder.getBuilder().setKeySalt(credential.getPassword()) .setPrivateKey(URI.create(keyPrincipal.getName())) .setServerAddress(URI.create(principal.getHostname())).setUsername(principal.getUsername()).build(); } return UserPassBuilder.getBuilder().setServerAddress(URI.create(principal.getHostname())) .setUsername(principal.getUsername()).setPassword(credential.getPassword()).build(); }
AuthHelper { public static FtpProduct fromCurrentSubject() { final BackendNodePrincipal principal = JaasUtils.getPrincipal(BackendNodePrincipal.class); final BackendNodePasswordCredential credential = JaasUtils .getPrivateCredential(BackendNodePasswordCredential.class); if (JaasUtils.hasPrincipal(PrivateKeyPrincipal.class)) { PrivateKeyPrincipal keyPrincipal = JaasUtils.getPrincipal(PrivateKeyPrincipal.class); return KeyCryptoBuilder.getBuilder().setKeySalt(credential.getPassword()) .setPrivateKey(URI.create(keyPrincipal.getName())) .setServerAddress(URI.create(principal.getHostname())).setUsername(principal.getUsername()).build(); } return UserPassBuilder.getBuilder().setServerAddress(URI.create(principal.getHostname())) .setUsername(principal.getUsername()).setPassword(credential.getPassword()).build(); } }
AuthHelper { public static FtpProduct fromCurrentSubject() { final BackendNodePrincipal principal = JaasUtils.getPrincipal(BackendNodePrincipal.class); final BackendNodePasswordCredential credential = JaasUtils .getPrivateCredential(BackendNodePasswordCredential.class); if (JaasUtils.hasPrincipal(PrivateKeyPrincipal.class)) { PrivateKeyPrincipal keyPrincipal = JaasUtils.getPrincipal(PrivateKeyPrincipal.class); return KeyCryptoBuilder.getBuilder().setKeySalt(credential.getPassword()) .setPrivateKey(URI.create(keyPrincipal.getName())) .setServerAddress(URI.create(principal.getHostname())).setUsername(principal.getUsername()).build(); } return UserPassBuilder.getBuilder().setServerAddress(URI.create(principal.getHostname())) .setUsername(principal.getUsername()).setPassword(credential.getPassword()).build(); } private  AuthHelper(); }
AuthHelper { public static FtpProduct fromCurrentSubject() { final BackendNodePrincipal principal = JaasUtils.getPrincipal(BackendNodePrincipal.class); final BackendNodePasswordCredential credential = JaasUtils .getPrivateCredential(BackendNodePasswordCredential.class); if (JaasUtils.hasPrincipal(PrivateKeyPrincipal.class)) { PrivateKeyPrincipal keyPrincipal = JaasUtils.getPrincipal(PrivateKeyPrincipal.class); return KeyCryptoBuilder.getBuilder().setKeySalt(credential.getPassword()) .setPrivateKey(URI.create(keyPrincipal.getName())) .setServerAddress(URI.create(principal.getHostname())).setUsername(principal.getUsername()).build(); } return UserPassBuilder.getBuilder().setServerAddress(URI.create(principal.getHostname())) .setUsername(principal.getUsername()).setPassword(credential.getPassword()).build(); } private  AuthHelper(); static FtpProduct fromCurrentSubject(); }
AuthHelper { public static FtpProduct fromCurrentSubject() { final BackendNodePrincipal principal = JaasUtils.getPrincipal(BackendNodePrincipal.class); final BackendNodePasswordCredential credential = JaasUtils .getPrivateCredential(BackendNodePasswordCredential.class); if (JaasUtils.hasPrincipal(PrivateKeyPrincipal.class)) { PrivateKeyPrincipal keyPrincipal = JaasUtils.getPrincipal(PrivateKeyPrincipal.class); return KeyCryptoBuilder.getBuilder().setKeySalt(credential.getPassword()) .setPrivateKey(URI.create(keyPrincipal.getName())) .setServerAddress(URI.create(principal.getHostname())).setUsername(principal.getUsername()).build(); } return UserPassBuilder.getBuilder().setServerAddress(URI.create(principal.getHostname())) .setUsername(principal.getUsername()).setPassword(credential.getPassword()).build(); } private  AuthHelper(); static FtpProduct fromCurrentSubject();  }