Skip to content

Commit

Permalink
refactor: update properties string log
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-Guillemin committed Oct 18, 2023
1 parent 61fa11e commit b75dfcd
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 176 deletions.
26 changes: 24 additions & 2 deletions src/main/java/fr/recia/glc/GlcApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,36 @@
*/
package fr.recia.glc;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@SpringBootApplication
public class GlcApplication {

public static void main(String[] args) {
SpringApplication.run(GlcApplication.class, args);
public static void main(String[] args) throws UnknownHostException {
SpringApplication app = new SpringApplication(GlcApplication.class);
app.setBannerMode(Banner.Mode.OFF);

Environment env = app.run(args).getEnvironment();
log.info(
"Access URLs:" +
"\n----------------------------------------------------------" +
"\n\tLocal: \t\thttp://127.0.0.1:{}" +
"\n\tExternal: \thttp://{}:{}" +
"\n\tProfiles: \t{}" +
"\n----------------------------------------------------------",
env.getProperty("server.port"),
InetAddress.getLocalHost().getHostAddress(),
env.getProperty("server.port"),
env.getProperty("spring.profiles.active")
);
}

}
6 changes: 3 additions & 3 deletions src/main/java/fr/recia/glc/configuration/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ private Constants() {

public static final String SARAPISUI_ = "SarapisUi_";
public static final String SANS_OBJET = "SANS OBJET";
public static final String PROPERTIES_TO_JSON_DELIMITER = "\", \"";
public static final String PROPERTIES_TO_JSON_PREFIX = "[ \"";
public static final String PROPERTIES_TO_JSON_SUFFIX = "\" ]";
public static final String JSON_ARRAY_DELIMITER = "\", \"";
public static final String JSON_ARRAY_PREFIX = "[ \"";
public static final String JSON_ARRAY_SUFFIX = "\" ]";

public static final String SPRING_PROFILE_DEVELOPMENT = "dev";
public static final String SPRING_PROFILE_PRODUCTION = "prod";
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/fr/recia/glc/configuration/GLCProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ private void init() throws JsonProcessingException {

@Override
public String toString() {
return "{\n"
+ cas + ",\n"
+ cors + ",\n"
+ customConfig + ",\n"
+ security + ",\n"
+ admins + ",\n"
+ users + ",\n"
+ mail + ",\n"
+ authorizedServices + ",\n"
+ metrics + ",\n"
+ ldap
+ "\n}";
return "{\n" +
"\"cas\" : " + cas + "," +
"\n\"cors\" : " + cors + "," +
"\n\"customConfig\" : " + customConfig + "," +
"\n\"security\" : " + security + "," +
"\n\"admins\" : " + admins + "," +
"\n\"users\" : " + users + "," +
"\n\"mail\" : " + mail + "," +
"\n\"authorizedServices\" : " + authorizedServices + "," +
"\n\"metrics\" : " + metrics + "," +
"\n\"ldap\" : " + ldap +
"\n}";
}

}
50 changes: 39 additions & 11 deletions src/main/java/fr/recia/glc/configuration/LDAPConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public LdapContextSource contextSource() {
ldapCtx.setPassword(ldapProperties.getContextSource().getPassword());
ldapCtx.setPooled(ldapProperties.getContextSource().isNativePooling());
log.debug("LDAPContext is configured with properties {}", ldapProperties.getContextSource());

return ldapCtx;
}

Expand All @@ -75,6 +76,7 @@ public LdapTemplate ldapTemplate() {
ldapTpl.setIgnoreNameNotFoundException(ldapProperties.getLdapTemplate().isIgnoreNameNotFoundException());
ldapTpl.setIgnorePartialResultException(ldapProperties.getLdapTemplate().isIgnorePartialResultException());
ldapTpl.setIgnoreSizeLimitExceededException(ldapProperties.getLdapTemplate().isIgnoreSizeLimitExceededException());

return ldapTpl;
}

Expand All @@ -88,15 +90,20 @@ public ExternalUserHelper externalUserHelper() {
ldapProperties.getUserBranch().getGroupAttribute(),
ldapProperties.getUserBranch().getOtherBackendAttributes(),
ldapProperties.getUserBranch().getOtherDisplayedAttributes(),
ldapProperties.getUserBranch().getBaseDN());
ldapProperties.getUserBranch().getBaseDN()
);
log.debug("LdapAttributes for Users configured : {}", ldapUh);

return ldapUh;
}

