Skip to content

Commit 1652628

Browse files
authored
Merge pull request #568 from fugerit-org/567-chore-add-property-for-security-hardening
feat: new option 'security-hardening' #567
2 parents a136b15 + 0af7ee8 commit 1652628

File tree

19 files changed

+399
-7
lines changed

19 files changed

+399
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- new security-hardening property <https://github.com/fugerit-org/fj-doc/issues/567>
13+
14+
### Fixed
15+
16+
- doc-language handling for AsciiDoc handler
17+
1018
## [8.17.2] - 2025-10-31
1119

1220
### Added

docs/html/doc_meta_info.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,29 @@ <h2 style="font-weight: bold;">Properties for generic metadata</h2>
347347
<td id="cell_15_4" style=" width: 5%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
348348
<p>8.15.0</p>
349349
</td>
350+
</tr>
351+
<tr>
352+
<td id="cell_16_0" style=" width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
353+
<span id="security-hardening"></span>
354+
<p style="font-style: italic;">security-hardening</p>
355+
</td>
356+
<td id="cell_16_1" style=" width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
357+
<p>If set to '0' (default) nothing change.
358+
Different values represents the hardening level.
359+
Currently supported values :
360+
'1' - Library version will not be shown in metadata.
361+
'max' - Maximum available level (currently equals '1')
362+
</p>
363+
</td>
364+
<td id="cell_16_2" style=" width: 25%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
365+
<p></p>
366+
</td>
367+
<td id="cell_16_3" style=" width: 10%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
368+
<p></p>
369+
</td>
370+
<td id="cell_16_4" style=" width: 5%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
371+
<p>8.17.3</p>
372+
</td>
350373
</tr>
351374
</tbody>
352375
</table>

fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/VenusVersion.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ private VenusVersion() {}
1313

1414
public static final String NOT_AVAILABLE = "NA";
1515

16-
public static final String VENUS_CREATOR = String.format( "%s (https://github.com/fugerit-org/fj-doc)", DocConfig.FUGERIT_VENUS_DOC );
16+
public static final String VENUS_CREATOR = String.format( "%s (https://venusdocs.fugerit.org)", DocConfig.FUGERIT_VENUS_DOC );
1717

1818
public static final String VENUS_PRODUCER_FORMAT = "%s (%s) over %s (%s)";
1919

20+
public static final String VENUS_PRODUCER_FORMAT_SH1 = "%s over %s";
21+
2022
public static Optional<String> getFjDocCoreVersion() {
2123
return getFjDocModuleVersion( FJ_DOC_BASE_ARTIFACT_ID );
2224
}

fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehelper/generic/GenericConsts.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,36 @@ private GenericConsts() {}
212212
*/
213213
public static final String DOC_TABLE_CHECK_INTEGRITY = "table-check-integrity";
214214

215+
/**
216+
* <a href="https://venusdocs.fugerit.org/docs/html/doc_meta_info.html#security-hardening">See 'security-hardening' documentation.</a>
217+
*/
218+
public static final String SECURITY_HARDENING = "security-hardening";
219+
220+
/**
221+
* This value disable security hardening (default)
222+
*/
223+
public static final String SECURITY_HARDENING_DISABLED = String.valueOf( SecurityHardeningConsts.SECURITY_HARDENING_DISABLED );
224+
225+
/**
226+
* Security hardening level 1
227+
*/
228+
public static final String SECURITY_HARDENING_1 = String.valueOf( SecurityHardeningConsts.SECURITY_HARDENING_1 );
229+
230+
/**
231+
* Security hardening level max (currently same as 1)
232+
*/
233+
public static final String SECURITY_HARDENING_MAX = "max";
234+
235+
/**
236+
* Security hardening level mapping to max (currently 1)
237+
*/
238+
public static final String SECURITY_HARDENING_CURRENT_MAX = SECURITY_HARDENING_1;
239+
240+
/**
241+
* Default security hardening option (0 - disabled)
242+
*/
243+
public static final String SECURITY_HARDENING_DEFAULT = SECURITY_HARDENING_DISABLED;
244+
215245
public static final boolean FAIL_WHEN_ELEMENT_NOT_FOUND_DEFAULT = Boolean.FALSE;
216246

