Skip to content

Commit da2368e

Browse files
committed
1227 Single sign-on with SAML 2
1 parent f3b648c commit da2368e

25 files changed

+557
-104
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,23 @@ public Session getByClientId(String clientId) {
269269
return null;
270270
}
271271

272+
/**
273+
* Gets the session with the specified dictionary value
274+
*
275+
* @param key identifier of the value in the dictionary
276+
* @param value the value to match
277+
*
278+
* @return the session
279+
*/
280+
public Session getByDictionaryValue(String key, Object value) {
281+
for (Session session : getSessions()) {
282+
if (value.equals(session.getDictionary().get(key)))
283+
return session;
284+
}
285+
286+
return null;
287+
}
288+
272289
/**
273290
* Counts the total number of opened sessions
274291
*

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class User extends PersistentObject implements Serializable {
3838
public static final int SOURCE_DEFAULT = 0;
3939

4040
public static final int SOURCE_LDAP = 1;
41+
42+
public static final int SOURCE_SAML = 2;
4143

4244
public static final long USERID_ADMIN = 1;
4345

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/util/ItemFactory.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import com.logicaldoc.gui.common.client.validators.EmailValidator;
5555
import com.logicaldoc.gui.common.client.validators.EmailsValidator;
5656
import com.logicaldoc.gui.common.client.validators.SimpleTextValidator;
57+
import com.logicaldoc.gui.common.client.widgets.CopyTextFormItemIcon;
5758
import com.logicaldoc.gui.common.client.widgets.CronExpressionComposer;
5859
import com.logicaldoc.gui.common.client.widgets.FolderSelector;
5960
import com.logicaldoc.gui.common.client.widgets.PasswordGenerator;
@@ -306,6 +307,7 @@ public class ItemFactory {
306307
textAreaItem.setRequiredMessage(I18N.message(FIELDREQUIRED));
307308
textAreaItem.setHintStyle("hint");
308309
textAreaItem.setBrowserSpellCheck(false);
310+
textAreaItem.setIconVAlign(VerticalAlignment.CENTER);
309311
TextAreaItem.setDefaultProperties(textAreaItem);
310312

311313
TimeItem timeItem = new TimeItem();
@@ -1844,13 +1846,21 @@ public static SliderItem newSliderItem(String name, String title, Double value,
18441846
return item;
18451847
}
18461848

1847-
public static LinkItem newLinkItem(String name, String title) {
1849+
public static LinkItem newLinkItem(String name, String title, String linkTitle, String url) {
1850+
return newLinkItem(name, title, linkTitle, url, null);
1851+
}
1852+
1853+
public static LinkItem newLinkItem(String name, String title, String linkTitle, String url, String textToCopy) {
18481854
LinkItem linkItem = new LinkItem(originalItemName(name));
1849-
if (!title.trim().isEmpty()) {
1850-
linkItem.setTitle(I18N.message(title));
1851-
linkItem.setLinkTitle(I18N.message(title));
1852-
}
1855+
linkItem.setTitle(I18N.message(title));
1856+
linkItem.setLinkTitle(I18N.message(linkTitle));
18531857
linkItem.setWrapTitle(false);
1858+
1859+
if (url != null)
1860+
linkItem.setValue(url);
1861+
1862+
linkItem.setIcons(new CopyTextFormItemIcon(textToCopy != null ? textToCopy : url,
1863+
textToCopy != null ? "copytext" : "copylink"));
18541864
return linkItem;
18551865
}
18561866

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/validators/SimpleTextValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public class SimpleTextValidator extends RegExpValidator {
1414
public SimpleTextValidator() {
1515
super();
1616
setErrorMessage(I18N.message("simpetextinvalid"));
17-
setExpression("^([a-zA-Z0-9\\-]+)$");
17+
setExpression("^([a-zA-Z0-9]+)$");
1818
}
1919
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ public class CopyTextFormItemIcon extends FormItemIcon {
1616
* The constructor.
1717
*
1818
* @param text the text to copy into the clipboard
19+
* @patram tooltip the tooltip to display
1920
*/
20-
public CopyTextFormItemIcon(String text) {
21-
setPrompt(I18N.message("copytext"));
21+
public CopyTextFormItemIcon(String text, String tooltip) {
22+
setName("copy");
23+
setPrompt(I18N.message(tooltip));
2224
setSrc("[SKIN]/page_white_paste.png");
2325
setWidth(16);
2426
setHeight(16);
@@ -30,6 +32,15 @@ public CopyTextFormItemIcon(String text) {
3032
});
3133
}
3234

