I have an OL3 webmap that is attempting to access services from Geoserver that is running on a server on our internal network that uses LDAP logins using windows credentials. I found this link (Accessing secure Geoserver layer with username password) and this link (https://stackoverflow.com/questions/10950747/authenticate-in-geoserver-with-asp-net-and-iis/13123640#13123640) and tried both but it is not resolving the 401 error issue.

This is the code I have from the second link:

//login function
function login (options) {
// url del servlet del geoserver
var url = options.server + "/geoserver/j_spring_security_check";
// parametros para el login
params = "username=" + options["user"] + "&password="
            + options["password"];

var contentType = "application/x-www-form-urlencoded";
//se inicializa la petición ajax
var ajax = $.ajax({
    data : params,
    type : "POST",
    contentType : contentType,
    url : url
// se ejecuta cuando la peticion finaliza
ajax.done(function() {

    if ($.cookie("JSESSIONID") != null && options && options.success) {
// si ocurrio un error al realizar la peticion
ajax.fail(function(data) {
    if (options && options.failure) {
// se ejecuta siempre al final de la petición, sin importar que esta
// haya fallado
ajax.always(function() {
    if (options && options.always) {
var un = prompt("enter your username","");
var pw = prompt("enter your password","");
    user: un, //geoserver user  
    password: pw, 
    server : "http://(host server here):8080", //geoserver host
    success : function(){
        alert("Login OK!");
    failure : function(){
        alert("Login fail!");

Also, if I log into the geoserver admin webpage in a separate tab, I can then open the webmapping application with no issue. I would like to ideally remove this step by putting in the geoserver login into the actual webpage (and preferably not store the login credentials anywhere for security purposes).

  • What kind of services? WMS/WFS? Commented Jan 24, 2018 at 14:41

1 Answer 1


I'm not familar with GeoServer, but I found this.

More generally spoken: HTTP-Status 401 means, that the server which receives your request is secured by "Basic Authentication" (hopefully via HTTPS). You have to put the credentials in the HTTP-Request Header "authorization" (this term is a bit misleading).

The content of header "authorization" looks like
Basic dXNlcjAxOnRvcFNlY3JldA==
The second word is the Base64 encoded presentation of user01:topSecret , with ':' as separator between username and password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.