sorry for my bad language at first. I am a student from Germany und new in programming.
I have implemented a little websocket server with Spring Boot and secured it with Spring Security using Basic Auth. Angular 2 is used in the Front End. I have implemented the following solution to connect to the websocket.
* Connects to a websocket server. * @param {string} url The url of the WS Server * @param {string} channel The channel to subscribe * @return {boolean} connection status */ public connect(url: string, channel: string): boolean { console.group('WebSocketService: Welcome to the connect function.'); console.log('Connects to', url); console.log('Channel is', channel); let _self = this; let socket = new SockJS(url);
_self.wsClient = Stomp.over(socket);
_self.wsClient.connect({}, function(frame) {
_self.setConnected(true);
console.log('Connected: ', frame);
_self.wsClient.subscribe(channel, function(greeting) {
console.log(greeting);
_self.subjects[channel].next(greeting);
});
});
console.groupEnd();
return true;
}
Calling this function let the browser open an input for username and password. Now i can connect and disconnect from the Server with no need to enter the username / password again.
How can i replace this browser input window with using login information in the code?
I tried to do this by a single Post request like:
private test2(){ let username : string = 'admin'; let password : string = 'pass'; let headers = new Headers(); headers.append("Authorization", "Basic " + btoa(username + ":" + password)); headers.append("Content-Type", "application/x-www-form-urlencoded"); console.log('Test beginnt'); return this._http.get('http://localhost:8080/gs-guide-websocket', {headers: headers}).map(res=> console.log(res)) }Blockquote
But this gives me only an http 200 response and did not open a session or something.
I have tried to put the login information in the original request also.
_self.wsClient.connect('admin','pass', function(frame) { ...}
Thank you for your help.