Use Lightadmin under HTTPS

162 views
Skip to first unread message

Yoann Khanh

unread,
Jul 10, 2015, 11:49:28 AM7/10/15
to light...@googlegroups.com
Hi,

I need to use Lightadmin under HTTPS but there are call to HTTP urls into the web page and it fail do display css/js.

<script type="text/javascript" src="http://mywebsite.com/admin/scripts/vendor/plugins/spinner/ui.spinner.js"></script>
<script type="text/javascript" src="http://mywebsite.com/admin/scripts/vendor/plugins/wysiwyg/jquery.wysiwyg.js"></script>

Anyone know how to configure Lightadmin so the all url used to fill template will use https? To have something like this:

<script type="text/javascript" src="https://mywebsite.com/admin/scripts/vendor/plugins/wysiwyg/jquery.wysiwyg.js"></script>

The other part of my web site is note under https.

Thanks,
Yoann

Anton Krug

unread,
Apr 7, 2016, 9:54:19 AM4/7/16
to Light Admin Group
I have the very same issue, all the resource links ignore the fact that the request came from HTTPS protocol.

Yoann Khanh

unread,
Apr 7, 2016, 10:02:10 AM4/7/16
to Light Admin Group
Hi Anton

Here the class I used to fix the problems

/**
 * Used to override the one included into the Lightadmin jar
 * @Author Yoann
 */

public class LightAdminUrlTag extends org.springframework.web.servlet.tags.UrlTag {

 
private static final String URL_TYPE_ABSOLUTE = "://";

 
private static final Logger LOGGER = LoggerFactory.getLogger(LightAdminUrlTag.class);

 
@Override
 
public int doEndTag() throws JspException {
 
if (isRelative(getValue())) {
 
String absUrl = absoluteUrlOf(applicationUrl(getValue()));
 
if (!absUrl.contains("localhost") && !absUrl.contains("https")) {
 absUrl
= absUrl.replace("http", "https");
 
}
 setValue
(absUrl);
 
}

 
return super.doEndTag();
 
}

 
private String absoluteUrlOf(String applicationBaseUrl) {
 
return fromCurrentContextPath().path(applicationBaseUrl).build().toUriString();
 
}

 
private boolean isRelative(String value) {
 
return !value.contains(URL_TYPE_ABSOLUTE);
 
}

 
private String getValue() {
 
return (String) forDirectFieldAccess(this).getPropertyValue("value");
 
}

 
private String applicationUrl(String value) {
 
return lightAdminConfiguration().getApplicationUrl(value);
 
}

 
private LightAdminConfiguration lightAdminConfiguration() {
 
return getRequestContext().getWebApplicationContext().getBean(LightAdminConfiguration.class);
 
}
}

Create it into package named
org.lightadmin.core.view.tags

Hope this help


Anton Krug

unread,
Apr 22, 2016, 10:00:26 AM4/22/16
to Light Admin Group
I left it be for some time and yesterday I was looking at the source code and came to this class as well and the org.springframework.web.servlet.tags.UrlTag.Thinking that simple replace would be dodgy but could work, so I searched if somebody done it already and then remembered that I posted in this forum. Thanks for your reply.

I had slightly different mileage with your code, I used your code and modified it a bit

/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lightadmin.core.view.tags;

import org.lightadmin.core.config.LightAdminConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.jsp.JspException;

import static org.springframework.beans.PropertyAccessorFactory.forDirectFieldAccess;
import static org.springframework.web.servlet.support.ServletUriComponentsBuilder.fromCurrentContextPath;

/**
* Overides http into https
* @Author Yoann
*/
/*
* Modified https handling
*
* @Author Anton
 */
public class LightAdminUrlTag extends org.springframework.web.servlet.tags.UrlTag {

    //these URLs will be excluded from https and will use http
public static String Exclude1 = "localhost";
public static String Exclude2 = "example.com";

private static final String URL_TYPE_ABSOLUTE = "://";
    private static final  Logger log               = LoggerFactory.getLogger(LightAdminUrlTag.class);


private String replaceHttp(String url) {
if ( !url.contains(Exclude1) && !url.contains(Exclude2) && !url.contains("https")) {
return url.replace("http", "https");
}
return url;

}


@Override
public int doEndTag() throws JspException {
        if (true) {
if (isRelative(getValue())) {
setValue(absoluteUrlOf(applicationUrl(getValue())));
}
return super.doEndTag();
}

log.debug(getValue() + " --- " +absoluteUrlOf(applicationUrl(getValue())));

if (isRelative(getValue())) {
//relative paths convert into absolute first and then convert http into https
setValue(replaceHttp(absoluteUrlOf(applicationUrl(getValue()))));
} else {
//absolute paths just replace http with https
setValue(replaceHttp(getValue()));
}

log.debug("Converted: "+getValue());

return super.doEndTag();
}

private String absoluteUrlOf(String applicationBaseUrl) {
return fromCurrentContextPath().path(applicationBaseUrl).build().toUriString();
}

private boolean isRelative(String value) {
return !value.contains(URL_TYPE_ABSOLUTE);
}

private String getValue() {
return (String) forDirectFieldAccess(this).getPropertyValue("value");
}

private String applicationUrl(String value) {
return lightAdminConfiguration().getApplicationUrl(value);
}

private LightAdminConfiguration lightAdminConfiguration() {
return getRequestContext().getWebApplicationContext().getBean(LightAdminConfiguration.class);
}
}

The exclude strings  are public so you can modify them from your application:

LightAdminUrlTag.Exclude2 = "example.com";

And then till the end I had issues anyway so I disabled it.

Your code didn't worked with Domain models on the dashboard on the left. The one I had later worked for most of the parts, but then when I was saving model the frontend wants to refresh the new updated data the calls and does these GET calls

/admin/rest/users/1
/admin/rest/users/metadata?_=1461333343708

When HTTPS was enabled it gave me NOT FOUND error, even the regular ShowForm (which is probably the same for both cases) works properly. I'm bit tired of this tool I removed at least the help/template/export buttons, I even made fork with to complain about issues I had with this tool so far. It was meant to be painless and rapid integration etc... so far I had very unlucky and frustrating expierence with it.

This is the fork I did:

https://github.com/truhlikfredy/light-admin-https



Reply all
Reply to author
Forward
0 new messages