Alex Dowining
Alex Dowining

Reputation: 970

Base64 encoding for the log in with the spring mvc

i'm trying to make a log in. I'm using the Spring MVC framework. I have to implement a form submitting the password and username at the server. My form is the following:

The model:

package org.client.log;

import javax.xml.bind.annotation.*;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class InfoLogin{



private String username;
private String password;




public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

}

I use the jaxb technology for marshaling and unmarshalling the xml's i exchange with the server side. The problem is that i need to to encode both username and password with the base64 encoding and after to send this on the server side. The encoding should be add something on the headers. I read many tutorials and the most of them said that i should do with the spring security. I don't know how to do this. Does anyone has anything to propose?

Actually that i want to do is: to make a base64 encoding to this ("username:password") and create this "QWxh784bjpvcG58VuIHNlc2FtZQ==" (for example) which will be added on the header

Upvotes: 2

Views: 4870

Answers (1)

Alex Dowining
Alex Dowining

Reputation: 970

Ok, i find the solution which is the following: I just need to add in the controller in the method addPersonLogin the following lines of code:

   byte[] data = Base64.encodeBase64(datas.getBytes());
   String personheader=  new String(bytevalues);
   headers.set( "Authorization: Basic", personheader);

Upvotes: 5

Related Questions