Skip to content

Commit acc21bc

Browse files
committed
Introducing Spring autowire
1 parent ac4f34c commit acc21bc

File tree

14 files changed

+304
-41
lines changed

14 files changed

+304
-41
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/document/dao/HibernateDocumentDAO.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,10 @@ private void setUniqueFilename(Document doc) {
519519
final Set<String> fileNames = new HashSet<>();
520520

521521
StringBuilder query = new StringBuilder(
522-
"select lower(ld_filename) from ld_document where ld_deleted=0 and ld_folderid=");
522+
"select ld_filename from ld_document where ld_deleted=0 and ld_folderid=");
523523
query.append(Long.toString(doc.getFolder().getId()));
524-
query.append(" and lower(ld_filename) like '");
525-
query.append(SqlUtil.doubleQuotes(baseName.toLowerCase()));
524+
query.append(" and ld_filename like '");
525+
query.append(SqlUtil.doubleQuotes(baseName));
526526
query.append("%' and not ld_id=");
527527
query.append(Long.toString(doc.getId()));
528528

logicaldoc-core/src/main/java/com/logicaldoc/core/security/SessionManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,24 +454,24 @@ public HttpSession getServletSession(String sid) {
454454
* Create a client identified using a concatenation of Basic authentication
455455
* credentials and remote IP.
456456
*
457-
* @param req The request to process
457+
* @param request The request to process
458458
*
459459
* @return The client
460460
*/
461-
public Client buildClient(HttpServletRequest req) {
462-
Client client = new Client(req);
461+
public Client buildClient(HttpServletRequest request) {
462+
Client client = new Client(request);
463463

464464
/**
465465
* We extract the username used by the user from the basic credentials.
466466
* This may differ from the real username in case the login.ignorecase
467467
* flag is activates
468468
*/
469-
String[] credentials = getBasicCredentials(req);
469+
String[] credentials = getBasicCredentials(request);
470470
if (credentials.length > 0 && credentials[0] != null)
471471
client.setUsername(credentials[0]);
472472
if (credentials.length > 1)
473473
client.setId(String.format("%s-%s-%s", credentials[0],
474-
credentials[1] != null ? "0" : credentials[1].hashCode(), req.getRemoteAddr()));
474+
credentials[1] != null ? "0" : credentials[1].hashCode(), request.getRemoteAddr()));
475475
return client;
476476

477477
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/Menu.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ public class Menu {
185185

186186
public static final long SINGLE_SIGNON = 1875;
187187

188+
public static final long SAML = 1876;
189+
190+
public static final long SAMK = 1876;
191+
188192
public static final long RESTART = -1190;
189193

190194
public static final long SYNDICATION = 2000;

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/widgets/CopyTextFormItemIcon.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
* @since 8.9
1212
*/
1313
public class CopyTextFormItemIcon extends FormItemIcon {
14+
1415
/**
15-
* The constructor
16+
* The constructor.
1617
*
1718
* @param text the text to copy into the clipboard
1819
*/
@@ -21,6 +22,19 @@ public CopyTextFormItemIcon(String text) {
2122
setSrc("[SKIN]/page_white_paste.png");
2223
setWidth(16);
2324
setHeight(16);
24-
addFormItemClickHandler(event -> Util.copyText(text));
25+
addFormItemClickHandler(event -> {
26+
if (text != null)
27+
Util.copyText(text);
28+
else
29+
Util.copyText(event.getItem().getValue().toString());
30+
});
31+
}
32+
33+
/**
34+
* The constructor, the current item's text will be copied into the
35+
* clipboard.
36+
*/
37+
public CopyTextFormItemIcon() {
38+
this(null);
2539
}
2640
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/security/SecurityMenu.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.logicaldoc.gui.frontend.client.administration.AdminScreen;
1212
import com.logicaldoc.gui.frontend.client.security.group.GroupsPanel;
1313
import com.logicaldoc.gui.frontend.client.security.ldap.LDAPServersPanel;
14+
import com.logicaldoc.gui.frontend.client.security.saml.SamlPanel;
1415
import com.logicaldoc.gui.frontend.client.security.twofactorsauth.TwoFactorsAuthenticationSettings;
1516
import com.logicaldoc.gui.frontend.client.security.user.UsersPanel;
1617
import com.smartgwt.client.types.Overflow;
@@ -47,6 +48,8 @@ public SecurityMenu() {
4748

4849
addExtAuthButton();
4950

51+
addSamlButton();
52+
5053
addSingleSignonButton();
5154
}
5255

@@ -87,6 +90,18 @@ private void addUsersButton() {
8790
addMember(users);
8891
}
8992

93+
private void addSamlButton() {
94+
Button saml = new Button(I18N.message("singlesignonsaml"));
95+
saml.setWidth100();
96+
saml.setHeight(25);
97+
saml.addClickHandler(event -> AdminScreen.get().setContent(new SamlPanel()));
98+
if (Feature.visible(Feature.SINGLE_SIGNON) && Session.get().isDefaultTenant() && Menu.enabled(Menu.SAML)) {
99+
addMember(saml);
100+
if (!Feature.enabled(Feature.SINGLE_SIGNON) || Session.get().isDemo())
101+
setFeatureDisabled(saml);
102+
}
103+
}
104+
90105
private void addSingleSignonButton() {
91106
Button singleSingon = new Button(I18N.message("singlesignon"));
92107
singleSingon.setWidth100();
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package com.logicaldoc.gui.frontend.client.security.saml;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
import com.google.gwt.user.client.rpc.AsyncCallback;
8+
import com.logicaldoc.gui.common.client.Session;
9+
import com.logicaldoc.gui.common.client.beans.GUIParameter;
10+
import com.logicaldoc.gui.common.client.i18n.I18N;
11+
import com.logicaldoc.gui.common.client.log.GuiLog;
12+
import com.logicaldoc.gui.common.client.util.ItemFactory;
13+
import com.logicaldoc.gui.common.client.widgets.CopyTextFormItemIcon;
14+
import com.logicaldoc.gui.frontend.client.services.SettingService;
15+
import com.smartgwt.client.types.Alignment;
16+
import com.smartgwt.client.types.TitleOrientation;
17+
import com.smartgwt.client.widgets.IButton;
18+
import com.smartgwt.client.widgets.events.ClickEvent;
19+
import com.smartgwt.client.widgets.form.DynamicForm;
20+
import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
21+
import com.smartgwt.client.widgets.form.fields.TextItem;
22+
import com.smartgwt.client.widgets.layout.VLayout;
23+
import com.smartgwt.client.widgets.tab.Tab;
24+
import com.smartgwt.client.widgets.tab.TabSet;
25+
26+
/**
27+
* This panel shows the Saml settings
28+
*
29+
* @author Marco Meschieri - LogicalDOC
30+
* @since 8.1
31+
*/
32+
public class SamlPanel extends VLayout {
33+
34+
private static final String SAML_ENABLED = "saml.enabled";
35+
36+
private static final String SAML_SP_ENTITYID = "saml.sp.entityid";
37+
38+
private static final String SAML_SP_X509CERT = "saml.sp.x509cert";
39+
40+
private static final String SAML_SP_PRIVATEKEY = "saml.sp.privatekey";
41+
42+
public SamlPanel() {
43+
setWidth100();
44+
setMembersMargin(5);
45+
setMargin(5);
46+
}
47+
48+
@Override
49+
protected void onDraw() {
50+
SettingService.Instance.get().loadSettingsByNames(
51+
new String[] { SAML_ENABLED, SAML_SP_ENTITYID, SAML_SP_X509CERT, SAML_SP_PRIVATEKEY },
52+
new AsyncCallback<GUIParameter[]>() {
53+
@Override
54+
public void onFailure(Throwable caught) {
55+
GuiLog.serverError(caught);
56+
}
57+
58+
@Override
59+
public void onSuccess(GUIParameter[] settings) {
60+
initGUI(settings);
61+
}
62+
});
63+
}
64+
65+
private void initGUI(GUIParameter[] settings) {
66+
final DynamicForm form = new DynamicForm();
67+
form.setTitleOrientation(TitleOrientation.LEFT);
68+
form.setAlign(Alignment.LEFT);
69+
70+
RadioGroupItem enabled = ItemFactory.newBooleanSelector(SAML_ENABLED, I18N.message("enabled"));
71+
enabled.setWrapTitle(false);
72+
enabled.setRequired(true);
73+
74+
TextItem id = ItemFactory.newTextItem(SAML_SP_ENTITYID, "entityid", null);
75+
id.setWidth(300);
76+
id.setWrapTitle(false);
77+
id.setRequired(true);
78+
79+
TextItem certificate = ItemFactory.newTextItem(SAML_SP_X509CERT, "x509cert", null);
80+
certificate.setWidth(300);
81+
certificate.setWrapTitle(false);
82+
certificate.setRequired(true);
83+
certificate.setIcons(new CopyTextFormItemIcon());
84+
85+
TextItem privateKey = ItemFactory.newTextItem(SAML_SP_PRIVATEKEY, "privatekey", null);
86+
privateKey.setWidth(300);
87+
privateKey.setWrapTitle(false);
88+
privateKey.setRequired(true);
89+
certificate.setIcons(new CopyTextFormItemIcon());
90+
91+
form.setFields(enabled, id, certificate, privateKey);
92+
93+
GuiLog.info("A");
94+
for (GUIParameter setting : settings) {
95+
GuiLog.info("B "+setting.getName());
96+
if (SAML_ENABLED.equals(setting.getName()))
97+
form.getItem(setting.getName()).setValue("true".equals(setting.getValue()) ? "yes" : "no");
98+
else
99+
form.getItem(setting.getName()).setValue(setting.getValue());
100+
}
101+
102+
GuiLog.info("C");
103+
104+
IButton save = prepareSaveButton(form);
105+
106+
107+
108+
Tab tab = new Tab();
109+
tab.setTitle(I18N.message("singlesignonsaml"));
110+
tab.setPane(form);
111+
112+
TabSet tabs = new TabSet();
113+
tabs.setWidth100();
114+
tabs.setHeight100();
115+
tabs.setTabs(tab);
116+
117+
setMembers(tabs, save);
118+
}
119+
120+
private IButton prepareSaveButton(final DynamicForm form) {
121+
IButton save = new IButton();
122+
save.setTitle(I18N.message("save"));
123+
save.addClickHandler((ClickEvent event) -> {
124+
if (!form.validate())
125+
return;
126+
127+
List<GUIParameter> params = new ArrayList<>();
128+
@SuppressWarnings("unchecked")
129+
Map<String, Object> values = (Map<String, Object>) form.getValues();
130+
for (Map.Entry<String, Object> entry : values.entrySet())
131+
params.add(
132+
new GUIParameter(entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : ""));
133+
134+
for (GUIParameter param : params)
135+
Session.get().setConfig(param.getName(), param.getValue());
136+
137+
SettingService.Instance.get().saveSettings(params.toArray(new GUIParameter[0]), new AsyncCallback<Void>() {
138+
139+
@Override
140+
public void onFailure(Throwable caught) {
141+
GuiLog.serverError(caught);
142+
}
143+
144+
@Override
145+
public void onSuccess(Void ret) {
146+
GuiLog.info(I18N.message("settingssaved"), null);
147+
}
148+
});
149+
});
150+
return save;
151+
}
152+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.logicaldoc.gui.frontend.client.security.saml;
2+
3+
import com.google.gwt.core.client.GWT;
4+
import com.google.gwt.user.client.rpc.RemoteService;
5+
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
6+
import com.google.gwt.user.client.rpc.ServiceDefTarget;
7+
import com.logicaldoc.gui.common.client.LDRpcRequestBuilder;
8+
9+
/**
10+
* Service for Saml administration
11+
*
12+
* @author Marco Meschieri - LogicalDOC
13+
* @since 8.9
14+
*/
15+
@RemoteServiceRelativePath("saml")
16+
public interface SamlService extends RemoteService {
17+
18+
public static class Instance {
19+
private static SamlServiceAsync inst;
20+
21+
private Instance() {
22+
}
23+
24+
public static SamlServiceAsync get() {
25+
if (inst == null) {
26+
inst = GWT.create(SamlService.class);
27+
((ServiceDefTarget) inst).setRpcRequestBuilder(new LDRpcRequestBuilder());
28+
}
29+
return inst;
30+
}
31+
}
32+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.logicaldoc.gui.frontend.client.security.saml;
2+
3+
import com.google.gwt.user.client.rpc.AsyncCallback;
4+
import com.logicaldoc.gui.common.client.beans.GUIInfo;
5+
import com.logicaldoc.gui.common.client.beans.GUIParameter;
6+
7+
public interface SamlServiceAsync {
8+
9+
}

logicaldoc-i18n/src/main/resources/i18n/messages.properties

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3035,4 +3035,12 @@ techsupnotavail = Technical support is not available for this installation
30353035
copylinks = Copy links
30363036
copynotes = Copy notes and annotations
30373037
copyoptions = Copy options
3038-
copydocuments = Copy documents
3038+
copydocuments = Copy documents
3039+
singlesignonsaml = Single Sign-on (SAML)
3040+
entityid = Entity ID
3041+
x509cert = x509 Certificate
3042+
3043+
saml.security.authnrequest_signed = true
3044+
saml.security.want_assertions_encrypted = true
3045+
saml.security.want_nameid_encrypted = false
3046+
saml.idp.metadata =

logicaldoc-util/src/main/java/com/logicaldoc/util/io/ResourceUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ public class ResourceUtil {
2121
private ResourceUtil() {
2222
}
2323

24-
public static String readAsString(String resourceName) throws IOException {
24+
public static byte[] readAsBytes(String resourcePath) throws IOException {
25+
return ResourceUtil.class.getClassLoader().getResourceAsStream(resourcePath).readAllBytes();
26+
}
27+
28+
public static String readAsString(String resourcePath) throws IOException {
2529
StringBuilder resourceData = new StringBuilder(1000);
2630
try (BufferedReader reader = new BufferedReader(
27-
new InputStreamReader(ResourceUtil.class.getResourceAsStream(resourceName)))) {
31+
new InputStreamReader(ResourceUtil.class.getResourceAsStream(resourcePath)))) {
2832
char[] buf = new char[1024];
2933
int numRead = 0;
3034
while ((numRead = reader.read(buf)) != -1) {

0 commit comments

Comments
 (0)