@Bean
public ExternalGroupHelper externalGroupHelper() {
log.debug("Configure bean ExternalGroupHelper with LDAP attributes");
Assert.notNull(ldapProperties.getGroupBranch(), "Use of LDAP group branch require 'app.ldap.groupBranch.*' properties configured !");
Assert.notNull(
ldapProperties.getGroupBranch(),
"Use of LDAP group branch require 'app.ldap.groupBranch.*' properties configured !"
);
ExternalGroupHelper ldapUh = new ExternalGroupHelper(
ldapProperties.getGroupBranch().getIdAttribute(),
ldapProperties.getGroupBranch().getDisplayNameAttribute(),
Expand All @@ -112,43 +119,64 @@ public ExternalGroupHelper externalGroupHelper() {
ldapProperties.getGroupBranch().isResolveUserMembersByUserAttributes(),
ldapProperties.getGroupBranch().getDontResolveMembersWithGroupPattern(),
ldapProperties.getGroupBranch().getOtherDisplayedAttributes(),
ldapProperties.getGroupBranch().getBaseDN());
ldapProperties.getGroupBranch().getBaseDN()
);
log.debug("LdapAttributes for Groups configured : {}", ldapUh);

return ldapUh;
}

@Bean
public IExternalGroupDao ldapExternalGroupDao(IExternalUserDao externalUserDao, LdapTemplate ldapTemplate) {
log.debug("Configuring IExternalGroupDao with LDAP DAO");
Assert.notNull(ldapProperties.getGroupBranch(), "Use of Group Branch require 'app.ldap.groupBranch.*' properties configured !");
Assert.notNull(
ldapProperties.getGroupBranch(),
"Use of Group Branch require 'app.ldap.groupBranch.*' properties configured !"
);
List<IExternalGroupDisplayNameFormatter> formatters = Lists.newLinkedList();
// should be run firstly !
formatters.add(new LdapGroupRegexpDisplayNameFormatter(externalGroupHelper()));
for (GroupRegexProperties grp : ldapProperties.getGroupBranch().getNameFormatters()) {
formatters.add(new LdapGroupRegexpDisplayNameFormatterESCO(externalGroupHelper(), grp.getGroupMatcher(),
grp.getGroupNameRegex(), grp.getGroupNameIndex(), grp.getGroupRecomposerSeparator(), grp.getGroupSuffixeToAppend()));
formatters.add(new LdapGroupRegexpDisplayNameFormatterESCO(
externalGroupHelper(),
grp.getGroupMatcher(),
grp.getGroupNameRegex(),
grp.getGroupNameIndex(),
grp.getGroupRecomposerSeparator(),
grp.getGroupSuffixeToAppend()
));
}
//should be run at final
formatters.add(new LdapGroupRegexpDisplayNameFormatterESCOReplace());

List<IGroupMemberDesigner> designers = Lists.newArrayList();
for (GroupDesignerProperties grp : ldapProperties.getGroupBranch().getDesigners()) {
designers.add(new LdapGroupAttachMemberDesignerImpl(externalGroupHelper(), grp.getGroupRootPattern(),
grp.getGroupAttachEndMatch(), grp.getGroupToAttachEndPattern()));
designers.add(new LdapGroupAttachMemberDesignerImpl(
externalGroupHelper(),
grp.getGroupRootPattern(),
grp.getGroupAttachEndMatch(),
grp.getGroupToAttachEndPattern()
));
}

return new LdapGroupDaoImpl(ldapTemplate, externalGroupHelper(), formatters, externalUserDao, designers, ldapProperties);
}

