Skip to content

Commit 0cb2b7b

Browse files
committed
#2438 add model for security related information, change general settings json and add function to retrieve security settings (model <-> json)
1 parent 91a16ff commit 0cb2b7b

6 files changed

Lines changed: 164 additions & 89 deletions

File tree

Components/AAA/BExIS.Security.Services/Subjects/UserManager.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using BExIS.Security.Entities.Subjects;
22
using BExIS.Security.Services.Authentication;
33
using BExIS.Security.Services.Utilities;
4+
using BExIS.Utils.Config;
5+
using BExIS.Utils.Config.Configurations;
46
using BExIS.Utils.NH.Querying;
57
using Microsoft.AspNet.Identity;
68
using Microsoft.AspNet.Identity.Owin;
@@ -16,23 +18,26 @@ namespace BExIS.Security.Services.Subjects
1618
{
1719
public class UserManager : UserManager<User, long>
1820
{
21+
private SecurityConfiguration _securityConfiguration;
1922
public UserManager(IUserStore<User, long> store): base(store)
2023
{
24+
_securityConfiguration = GeneralSettings.SecurityConfiguration;
25+
2126
// Configure validation logic for usernames
2227
UserValidator = new UserValidator<User, long>(this)
2328
{
24-
AllowOnlyAlphanumericUserNames = false,
25-
RequireUniqueEmail = true
29+
AllowOnlyAlphanumericUserNames = _securityConfiguration.UserValidatorConfiguration.AllowOnlyAlphanumericUserNames,
30+
RequireUniqueEmail = _securityConfiguration.UserValidatorConfiguration.RequireUniqueEmail
2631
};
2732

2833
// Configure validation logic for passwords
2934
PasswordValidator = new PasswordValidator
3035
{
31-
RequiredLength = 12,
32-
RequireNonLetterOrDigit = true,
33-
RequireDigit = true,
34-
RequireLowercase = true,
35-
RequireUppercase = true
36+
RequiredLength = _securityConfiguration.PasswordValidatorConfiguration.RequiredLength,
37+
RequireNonLetterOrDigit = _securityConfiguration.PasswordValidatorConfiguration.RequireNonLetterOrDigit,
38+
RequireDigit = _securityConfiguration.PasswordValidatorConfiguration.RequireDigit,
39+
RequireLowercase = _securityConfiguration.PasswordValidatorConfiguration.RequireLowercase,
40+
RequireUppercase = _securityConfiguration.PasswordValidatorConfiguration.RequireUppercase
3641
};
3742

3843
// Configure user lockout defaults

Components/AAA/BExIS.Security.Services/Subjects/UserStore.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using BExIS.Security.Entities.Authentication;
22
using BExIS.Security.Entities.Authorization;
33
using BExIS.Security.Entities.Subjects;
4-
using BExIS.Utils.NH.Querying;
54
using Microsoft.AspNet.Identity;
6-
using NHibernate;
7-
using Owin.Security.Providers.Orcid.Message;
85
using System;
96
using System.Collections.Generic;
107
using System.Data;

Components/Utils/BExIS.Utils.Config/BExIS.Utils.Config.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="Configurations\CurationConfiguration.cs" />
7272
<Compile Include="Configurations\JwtConfiguration.cs" />
7373
<Compile Include="Configurations\LdapConfiguration.cs" />
74+
<Compile Include="Configurations\SecurityConfiguration.cs" />
7475
<Compile Include="Configurations\SmtpConfiguration.cs" />
7576
<Compile Include="GeneralSettings.cs" />
7677
<Compile Include="Properties\AssemblyInfo.cs" />
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace BExIS.Utils.Config.Configurations
9+
{
10+
public class SecurityConfiguration
11+
{
12+
[JsonProperty("userValidatorConfiguration")]
13+
public UserValidatorConfiguration UserValidatorConfiguration { get; set; }
14+
15+
[JsonProperty("passwordValidatorConfiguration")]
16+
public PasswordValidatorConfiguration PasswordValidatorConfiguration { get; set; }
17+
}
18+
19+
public class UserValidatorConfiguration
20+
{
21+
[JsonProperty("allowOnlyAlphanumericUserNames")]
22+
public bool AllowOnlyAlphanumericUserNames { get; set; }
23+
24+
[JsonProperty("requireUniqueEmail")]
25+
public bool RequireUniqueEmail { get; set; }
26+
}
27+
28+
public class PasswordValidatorConfiguration
29+
{
30+
[JsonProperty("requiredLength")]
31+
public int RequiredLength { get; set; }
32+
33+
[JsonProperty("requireNonLetterOrDigit")]
34+
public bool RequireNonLetterOrDigit { get; set; }
35+
36+
[JsonProperty("requireDigit")]
37+
public bool RequireDigit { get; set; }
38+
39+
[JsonProperty("requireLowercase")]
40+
public bool RequireLowercase { get; set; }
41+
42+
[JsonProperty("requireUppercase")]
43+
public bool RequireUppercase { get; set; }
44+
}
45+
}

Components/Utils/BExIS.Utils.Config/GeneralSettings.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ public static string FAQ
124124
}
125125
}
126126

127+
public static SecurityConfiguration SecurityConfiguration
128+
{
129+
get
130+
{
131+
return JsonConvert.DeserializeObject<SecurityConfiguration>(GetValueByKey("security").ToString());
132+
}
133+
}
134+
127135
public static JwtConfiguration JwtConfiguration
128136
{
129137
get

Console/BExIS.Web.Shell/General.Settings.json

Lines changed: 98 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@
1010
"type": "String",
1111
"description": "(Short) name of the BEXIS2 instance. The name is e.g., used in the breadcrumb or as prefix in emails sent via the system. Avoid special characters or to long names."
1212
},
13+
{
14+
"key": "security",
15+
"title": "Security",
16+
"value": {
17+
"userValidatorConfiguration": {
18+
"allowOnlyAlphanumericUserNames": true,
19+
"requireUniqueEmail": true
20+
},
21+
"passwordValidatorConfiguration": {
22+
"requiredLength": 8,
23+
"requireDigit": true,
24+
"requireLowercase": true,
25+
"requireUppercase": true,
26+
"requireNonAlphanumeric": false
27+
}
28+
},
29+
"type": "JSON",
30+
"description": "Security Settings."
31+
},
1332
{
1433
"key": "jwt",
1534
"title": "JWT",
@@ -19,7 +38,7 @@
1938
"validateIssuer": true,
2039
"validAudience": "http://localhost:3000",
2140
"validIssuer": "https://localhost:7041",
22-
"issuerSigningKey": "",
41+
"issuerSigningKey": "abcdefghijklmnopqrstuvwxyz",
2342
"validateLifetime": true,
2443
"validLifetime": 1
2544
},
@@ -117,84 +136,84 @@
117136
"value": "https://github.com/BEXIS2/Core/wiki/FAQ"
118137
}
119138
]
120-
},
121-
{
122-
"key": "landingPage",
123-
"title": "Landing Page (without login)",
124-
"value": "ddm, publicsearch, index",
125-
"type": "String",
126-
"description": "User is not logging in -> app goes to e.g. (ddm, publicsearch, index). If no destination is entered, the landingpage.htm is loaded from the tenant/content/landingpage.htm"
127-
},
128-
{
129-
"key": "showMenuOnLandingPage",
130-
"title": "Show menu on landing page",
131-
"value": "true",
132-
"type": "Boolean",
133-
"description": "Show or hide menu on your own created landing page"
134-
},
135-
{
136-
"key": "showHeaderOnLandingPage",
137-
"title": "Show header on landing page",
138-
"value": "true",
139-
"type": "Boolean",
140-
"description": "Show or hide header on your own created landing page"
141-
},
142-
{
143-
"key": "showFooterOnLandingPage",
144-
"title": "Show footer on landing page",
145-
"value": "true",
146-
"type": "Boolean",
147-
"description": "Show or hide footer on your own created landing page"
148-
},
149-
{
150-
"key": "landingPageForUsers",
151-
"title": "Landing Page after login for users with permission",
152-
"value": "ddm, search, index",
153-
"type": "String",
154-
"description": "User logged in, but does not have permission to view the page; shell, home, nopermission is by default; Alternatives must be in a module NOT shell"
155-
},
156-
{
157-
"key": "landingPageForUsersNoPermission",
158-
"title": "Landing Page after login for users with no permission",
159-
"value": "shell, home, nopermission",
160-
"type": "String",
161-
"description": "Landing page for users, after logging in successfully without permission."
162-
},
163-
{
164-
"key": "systemEmail",
165-
"title": "System E-Mail Address",
166-
"value": "david.schoene@uni-jena.de",
167-
"type": "String",
168-
"description": "All administrative information will be sent to this email."
169-
},
170-
{
171-
"key": "usePersonEmailAttributeName",
172-
"title": "Use Person E-Mail Attribute Name",
173-
"value": false,
174-
"type": "Boolean",
175-
"description": "To activate the linkage between between user email and a party email set Use Person E-Mail Attribute Name to true and define the party party attribute. If one of the email addresses is changed the other is changed as well."
176-
},
177-
{
178-
"key": "personEmailAttributeName",
179-
"title": "Person E-Mail Attribute Name",
180-
"value": "Email",
181-
"type": "String",
182-
"description": "To activate the linkage between between user email and a party email set Use Person E-Mail Attribute Name to true and define the party party attribute. If one of the email addresses is changed the other is changed as well."
183-
},
184-
{
185-
"key": "useMultimediaModule",
186-
"title": "Use Multimedia Module?",
187-
"value": true,
188-
"type": "Boolean",
189-
"description": "This flag turns on/off the Multimedia Module."
190-
},
191-
{
192-
"key": "faq",
193-
"title": "FAQ",
194-
"value": "https://github.com/BEXIS2/Core/wiki/FAQ",
195-
"type": "String",
196-
"description": "FAQ URL. Can link to an external page."
197-
}
139+
},
140+
{
141+
"key": "landingPage",
142+
"title": "Landing Page (without login)",
143+
"value": "ddm, publicsearch, index",
144+
"type": "String",
145+
"description": "User is not logging in -> app goes to e.g. (ddm, publicsearch, index). If no destination is entered, the landingpage.htm is loaded from the tenant/content/landingpage.htm"
146+
},
147+
{
148+
"key": "showMenuOnLandingPage",
149+
"title": "Show menu on landing page",
150+
"value": "true",
151+
"type": "Boolean",
152+
"description": "Show or hide menu on your own created landing page"
153+
},
154+
{
155+
"key": "showHeaderOnLandingPage",
156+
"title": "Show header on landing page",
157+
"value": "true",
158+
"type": "Boolean",
159+
"description": "Show or hide header on your own created landing page"
160+
},
161+
{
162+
"key": "showFooterOnLandingPage",
163+
"title": "Show footer on landing page",
164+
"value": "true",
165+
"type": "Boolean",
166+
"description": "Show or hide footer on your own created landing page"
167+
},
168+
{
169+
"key": "landingPageForUsers",
170+
"title": "Landing Page after login for users with permission",
171+
"value": "ddm, search, index",
172+
"type": "String",
173+
"description": "User logged in, but does not have permission to view the page; shell, home, nopermission is by default; Alternatives must be in a module NOT shell"
174+
},
175+
{
176+
"key": "landingPageForUsersNoPermission",
177+
"title": "Landing Page after login for users with no permission",
178+
"value": "shell, home, nopermission",
179+
"type": "String",
180+
"description": "Landing page for users, after logging in successfully without permission."
181+
},
182+
{
183+
"key": "systemEmail",
184+
"title": "System E-Mail Address",
185+
"value": "david.schoene@uni-jena.de",
186+
"type": "String",
187+
"description": "All administrative information will be sent to this email."
188+
},
189+
{
190+
"key": "usePersonEmailAttributeName",
191+
"title": "Use Person E-Mail Attribute Name",
192+
"value": false,
193+
"type": "Boolean",
194+
"description": "To activate the linkage between between user email and a party email set Use Person E-Mail Attribute Name to true and define the party party attribute. If one of the email addresses is changed the other is changed as well."
195+
},
196+
{
197+
"key": "personEmailAttributeName",
198+
"title": "Person E-Mail Attribute Name",
199+
"value": "Email",
200+
"type": "String",
201+
"description": "To activate the linkage between between user email and a party email set Use Person E-Mail Attribute Name to true and define the party party attribute. If one of the email addresses is changed the other is changed as well."
202+
},
203+
{
204+
"key": "useMultimediaModule",
205+
"title": "Use Multimedia Module?",
206+
"value": true,
207+
"type": "Boolean",
208+
"description": "This flag turns on/off the Multimedia Module."
209+
},
210+
{
211+
"key": "faq",
212+
"title": "FAQ",
213+
"value": "https://github.com/BEXIS2/Core/wiki/FAQ",
214+
"type": "String",
215+
"description": "FAQ URL. Can link to an external page."
216+
}
198217

199218
]
200219
}

0 commit comments

Comments
 (0)