Best Citrus code snippet using com.consol.citrus.ws.security.User.User
Source:SshServer.java
...63 */64public class SshServer extends AbstractServer {65 /** Port to listen to **/66 private int port = 22;67 /** User allowed to connect **/68 private String user;69 /** User's password or ... **/70 private String password;71 /** ... path to its public key72 Use this to convert to PEM: ssh-keygen -f key.pub -e -m pem **/73 private String allowedKeyPath;74 /* Path to our own host keys. If not provided, a default is used. The format of this75 file should be PEM, a serialized {@link java.security.KeyPair}. **/76 private String hostKeyPath;77 /** User home directory path **/78 private String userHomePath;79 /** Ssh message converter **/80 private SshMessageConverter messageConverter = new SshMessageConverter();81 /** SSH server used **/82 private org.apache.sshd.server.SshServer sshd;83 /** This servers endpoint configuration */84 private final SshEndpointConfiguration endpointConfiguration;85 /**86 * Default constructor using default endpoint configuration.87 */88 public SshServer() {89 this(new SshEndpointConfiguration());90 }91 /**92 * Constructor using endpoint configuration.93 * @param endpointConfiguration94 */95 public SshServer(SshEndpointConfiguration endpointConfiguration) {96 this.endpointConfiguration = endpointConfiguration;97 }98 @Override99 protected void startup() {100 if (!StringUtils.hasText(user)) {101 throw new CitrusRuntimeException("No 'user' provided (mandatory for authentication)");102 }103 sshd = org.apache.sshd.server.SshServer.setUpDefaultServer();104 sshd.setPort(port);105 VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory();106 Path userHomeDir = Optional.ofNullable(userHomePath).map(Paths::get).map(Path::toAbsolutePath).orElse(Paths.get(String.format("target/%s/home/%s", getName(), user)).toAbsolutePath());107 if (!Files.exists(userHomeDir)) {108 try {109 Files.createDirectories(userHomeDir);110 } catch (IOException e) {111 throw new CitrusRuntimeException("Failed to setup user home dir", e);112 }113 }114 fileSystemFactory.setUserHomeDir(user, userHomeDir);115 sshd.setFileSystemFactory(fileSystemFactory);116 if (hostKeyPath != null) {117 Resource hostKey = FileUtils.getFileResource(hostKeyPath);118 if (hostKey instanceof ClassPathResource) {119 ClassLoadableResourceKeyPairProvider resourceKeyPairProvider = new ClassLoadableResourceKeyPairProvider(Collections.singletonList(((ClassPathResource) hostKey).getPath()));120 sshd.setKeyPairProvider(resourceKeyPairProvider);121 } else {122 try {123 FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(Collections.singletonList(hostKey.getFile().toPath()));124 sshd.setKeyPairProvider(fileKeyPairProvider);125 } catch (IOException e) {126 throw new CitrusRuntimeException("Failed to read host key path", e);127 }128 }129 } else {130 ClassLoadableResourceKeyPairProvider resourceKeyPairProvider = new ClassLoadableResourceKeyPairProvider(Collections.singletonList("com/consol/citrus/ssh/citrus.pem"));131 sshd.setKeyPairProvider(resourceKeyPairProvider);132 }133 // Authentication134 boolean authFound = false;135 if (password != null) {136 sshd.setPasswordAuthenticator(new SimplePasswordAuthenticator(user, password));137 authFound = true;138 }139 if (allowedKeyPath != null) {140 sshd.setPublickeyAuthenticator(new SinglePublicKeyAuthenticator(user, allowedKeyPath));141 authFound = true;142 }143 if (!authFound) {144 throw new CitrusRuntimeException("Neither 'password' nor 'allowed-key-path' is set. Please provide at least one");145 }146 // Setup endpoint adapter147 ScpCommandFactory commandFactory = new ScpCommandFactory.Builder()148 .withDelegate(command -> new SshCommand(command, getEndpointAdapter(), endpointConfiguration))149 .build();150 commandFactory.addEventListener(getScpTransferEventListener());151 sshd.setCommandFactory(commandFactory);152 ArrayList<NamedFactory<Command>> subsystemFactories = new ArrayList<>();153 SftpSubsystemFactory sftpSubsystemFactory = new SftpSubsystemFactory.Builder().build();154 sftpSubsystemFactory.addSftpEventListener(getSftpEventListener());155 subsystemFactories.add(sftpSubsystemFactory);156 sshd.setSubsystemFactories(subsystemFactories);157 try {158 sshd.start();159 } catch (IOException e) {160 throw new CitrusRuntimeException("Failed to start SSH server - " + e.getMessage(), e);161 }162 }163 /**164 * Gets Scp trsanfer event listener. By default uses abstract implementation that use trace level logging of all operations.165 * @return166 */167 protected ScpTransferEventListener getScpTransferEventListener() {168 return new AbstractScpTransferEventListenerAdapter() {};169 }170 /**171 * Gets Sftp event listener. By default uses abstract implementation that use trace level logging of all operations.172 * @return173 */174 protected SftpEventListener getSftpEventListener() {175 return new AbstractSftpEventListenerAdapter(){};176 }177 @Override178 protected void shutdown() {179 try {180 sshd.stop();181 } catch (IOException e) {182 throw new CitrusRuntimeException("Failed to stop SSH server - " + e.getMessage(), e);183 }184 }185 @Override186 public AbstractPollableEndpointConfiguration getEndpointConfiguration() {187 return endpointConfiguration;188 }189 /**190 * Gets the server port.191 * @return192 */193 public int getPort() {194 return port;195 }196 /**197 * Sets the port.198 * @param port the port to set199 */200 public void setPort(int port) {201 this.port = port;202 this.endpointConfiguration.setPort(port);203 }204 /**205 * Gets the username.206 * @return207 */208 public String getUser() {209 return user;210 }211 /**212 * Sets the user.213 * @param user the user to set214 */215 public void setUser(String user) {216 this.user = user;217 this.endpointConfiguration.setUser(user);218 }219 /**220 * Gets the user password.221 * @return222 */223 public String getPassword() {224 return password;225 }226 /**227 * Sets the password.228 * @param password the password to set229 */230 public void setPassword(String password) {231 this.password = password;232 this.endpointConfiguration.setPassword(password);233 }234 /**235 * Gets the allowed key path.236 * @return237 */238 public String getAllowedKeyPath() {239 return allowedKeyPath;240 }241 /**242 * Sets the allowedKeyPath.243 * @param allowedKeyPath the allowedKeyPath to set244 */245 public void setAllowedKeyPath(String allowedKeyPath) {246 this.allowedKeyPath = allowedKeyPath;247 }248 /**249 * Gets the host key path.250 * @return251 */252 public String getHostKeyPath() {253 return hostKeyPath;254 }255 /**256 * Sets the hostKeyPath.257 * @param hostKeyPath the hostKeyPath to set258 */259 public void setHostKeyPath(String hostKeyPath) {260 this.hostKeyPath = hostKeyPath;261 }262 /**263 * Gets the userHomePath.264 *265 * @return266 */267 public String getUserHomePath() {268 return userHomePath;269 }270 /**271 * Sets the userHomePath.272 *273 * @param userHomePath274 */275 public void setUserHomePath(String userHomePath) {276 this.userHomePath = userHomePath;277 }278 /**279 * Gets the message converter.280 * @return281 */282 public SshMessageConverter getMessageConverter() {283 return messageConverter;284 }285 /**286 * Sets the message converter.287 * @param messageConverter288 */289 public void setMessageConverter(SshMessageConverter messageConverter) {...
Source:SOAP_API_EndToEnd_IT.java
...48import com.consol.citrus.dsl.endpoint.CitrusEndpoints;49import com.consol.citrus.dsl.runner.TestRunner;50import com.consol.citrus.http.security.BasicAuthConstraint;51import com.consol.citrus.ws.security.SecurityHandlerFactory;52import com.consol.citrus.ws.security.User;53import com.consol.citrus.ws.server.WebServiceServer;54import com.jayway.jsonpath.Configuration;55import com.jayway.jsonpath.JsonPath;56import com.jayway.jsonpath.TypeRef;57import com.jayway.jsonpath.spi.json.JacksonJsonProvider;58import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;59/**60 * End to end test, in the sense that SOAP API generator is used to create the61 * API client connector instead of having a predefined connector. Tests all62 * combinations of path/operation, defined/referenced parameters.63 */64@Testcontainers65public class SOAP_API_EndToEnd_IT extends SyndesisIntegrationTestSupport {66 @Container67 public static final SyndesisIntegrationRuntimeContainer INTEGRATION_CONTAINER;68 private static final WebServiceServer SOAP_SERVER;69 static {70 final SecurityHandlerFactory securityHandlerFactory = new SecurityHandlerFactory();71 final User testUser = new User();72 testUser.setName("test");73 testUser.setPassword("secret");74 final String[] authenticated = new String[] {"authenticated"};75 testUser.setRoles(authenticated);76 securityHandlerFactory.setUsers(Collections.singletonList(testUser));77 securityHandlerFactory.setConstraints(Collections.singletonMap("/endpoint/*", new BasicAuthConstraint(authenticated)));78 try {79 securityHandlerFactory.afterPropertiesSet();80 SOAP_SERVER = startup(CitrusEndpoints.soap()81 .server()82 .port(SocketUtils.findAvailableTcpPort())83 .autoStart(true)84 .securityHandler(securityHandlerFactory.getObject())85 .build());86 } catch (Exception e) {87 throw new ExceptionInInitializerError(e);88 }89 org.testcontainers.Testcontainers.exposeHostPorts(SOAP_SERVER.getPort());90 INTEGRATION_CONTAINER = new SyndesisIntegrationRuntimeContainer.Builder()...
Source:SoapConnectorBasicAuth_IT.java
...26import com.consol.citrus.dsl.runner.TestRunner;27import com.consol.citrus.exceptions.CitrusRuntimeException;28import com.consol.citrus.http.security.BasicAuthConstraint;29import com.consol.citrus.http.security.SecurityHandlerFactory;30import com.consol.citrus.http.security.User;31import com.consol.citrus.ws.server.WebServiceServer;32import io.syndesis.test.SyndesisTestEnvironment;33import io.syndesis.test.container.integration.SyndesisIntegrationRuntimeContainer;34import io.syndesis.test.itest.SyndesisIntegrationTestSupport;35import org.eclipse.jetty.security.AbstractLoginService;36import org.eclipse.jetty.security.HashLoginService;37import org.eclipse.jetty.security.IdentityService;38import org.eclipse.jetty.security.PropertyUserStore;39import org.eclipse.jetty.security.SecurityHandler;40import org.eclipse.jetty.util.security.Credential;41import org.junit.jupiter.api.Test;42import org.springframework.util.SocketUtils;43import org.testcontainers.containers.GenericContainer;44import org.testcontainers.junit.jupiter.Container;45import org.testcontainers.junit.jupiter.Testcontainers;46import static org.hamcrest.CoreMatchers.is;47@Testcontainers48public class SoapConnectorBasicAuth_IT extends SyndesisIntegrationTestSupport {49 private static final int SOAP_SERVER_PORT = SocketUtils.findAvailableTcpPort();50 private static final String USERNAME = "registered";51 private static final String PASSWORD = "secret";52 private static final List<User> USERS = new ArrayList<User>();53 private static final String[] ROLES = new String[]{USERNAME};54 private static final User USER = new User();55 static {56 org.testcontainers.Testcontainers.exposeHostPorts(SOAP_SERVER_PORT);57 USER.setName(USERNAME);58 USER.setRoles(ROLES);59 USER.setPassword(PASSWORD);60 USERS.add(USER);61 }62 private static final WebServiceServer SOAP_SERVER = startup(soapServer());63 private static final String REQUEST_PAYLOAD =64 "<ns1:sayHi xmlns:ns1=\"http://camel.apache.org/cxf/wsrm\">" +65 "<arg0 xmlns=\"http://camel.apache.org/cxf/wsrm\">BasicAuth</arg0>" +66 "</ns1:sayHi>";67 private static final String RESPONSE_PAYLOAD =68 "<ns1:sayHiResponse xmlns:ns1=\"http://camel.apache.org/cxf/wsrm\">" +69 " <ns1:return xmlns=\"http://camel.apache.org/cxf/wsrm\">Hello BasicAuth!</ns1:return>" +70 "</ns1:sayHiResponse>";71 /**72 * Integration uses api connector to send SOAP client requests to a REST endpoint. The client API connector was generated73 * from SOAP WSDL1.1 specification.74 * <p>75 * The integration invokes following sequence of client requests on the test server76 * Invoke operation sayHi.77 */78 @Container79 public static final SyndesisIntegrationRuntimeContainer INTEGRATION_CONTAINER = new SyndesisIntegrationRuntimeContainer.Builder()80 .name("soap-basic-auth")81 .fromExport(SoapConnectorBasicAuth_IT.class.getResource("SOAPBasicAuthentication-export"))82 .customize("$..configuredProperties.period", "5000")83 .customize("$..configuredProperties.address",84 String.format("http://%s:%s/HelloWorld", GenericContainer.INTERNAL_HOST_HOSTNAME, SOAP_SERVER_PORT))85 .build()86 .withNetwork(getSyndesisDb().getNetwork())87 .withExposedPorts(SyndesisTestEnvironment.getServerPort(),88 SyndesisTestEnvironment.getManagementPort());89 @Test90 @CitrusTest91 public void testSayHi(@CitrusResource TestRunner runner) {92 runner.sql(builder -> builder.dataSource(sampleDb())93 .statement("delete from contact"));94 runner.echo("SayHi operation");95 runner.soap(builder -> builder.server(SOAP_SERVER)96 .receive()97 .payload(REQUEST_PAYLOAD));98 runner.soap(builder -> builder.server(SOAP_SERVER)99 .send()100 .payload(RESPONSE_PAYLOAD));101 runner.repeatOnError()102 .index("retries")103 .autoSleep(1000L)104 .until(is(6))105 .actions(runner.query(builder -> builder.dataSource(sampleDb())106 .statement("select count(*) as found_records from contact where first_name like 'Hello BasicAuth!'")107 .validateScript("assert rows.get(0).get(\"found_records\") > 0", "groovy")));108 }109 public static WebServiceServer soapServer() {110 return CitrusEndpoints.soap()111 .server()112 .port(SOAP_SERVER_PORT)113 .securityHandler(basicAuthSecurityHandler())114 .autoStart(true)115 .timeout(600000L)116 .build();117 }118 public static SecurityHandler basicAuthSecurityHandler() {119 try {120 return basicAuthSecurityHandlerFactoryBean().getObject();121 } catch (Exception e) {122 throw new CitrusRuntimeException("Failed to create basic auth security handler", e);123 }124 }125 public static SecurityHandlerFactory basicAuthSecurityHandlerFactoryBean() {126 SecurityHandlerFactory securityHandlerFactory = new SecurityHandlerFactory();127 securityHandlerFactory.setUsers(USERS);128 securityHandlerFactory.setLoginService(basicAuthLoginService(basicAuthUserStore()));129 securityHandlerFactory.setConstraints(130 Collections.singletonMap("/*", new BasicAuthConstraint(ROLES)));131 return securityHandlerFactory;132 }133 public static HashLoginService basicAuthLoginService(PropertyUserStore basicAuthUserStore) {134 return new HashLoginService() {135 @Override136 protected void doStart() throws Exception {137 setUserStore(basicAuthUserStore);138 basicAuthUserStore.start();139 super.doStart();140 }141 };142 }143 public static PropertyUserStore basicAuthUserStore() {144 return new PropertyUserStore() {145 @Override146 protected void loadUsers() throws IOException {147 getKnownUserIdentities().clear();148 for (User user : USERS) {149 Credential credential = Credential.getCredential(user.getPassword());150 Principal userPrincipal = new AbstractLoginService.UserPrincipal(user.getName(), credential);151 Subject subject = new Subject();152 subject.getPrincipals().add(userPrincipal);153 subject.getPrivateCredentials().add(credential);154 String[] roleArray = IdentityService.NO_ROLES;155 if (user.getRoles() != null && user.getRoles().length > 0) {156 roleArray = user.getRoles();157 }158 for (String role : roleArray) {159 subject.getPrincipals().add(new AbstractLoginService.RolePrincipal(role));160 }161 subject.setReadOnly();162 getKnownUserIdentities().put(user.getName(), getIdentityService().newUserIdentity(subject, userPrincipal, roleArray));163 }164 }165 };166 }167}...
User
Using AI Code Generation
1package com.consol.citrus;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.ws.client.WebServiceClient;5import com.consol.citrus.ws.message.SoapAttachment;6import com.consol.citrus.ws.message.SoapMessage;7import com.consol.citrus.ws.security.WssSecurityInterceptor;8import com.consol.citrus.ws.security.callback.SimplePasswordValidationCallbackHandler;9import com.consol.citrus.ws.security.callback.SimpleUsernameValidationCallbackHandler;10import com.consol.citrus.ws.security.callback.WssPasswordCallbackHandler;11import com.consol.citrus.ws.security.callback.WssUsernameCallbackHandler;12import com.consol.citrus.ws.security.callback.WssUsernameTokenCallbackHandler;13import com.consol.citrus.ws.security.callback.WssUsernameTokenPasswordCallbackHandler;14import com.consol.citrus.ws.security.callback.WssUsernameTokenUsernameCallbackHandler;15import com.consol.citrus.ws.security.callback.WssUsernameTokenUsernamePasswordCallbackHandler;16import com.consol.citrus.ws.security.callback.WssX509CallbackHandler;17import com.consol.citrus.ws.security.callback.WssX509TokenCallbackHandler;18import com.consol.citrus.ws.security.callback.WssX509TokenPasswordCallbackHandler;19import com.consol.citrus.ws.security.callback.WssX509TokenUsernameCallbackHandler;20import com.consol.citrus.ws.security.callback.WssX509TokenUsernamePasswordCallbackHandler;21import com.consol.citrus.ws.security.callback.WssX509TokenX509CallbackHandler;22import com.consol.citrus.ws.security.callback.WssX509TokenX509PasswordCallbackHandler;23import com.consol.citrus.ws.security.callback.WssX509TokenX509UsernameCallbackHandler;24import com.consol.citrus.ws.security.callback.WssX509TokenX509UsernamePasswordCallbackHandler;25import com.consol.citrus.ws.security.callback.WssX509TokenX509UsernameRequestSignatureCallbackHandler;26import com.consol.citrus.ws.security.callback.WssX509TokenX509UsernameRequestSignaturePasswordCallbackHandler;27import com.consol.citrus.ws.security.callback.WssX509TokenX509UsernameRequestSignatureUsernameCallbackHandler;28import com.consol.citrus.ws.security.callback.WssX509TokenX509UsernameRequestSignatureUsernamePasswordCallbackHandler
User
Using AI Code Generation
1User user = new User();2user.setUserName("admin");3user.setPassword("password");4User user = new User();5user.setUserName("admin");6user.setPassword("password");7User user = new User();8user.setUserName("admin");9user.setPassword("password");10User user = new User();11user.setUserName("admin");12user.setPassword("password");13User user = new User();14user.setUserName("admin");15user.setPassword("password");16User user = new User();17user.setUserName("admin");18user.setPassword("password");19User user = new User();20user.setUserName("admin");21user.setPassword("password");22User user = new User();23user.setUserName("admin");24user.setPassword("password");25User user = new User();26user.setUserName("admin");27user.setPassword("password");28User user = new User();29user.setUserName("admin");30user.setPassword("password");31User user = new User();32user.setUserName("admin");33user.setPassword("password");34User user = new User();35user.setUserName("admin");36user.setPassword("password");37User user = new User();38user.setUserName("admin");39user.setPassword("password");40User user = new User();41user.setUserName("admin");42user.setPassword("password");43User user = new User();
User
Using AI Code Generation
1package com.consol.citrus.samples;2import com.consol.citrus.dsl.endpoint.CitrusEndpoints;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.dsl.runner.TestRunnerSupport;5import com.consol.citrus.ws.client.WebServiceClient;6import com.consol.citrus.ws.message.SoapAttachment;7import com.consol.citrus.ws.message.SoapMessage;8import com.consol.citrus.ws.message.SoapMessageHeaders;9import com.consol.citrus.ws.security.User;10import org.springframework.context.annotation.Bean;11import org.springframework.context.annotation.Configuration;12import org.springframework.core.io.ClassPathResource;13import org.springframework.http.HttpStatus;14import org.springframework.ws.soap.SoapVersion;15public class WebServiceClientConfig extends TestRunnerSupport {16 public WebServiceClient webServiceClient() {17 .soap()18 .client()19 .interceptor(new User("citrus", "citrus"))20 .build();21 }22 public WebServiceClient webServiceClient2() {23 .soap()24 .client()25 .interceptor(new User("citrus", "citrus"))26 .build();27 }28 public WebServiceClient webServiceClient3() {29 .soap()30 .client()31 .interceptor(new User("citrus", "citrus"))32 .build();33 }34 public WebServiceClient webServiceClient4() {35 .soap()36 .client()37 .interceptor(new User("citrus", "citrus"))38 .build();39 }40 public WebServiceClient webServiceClient5() {41 .soap()42 .client()43 .interceptor(new
User
Using AI Code Generation
1import com.consol.citrus.ws.client.WebServiceClient;2import com.consol.citrus.ws.security.User;3import com.consol.citrus.ws.security.callback.CitrusKeystorePasswordCallback;4import com.consol.citrus.ws.security.callback.CitrusPrivateKeyPasswordCallback;5import com.consol.citrus.ws.security.callback.CitrusUsernamePasswordCallback;6import com.consol.citrus.ws.security.callback.CitrusValidationCallback;7import com.consol.citrus.ws.security.callback.CitrusWss4jCallbackHandler;8import com.consol.citrus.ws.security.callback.Wss4jPasswordCallbackHandler;9import com.consol.citrus.ws.security.callback.Wss4jUsernameTokenCallbackHandler;10import com.consol.citrus.ws.security.callback.Wss4jValidationCallbackHandler;11import com.consol.citrus.ws.security.callback.Wss4jValidationSamlCallbackHandler;12import com.consol.citrus.ws.security.callback.Wss4jX509CallbackHandler;13import org.apache.ws.security.WSPasswordCallback;14import org.apache.ws.security.handler.WSHandlerConstants;15import org.springframework.context.annotation.Bean;16import org.springframework.context.annotation.Configuration;17import org.springframework.ws.soap.security.wss4j2.Wss4jSecurityInterceptor;18import javax.xml.namespace.QName;19import java.util.HashMap;20import java.util.Map;21public class WebServiceClientConfig {22 public WebServiceClient webServiceClient() {23 WebServiceClient client = new WebServiceClient();24 client.setMarshaller(marshaller());25 client.setUnmarshaller(marshaller());26 return client;27 }28 public Marshaller marshaller() {29 Jaxb2Marshaller marshaller = new Jaxb2Marshaller();30 marshaller.setContextPath("com.consol.citrus.samples.ws");31 return marshaller;32 }33 public Wss4jSecurityInterceptor securityInterceptor() {34 Wss4jSecurityInterceptor securityInterceptor = new Wss4jSecurityInterceptor();35 Map<String, Object> properties = new HashMap<>();36 properties.put(WSHandlerConstants.ACTION, "UsernameToken");37 properties.put(WSHandlerConstants.PASSWORD_TYPE, "PasswordText");
User
Using AI Code Generation
1User user = new User();2user.setUsername("username");3user.setPassword("password");4user.setRoles("ROLE_USER");5user.setAuthorizations("AUTH_USER");6user.setAuthorities("AUTH_USER");7user.setAuthorities("AUTH_USER");8user.setDn("cn=username,ou=users,
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!