@Bean
public IStructureLoader loadedStructure(IExternalGroupDao externalGroupDao){
public IStructureLoader loadedStructure(IExternalGroupDao externalGroupDao) {
log.debug("Loading Structure extracted from groups");
IStructureLoader loader = new StructureLoaderImpl(externalGroupDao);

return loader;
}

// @Bean
// public IGroupService ldapGroupService(IPermissionService permissionService, TreeJSDTOFactory treeJSDTOFactory, UserDTOFactory userDTOFactory,
// SubscriberService subscriberService, FilterRepository filterRepository, ContextService contextService, IExternalGroupDao externalGroupDao) {
// public IGroupService ldapGroupService(
// IPermissionService permissionService, TreeJSDTOFactory treeJSDTOFactory, UserDTOFactory userDTOFactory,
// SubscriberService subscriberService, FilterRepository filterRepository, ContextService contextService,
// IExternalGroupDao externalGroupDao
// ) {
// return new GroupService(permissionService, treeJSDTOFactory, userDTOFactory, externalGroupDao, subscriberService, filterRepository, contextService);
// }

}
30 changes: 20 additions & 10 deletions src/main/java/fr/recia/glc/configuration/MethodSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public RoleHierarchy roleHierarchy() {
RoleHierarchyImpl rhi = new RoleHierarchyImpl();
rhi.setHierarchy(
AuthoritiesConstants.ADMIN + " > " +
AuthoritiesConstants.USER + " > " +
AuthoritiesConstants.AUTHENTICATED + " > " +
AuthoritiesConstants.ANONYMOUS
AuthoritiesConstants.USER + " > " +
AuthoritiesConstants.AUTHENTICATED + " > " +
AuthoritiesConstants.ANONYMOUS
);

return rhi;
Expand Down Expand Up @@ -108,28 +108,38 @@ public IAuthoritiesDefinition mainRolesDefs() {

final String userAdmin = glcProperties.getAdmins().getUserName();
if (userAdmin != null && !userAdmin.isEmpty()) {
final UserAttributesEvaluation uae1 = new UserAttributesEvaluation("uid", userAdmin, StringEvaluationMode.EQUALS);
final UserAttributesEvaluation uae1 =
new UserAttributesEvaluation("uid", userAdmin, StringEvaluationMode.EQUALS);
set.add(uae1);
}

final String groupAdmin = glcProperties.getAdmins().getGroupName();
if (groupAdmin != null && !groupAdmin.isEmpty()) {
final UserAttributesEvaluation uae2 = new UserMultivaluedAttributesEvaluation("isMemberOf", groupAdmin, StringEvaluationMode.EQUALS);
final UserAttributesEvaluation uae2 =
new UserMultivaluedAttributesEvaluation("isMemberOf", groupAdmin, StringEvaluationMode.EQUALS);
set.add(uae2);
}

Assert.isTrue(set.size() > 0, "Properties that define admins aren't set in properties, there are needed to define an Admin user" +
", name should be 'app.admins.userName' or 'app.admins.groupName'");
Assert.isTrue(
!set.isEmpty(),
"Properties that define admins aren't set in properties, there are needed to define an Admin user," +
" name should be 'app.admins.userName' or 'app.admins.groupName'"
);

OperatorEvaluation admins = new OperatorEvaluation(OperatorType.OR, set);
defs.setAdmins(admins);

final String groupUsers = glcProperties.getUsers().getGroupName();
UserMultivaluedAttributesEvaluation umae = new UserMultivaluedAttributesEvaluation("isMemberOf", groupUsers, StringEvaluationMode.MATCH);
UserMultivaluedAttributesEvaluation umae =
new UserMultivaluedAttributesEvaluation("isMemberOf", groupUsers, StringEvaluationMode.MATCH);
defs.setUsers(umae);

Assert.isTrue(!groupUsers.isEmpty(), "Properties that define users aren't set in properties, there are needed to define all access users" +
", name should be 'app.users.groupName'");
Assert.isTrue(
!groupUsers.isEmpty(),
"Properties that define users aren't set in properties, there are needed to define all access users," +
" name should be 'app.users.groupName'"
);

return defs;
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/fr/recia/glc/configuration/bean/CASProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public class CASProperties {

@Override
public String toString() {
return "\"CASProperties\": {"
+ "\n\t\"urlPrefix\": \"" + urlPrefix + "\""
+ ",\n\t\"urlLogin\": \"" + urlLogin + "\""
+ ",\n\t\"urlLogout\": \"" + urlLogout + "\""
+ "\n}";
return "{" +
"\n\t\"CASProperties\": {" +
"\n\t\t\"urlPrefix\": \"" + urlPrefix + "\"," +
"\n\t\t\"urlLogin\": \"" + urlLogin + "\"," +
"\n\t\t\"urlLogout\": \"" + urlLogout + "\"" +
"\n\t}" +
"\n}";
}

}
30 changes: 16 additions & 14 deletions src/main/java/fr/recia/glc/configuration/bean/CorsProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import java.util.List;
import java.util.stream.Collectors;

import static fr.recia.glc.configuration.Constants.PROPERTIES_TO_JSON_DELIMITER;
import static fr.recia.glc.configuration.Constants.PROPERTIES_TO_JSON_PREFIX;
import static fr.recia.glc.configuration.Constants.PROPERTIES_TO_JSON_SUFFIX;
import static fr.recia.glc.configuration.Constants.JSON_ARRAY_DELIMITER;
import static fr.recia.glc.configuration.Constants.JSON_ARRAY_PREFIX;
import static fr.recia.glc.configuration.Constants.JSON_ARRAY_SUFFIX;

@Data
public class CorsProperties {
Expand All @@ -36,21 +36,23 @@ public class CorsProperties {

@Override
public String toString() {
return "\"CorsProperties\": {" +
"\n\t\"enable\": " + enable +
",\n\t\"allowCredentials\": " + allowCredentials +
",\n\t\"allowedOrigins\": " + allowedOrigins.stream()
return "{" +
"\n\t\"CorsProperties\": {" +
"\n\t\t\"enable\": " + enable + "," +
"\n\t\t\"allowCredentials\": " + allowCredentials + "," +
"\n\t\t\"allowedOrigins\": " + allowedOrigins.stream()
.map(String::valueOf)
.collect(Collectors.joining(PROPERTIES_TO_JSON_DELIMITER, PROPERTIES_TO_JSON_PREFIX, PROPERTIES_TO_JSON_SUFFIX)) +
",\n\t\"exposedHeaders\": " + exposedHeaders.stream()
.collect(Collectors.joining(JSON_ARRAY_DELIMITER, JSON_ARRAY_PREFIX, JSON_ARRAY_SUFFIX)) + "," +
"\n\t\t\"exposedHeaders\": " + exposedHeaders.stream()
.map(String::valueOf)
.collect(Collectors.joining(PROPERTIES_TO_JSON_DELIMITER, PROPERTIES_TO_JSON_PREFIX, PROPERTIES_TO_JSON_SUFFIX)) +
",\n\t\"allowedHeaders\": " + allowedHeaders.stream()
.collect(Collectors.joining(JSON_ARRAY_DELIMITER, JSON_ARRAY_PREFIX, JSON_ARRAY_SUFFIX)) + "," +
"\n\t\t\"allowedHeaders\": " + allowedHeaders.stream()
.map(String::valueOf)
.collect(Collectors.joining(PROPERTIES_TO_JSON_DELIMITER, PROPERTIES_TO_JSON_PREFIX, PROPERTIES_TO_JSON_SUFFIX)) +
",\n\t\"allowedMethods\": " + allowedMethods.stream()
.collect(Collectors.joining(JSON_ARRAY_DELIMITER, JSON_ARRAY_PREFIX, JSON_ARRAY_SUFFIX)) + "," +
"\n\t\t\"allowedMethods\": " + allowedMethods.stream()
.map(String::valueOf)
.collect(Collectors.joining(PROPERTIES_TO_JSON_DELIMITER, PROPERTIES_TO_JSON_PREFIX, PROPERTIES_TO_JSON_SUFFIX)) +
.collect(Collectors.joining(JSON_ARRAY_DELIMITER, JSON_ARRAY_PREFIX, JSON_ARRAY_SUFFIX)) +
"\n\t}" +
"\n}";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import java.util.List;
import java.util.stream.Collectors;

import static fr.recia.glc.configuration.Constants.PROPERTIES_TO_JSON_DELIMITER;
import static fr.recia.glc.configuration.Constants.PROPERTIES_TO_JSON_PREFIX;
import static fr.recia.glc.configuration.Constants.PROPERTIES_TO_JSON_SUFFIX;
import static fr.recia.glc.configuration.Constants.JSON_ARRAY_DELIMITER;
import static fr.recia.glc.configuration.Constants.JSON_ARRAY_PREFIX;
import static fr.recia.glc.configuration.Constants.JSON_ARRAY_SUFFIX;

@Data
public class CustomConfigProperties {
Expand All @@ -34,19 +34,21 @@ public class CustomConfigProperties {

@Override
public String toString() {
return "\"CustomConfigProperties\": {" +
"\n\t\"administrative\": " + filiereAdministrative.stream()
return "{" +
"\n\t\"CustomConfigProperties\": {" +
"\n\t\t\"administrative\": " + filiereAdministrative.stream()
.map(String::valueOf)
.collect(Collectors.joining(PROPERTIES_TO_JSON_DELIMITER, PROPERTIES_TO_JSON_PREFIX, PROPERTIES_TO_JSON_SUFFIX)) +
",\n\t\"teaching\": " + filiereTeaching.stream()
.collect(Collectors.joining(JSON_ARRAY_DELIMITER, JSON_ARRAY_PREFIX, JSON_ARRAY_SUFFIX)) + "," +
"\n\t\t\"teaching\": " + filiereTeaching.stream()
.map(String::valueOf)
.collect(Collectors.joining(PROPERTIES_TO_JSON_DELIMITER, PROPERTIES_TO_JSON_PREFIX, PROPERTIES_TO_JSON_SUFFIX)) +
",\n\t\"sourcesExternalAll\": " + sourcesExternalAll.stream()
.collect(Collectors.joining(JSON_ARRAY_DELIMITER, JSON_ARRAY_PREFIX, JSON_ARRAY_SUFFIX)) + "," +
"\n\t\t\"sourcesExternalAll\": " + sourcesExternalAll.stream()
.map(String::valueOf)
.collect(Collectors.joining(PROPERTIES_TO_JSON_DELIMITER, PROPERTIES_TO_JSON_PREFIX, PROPERTIES_TO_JSON_SUFFIX)) +
",\n\t\"sourcesExternal4login\": " + sourcesExternal4login.stream()
.collect(Collectors.joining(JSON_ARRAY_DELIMITER, JSON_ARRAY_PREFIX, JSON_ARRAY_SUFFIX)) + "," +
"\n\t\t\"sourcesExternal4login\": " + sourcesExternal4login.stream()
.map(String::valueOf)
.collect(Collectors.joining(PROPERTIES_TO_JSON_DELIMITER, PROPERTIES_TO_JSON_PREFIX, PROPERTIES_TO_JSON_SUFFIX)) +
.collect(Collectors.joining(JSON_ARRAY_DELIMITER, JSON_ARRAY_PREFIX, JSON_ARRAY_SUFFIX)) +
"\n\t}" +
"\n}";
}

Expand Down
Loading

0 comments on commit b75dfcd

Please sign in to comment.