35+
/**
36+
* The constructor.
37+
*
38+
* @param text the text to copy into the clipboard
39+
*/
40+
public CopyTextFormItemIcon(String text) {
41+
this(text, "copytext");
42+
}
43+
3344
/**
3445
* The constructor, the current item's text will be copied into the
3546
* clipboard.

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/document/StandardPropertiesPanel.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,10 @@ private void prepareForm1() {
196196

197197
private LinkItem prepareFolderItem() {
198198
String path = document.getPathExtended();
199-
200-
LinkItem folder = ItemFactory.newLinkItem("folder", Util.padLeft(path, 40));
199+
LinkItem folder = ItemFactory.newLinkItem("folder", Util.padLeft(path, 40), Util.displayURL(null, document.getFolder().getId()), path);
201200
folder.setTitle(I18N.message("folder"));
202-
folder.setValue(Util.displayURL(null, document.getFolder().getId()));
203-
folder.setTooltip(document.getPathExtended());
201+
folder.setTooltip(path);
204202
folder.setWrap(false);
205-
folder.setWidth(DEFAULT_ITEM_WIDTH);
206-
folder.setIcons(new CopyTextFormItemIcon(path));
207203
return folder;
208204
}
209205

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/folder/FolderStandardPropertiesPanel.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ private void refresh() {
115115

116116
LinkItem pathItem = preparePathItem();
117117

118-
LinkItem barcode = ItemFactory.newLinkItem("barcode", I18N.message("generatebarcode"));
118+
LinkItem barcode = ItemFactory.newLinkItem("barcode", I18N.message("generatebarcode"),
119+
I18N.message("generatebarcode"),
120+
GWT.getHostPageBaseURL() + "barcode?code=" + folder.getId() + "&width=400&height=150");
119121
barcode.setTarget("_blank");
120122
barcode.setTitle(I18N.message("barcode"));
121-
barcode.setValue(GWT.getHostPageBaseURL() + "barcode?code=" + folder.getId() + "&width=400&height=150");
122123

123124
final StaticTextItem documents = ItemFactory.newStaticTextItem("documents",
124125
folder.getDocumentCount() > 0 ? Util.formatLong(folder.getDocumentCount()) : "-");
@@ -220,10 +221,10 @@ public void onSuccess(long[] stats) {
220221
private LinkItem preparePathItem() {
221222
String path = folder.getPathExtended() != null ? folder.getPathExtended()
222223
: FolderNavigator.get().getPath(folder.getId());
223-
LinkItem pathItem = ItemFactory.newLinkItem("path", Util.padLeft(path, 150));
224+
LinkItem pathItem = ItemFactory.newLinkItem("path", Util.padLeft(path, 150), Util.padLeft(path, 150),
225+
Util.displayURL(null, folder.getId()));
224226
pathItem.setTooltip(path);
225227
pathItem.setTitle(I18N.message("path"));
226-
pathItem.setValue(Util.displayURL(null, folder.getId()));
227228
pathItem.setWidth(400);
228229
pathItem.setIcons(new CopyTextFormItemIcon(path));
229230
return pathItem;

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/metadata/template/AttributeSetPropertiesPanel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ private TextAreaItem prepareValidationItem() {
408408
}
409409

410410
private void addOptionsItem(final TextItem attributeName) {
411-
options = ItemFactory.newLinkItem("options", I18N.message("options"));
411+
options = new LinkItem("options");
412+
options.setTitle(I18N.message("options"));
412413
options.setLinkTitle(I18N.message("attributeoptions"));
413414
options.addClickHandler(optionsClick -> {
414415
if (attributeSet.getId() == 0L) {

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/search/SaveDialog.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ public SaveDialog() {
4646
form.setWidth(350);
4747
form.setMargin(5);
4848

49-
TextItem name = ItemFactory.newTextItem("name", null);
49+
TextItem name = ItemFactory.newSimpleTextItem("name", null);
5050
name.setRequired(true);
51-
name.setValidators(new SimpleTextValidator());
5251
name.setWidth(200);
5352

5453
TextItem description = ItemFactory.newTextItem(DESCRIPTION, null);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.logicaldoc.gui.frontend.client.security.saml;
2+
3+
import com.logicaldoc.gui.common.client.i18n.I18N;
4+
import com.logicaldoc.gui.common.client.util.Util;
5+
import com.smartgwt.client.widgets.form.fields.FormItemIcon;
6+
7+
/**
8+
* An icon to be used to download a resource of Saml
9+
*
10+
* @author Marco Meschieri - LogicalDOC
11+
* @since 8.9
12+
*/
13+
public class DownloadFormItemIcon extends FormItemIcon {
14+
15+
/**
16+
* The constructor.
17+
*
18+
* @param url the url to invoke
19+
*/
20+
public DownloadFormItemIcon(String url) {
21+
setPrompt(I18N.message("download"));
22+
setSrc("[SKIN]/page_white_put.png");
23+
setWidth(16);
24+
setHeight(16);
25+
addFormItemClickHandler(event -> Util.download(url));
26+
}
27+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package com.logicaldoc.gui.frontend.client.security.saml;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* A bean to store the SAML settings
7+
*
8+
* @author Marco Meschieri - LogicalDOC
9+
* @since 8.9
10+
*/
11+
public class GUISamlSettings implements Serializable {
12+
13+
private static final long serialVersionUID = 1L;
14+
15+
private boolean enabled = false;
16+
17+
private String entityId;
18+
19+
private String certificate;
20+
21+
private String privateKey;
22+
23+
private boolean authnRequestSigned = false;
24+
25+
private String idpMetadata;
26+
27+
private boolean wantAssertionsEncrypted = false;
28+
29+
private boolean wantNameIdEncrypted = false;
30+
31+
private String username = "username";
32+
33+
private String firstName = "firstName";
34+
35+
private String lastName = "lastName";
36+
37+
private String email = "email";
38+
39+
private String group = "group";
40+
41+
public boolean isEnabled() {
42+
return enabled;
43+
}
44+
45+
public void setEnabled(boolean enabled) {
46+
this.enabled = enabled;
47+
}
48+
49+
public String getEntityId() {
50+
return entityId;
51+
}
52+
53+
public void setEntityId(String entityId) {
54+
this.entityId = entityId;
55+
}
56+
57+
public String getCertificate() {
58+
return certificate;
59+
}
60+
61+
public void setCertificate(String certificate) {
62+
this.certificate = certificate;
63+
}
64+
65+
public boolean isAuthnRequestSigned() {
66+
return authnRequestSigned;
67+
}
68+
69+
public void setAuthnRequestSigned(boolean authnRequestSigned) {
70+
this.authnRequestSigned = authnRequestSigned;
71+
}
72+
73+
public String getIdpMetadata() {
74+
return idpMetadata;
75+
}
76+
77+
public void setIdpMetadata(String idpMetadata) {
78+
this.idpMetadata = idpMetadata;
79+
}
80+
81+
public String getPrivateKey() {
82+
return privateKey;
83+
}
84+
85+
public void setPrivateKey(String privateKey) {
86+
this.privateKey = privateKey;
87+
}
88+
89+
public boolean isWantAssertionsEncrypted() {
90+
return wantAssertionsEncrypted;
91+
}
92+
93+
public void setWantAssertionsEncrypted(boolean wantAssertionsEncrypted) {
94+
this.wantAssertionsEncrypted = wantAssertionsEncrypted;
95+
}
96+
97+
public boolean isWantNameIdEncrypted() {
98+
return wantNameIdEncrypted;
99+
}
100+
101+
public void setWantNameIdEncrypted(boolean wantNameIdEncrypted) {
102+
this.wantNameIdEncrypted = wantNameIdEncrypted;
103+
}
104+
105+
public String getUsername() {
106+
return username;
107+
}
108+
109+
public void setUsername(String username) {
110+
this.username = username;
111+
}
112+
113+
public String getFirstName() {
114+
return firstName;
115+
}
116+
117+
public void setFirstName(String firstName) {
118+
this.firstName = firstName;
119+
}
120+
121+
public String getLastName() {
122+
return lastName;
123+
}
124+
125+
public void setLastName(String lastName) {
126+
this.lastName = lastName;
127+
}
128+
129+
public String getEmail() {
130+
return email;
131+
}
132+
133+
public void setEmail(String email) {
134+
this.email = email;
135+
}
136+
137+
public String getGroup() {
138+
return group;
139+
}
140+
141+
public void setGroup(String group) {
142+
this.group = group;
143+
}
144+
}

0 commit comments

Comments
 (0)