217247
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.fugerit.java.doc.base.typehelper.generic;
2+
3+
public class SecurityHardeningConsts {
4+
5+
private SecurityHardeningConsts() {}
6+
7+
public static final int SECURITY_HARDENING_DISABLED = 0;
8+
9+
public static final int SECURITY_HARDENING_1 = 1;
10+
11+
12+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.fugerit.java.doc.base.typehelper.generic;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.fugerit.java.doc.base.model.DocBase;
5+
6+
import java.util.function.Supplier;
7+
8+
@Slf4j
9+
public class SecurityHardeningUtil {
10+
11+
private SecurityHardeningUtil() {}
12+
13+
private static String resolveSecurityHardeningInfo( String securityHardeningInfo ) {
14+
if ( GenericConsts.SECURITY_HARDENING_MAX.equalsIgnoreCase( securityHardeningInfo ) ) {
15+
return GenericConsts.SECURITY_HARDENING_CURRENT_MAX;
16+
} else {
17+
return securityHardeningInfo;
18+
}
19+
}
20+
21+
public static int findCurrentValue( DocBase docBase ) {
22+
return findCurrentValue( docBase.getStableInfo().getProperty(GenericConsts.SECURITY_HARDENING, GenericConsts.SECURITY_HARDENING_DEFAULT) );
23+
}
24+
25+
public static int findCurrentValue( String securityHardeningInfo ) {
26+
String securityHardening = resolveSecurityHardeningInfo( securityHardeningInfo );
27+
log.debug( "securityHardening : {}", securityHardening );
28+
try {
29+
return Integer.parseInt(securityHardening);
30+
} catch (NumberFormatException nfe) {
31+
log.warn( "failed to check option {} - {}", GenericConsts.SECURITY_HARDENING, nfe.getMessage() );
32+
}
33+
return SecurityHardeningConsts.SECURITY_HARDENING_DISABLED;
34+
}
35+
36+
public static <T> T applyHardening( DocBase docBase, int minimumSecurityHardening, Supplier<T> securityHardening, Supplier<T> noSecurityHardening) {
37+
return applyHardening( docBase.getStableInfo().getProperty(GenericConsts.SECURITY_HARDENING, GenericConsts.SECURITY_HARDENING_DEFAULT), minimumSecurityHardening, securityHardening, noSecurityHardening );
38+
}
39+
40+
public static <T> T applyHardening( String securityHardeningInfo, int minimumSecurityHardening, Supplier<T> securityHardening, Supplier<T> noSecurityHardening) {
41+
int valueSecurityHardening = SecurityHardeningUtil.findCurrentValue( securityHardeningInfo );
42+
if ( valueSecurityHardening >= minimumSecurityHardening) {
43+
return securityHardening.get();
44+
} else {
45+
return noSecurityHardening.get();
46+
}
47+
}
48+
49+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package test.org.fugerit.java.doc.base.typehelper.generic;
2+
3+
import org.fugerit.java.doc.base.model.DocBase;
4+
import org.fugerit.java.doc.base.typehelper.generic.GenericConsts;
5+
import org.fugerit.java.doc.base.typehelper.generic.SecurityHardeningConsts;
6+
import org.fugerit.java.doc.base.typehelper.generic.SecurityHardeningUtil;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Test;
9+
10+
class TestSecurityHardeningUtil {
11+
12+
@Test
13+
void testDefault() {
14+
Assertions.assertEquals( SecurityHardeningConsts.SECURITY_HARDENING_DISABLED, SecurityHardeningUtil.findCurrentValue( (String)null ) );
15+
}
16+
17+
@Test
18+
void testDisabled() {
19+
Assertions.assertEquals( SecurityHardeningConsts.SECURITY_HARDENING_DISABLED, SecurityHardeningUtil.findCurrentValue(GenericConsts.SECURITY_HARDENING_DISABLED) );
20+
}
21+
22+
@Test
23+
void testSH1() {
24+
Assertions.assertEquals( SecurityHardeningConsts.SECURITY_HARDENING_1, SecurityHardeningUtil.findCurrentValue(GenericConsts.SECURITY_HARDENING_1) );
25+
}
26+
27+
@Test
28+
void testSHMax() {
29+
Assertions.assertEquals( SecurityHardeningConsts.SECURITY_HARDENING_1, SecurityHardeningUtil.findCurrentValue(GenericConsts.SECURITY_HARDENING_MAX) );
30+
}
31+
32+
@Test
33+
void testSHNumberFormatExceptionSetToDefault() {
34+
Assertions.assertEquals( SecurityHardeningConsts.SECURITY_HARDENING_DISABLED, SecurityHardeningUtil.findCurrentValue( "not-a-number" ) );
35+
}
36+
37+
@Test
38+
void testDocBase() {
39+
DocBase docBase = new DocBase();
40+
docBase.getStableInfoSafe().setProperty( GenericConsts.SECURITY_HARDENING, GenericConsts.SECURITY_HARDENING_1);
41+
Assertions.assertEquals( SecurityHardeningConsts.SECURITY_HARDENING_1, SecurityHardeningUtil.findCurrentValue( docBase ) );
42+
}
43+
44+
private static final String YES = "YES";
45+
46+
private static final String NO = "NO";
47+
48+
@Test
49+
void testApplyNoSecurityHardening() {
50+
DocBase docBase = new DocBase();
51+
docBase.getStableInfoSafe().setProperty( GenericConsts.SECURITY_HARDENING, GenericConsts.SECURITY_HARDENING_DISABLED );
52+
String result = SecurityHardeningUtil.applyHardening( docBase, SecurityHardeningConsts.SECURITY_HARDENING_1, () -> YES, () -> NO );
53+
Assertions.assertEquals( NO, result );
54+
}
55+
56+
@Test
57+
void testApplySecurityHardening() {
58+
DocBase docBase = new DocBase();
59+
docBase.getStableInfoSafe().setProperty( GenericConsts.SECURITY_HARDENING, GenericConsts.SECURITY_HARDENING_1 );
60+
String result = SecurityHardeningUtil.applyHardening( GenericConsts.SECURITY_HARDENING_1 , SecurityHardeningConsts.SECURITY_HARDENING_1, () -> YES, () -> NO );
61+
Assertions.assertEquals( YES, result );
62+
}
63+
64+
}

fj-doc-freemarker/src/main/resources/fj_doc_freemarker_config/template/asciidoc.ftl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<#if (docBase.infoDocTitle)??>= ${docBase.infoDocTitle}</#if>
33
<#if (docBase.infoDocAuthor)??>${docBase.infoDocAuthor}</#if>
44
<#if (docBase.infoDocSubject)??>:description: ${docBase.infoDocSubject}</#if>
5-
<#if (docBase.infoDocSubject)??>:lang: ${docBase.infoDocLanguage}</#if>
5+
<#if (docBase.infoDocLanguage)??>:lang: ${docBase.infoDocLanguage}</#if>
6+
<#if (docBase.infoDocProducer)??>:generator: ${docBase.infoDocProducer}<#else>:generator: Venus Fugerit Doc over Apache FreeMarker</#if>
7+
<#if (docBase.infoDocCreator)??>:created-by: ${docBase.infoDocCreator}<#else>:created-by: Venus Fugerit Doc (https://venusdocs.fugerit.org)</#if>
68

79
<#list docBase.docBody.elementList as item>
810
<@doc_element.handleElement current=item/>

fj-doc-freemarker/src/main/resources/fj_doc_freemarker_config/template/html_doc.ftl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
<#if (docBase.stableInfo['html-charset'])??><meta charset="${docBase.stableInfo['html-charset']}"></#if>
1414
<#if (docBase.infoDocAuthor)??><meta name="author" content="${docBase.infoDocAuthor}"/></#if>
1515
<#if (docBase.infoDocSubject)??><meta name="description" content="${docBase.infoDocSubject}"/></#if>
16-
<#if (docBase.infoDocLanguage)??><meta http-equiv="content-language" content="${docBase.infoDocLanguage}"/></#if>
17-
<meta name="doc-version-compatibility" content="${comp}"/>
16+
<#if (docBase.infoDocLanguage)??><meta http-equiv="content-language" content="${docBase.infoDocLanguage}"/></#if>
17+
<#if (docBase.infoDocProducer)??><meta http-equiv="generator" content="${docBase.infoDocProducer}"/><#else><meta http-equiv="generator" content="Venus Fugerit Doc over Apache FreeMarker"/></#if>
18+
<#if (docBase.infoDocCreator)??><meta http-equiv="created-by" content="${docBase.infoDocCreator}"/><#else><meta http-equiv="created-by" content="Venus Fugerit Doc (https://venusdocs.fugerit.org)"/></#if>
19+
<meta name="doc-version-compatibility" content="${comp}"/>
1820
${docBase.stableInfo['html-add-to-head']!''}
1921
<#if (docBase.stableInfo['html-css-style'])??>
2022
<style type="text/css">

fj-doc-freemarker/src/test/resources/coverage/xml/asciidoc.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<info name="doc-subject">fj doc venus sample source xml</info>
1414
<info name="doc-author">fugerit79</info>
1515
<info name="doc-language">en</info>
16+
<info name="doc-producer">My AsciiDoc producer</info>
17+
<info name="doc-creator">My AsciiDoc creator</info>
1618
<!-- additional properties -->
1719
<info name="set-total-page">true</info>
1820
<info name="html-css-link">/css/test.css</info>

0 commit comments

Comments
 (0)