Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openconnect #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Openconnect #35

wants to merge 1 commit into from

Conversation

frol2103
Copy link

@frol2103 frol2103 commented Feb 27, 2022

modification of app and configuration to use openconnect.
Have been tested with lghs keycloak.
Will be easier to read when the 2 other PR have been merged

@bendem
Copy link
Member

bendem commented Mar 7, 2022

Looks ok to me, I've left a few comments about code style and error handling.

Comment on lines 27 to 29
if(values.containsKey(attribute)){
return (String) values.get(attribute);
} else {
logger.error("Missing attribute " + attribute + " for user " +
values.entrySet().stream().map(e-> e.getKey() +":"+e.getValue())
.collect(Collectors.joining(";")));

throw new RuntimeException("Missing attribute " + attribute + " for user ");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(values.containsKey(attribute)){
return (String) values.get(attribute);
} else {
logger.error("Missing attribute " + attribute + " for user " +
values.entrySet().stream().map(e-> e.getKey() +":"+e.getValue())
.collect(Collectors.joining(";")));
throw new RuntimeException("Missing attribute " + attribute + " for user ");
}
var value = (String) values.get(attribute);
if (value == null) {
logger.error("Missing attribute {} for user {}", attribute, values);
throw new RuntimeException("Missing attribute " + attribute + " for user");
}
return value;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the log altogether because there already is a log after.
not particularly a fan of extracting a variable and checking directly for null but if you really want I can do it.

usersRecord
);

} catch( Exception e){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't try/catch the exception, you already logged everything required in getMandatory

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is other potential errors, I removed the log from getMandatory to not have a duplication of logs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is indeed other potential error. Spring will handle all of them just fine, leave exception handling to the framework, it will log what's required and display to the user what's required.


@Service
@RequiredArgsConstructor
public class SecurityUserService extends DefaultOAuth2UserService {

private final UserRepository userRepository;

private static final Logger logger = LoggerFactory.getLogger(SecurityUserService.class);

String getMandatory(Map<String, Object> values, String attribute){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
String getMandatory(Map<String, Object> values, String attribute){
private static String getMandatory(Map<String, Object> values, String attribute) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changé


@Service
@RequiredArgsConstructor
public class SecurityUserService extends DefaultOAuth2UserService {

private final UserRepository userRepository;

private static final Logger logger = LoggerFactory.getLogger(SecurityUserService.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use lombok to create loggers so there is no way to miss copy/pasta errors.

Example:


log.info("sending pending iban validation mail to {} people", admins.size());

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done



server:
forward-headers-strategy: framework
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use native unless we have a specific need, also, we already have server values at the top of the file, please combine them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combined. I have no way of testing native because I don't know what the tomcat config is in production.

token-uri: "https://members.lghs.be/oauth/token"
user-info-uri: "https://members.lghs.be/api/me"
client-id: "accounting"
client-secret: "f539b20e-048a-4d81-90bf-238477fb3ad6"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please never include secrets, even fake ones in configs. You never know who will copy paste and it makes debugging harder.
If you need those secrets, drop an application.yml in your work folder and gitignore it (I personally always run project with a CWD outside the git repository to avoid committing secrets by mistake).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fan of having additional configuration to do before launching a development environment. There is a lot of step before being able to launch the app and this can only introduce error between dev-env/prod or between two developer.
The other MR aims to have a init script, so that you can launch the init script, then docker-compose up and the dev-env is running without any other step (maybe add a line in the host file because I'm not fan of having root privileges to the scripts).
That being said, I understand the issue with having them in the app config file. I replaced them with env variables and defined them directly in the docker-compose.yaml file

@bendem
Copy link
Member

bendem commented Mar 7, 2022

This will require a change of the production config that's stored here: https://github.com/LgHS/infra/blob/main/playbooks/accounting.lghs.be/templates/application.yml.j2

@frol2103 frol2103 force-pushed the openconnect branch 3 times, most recently from 4dccacb to 981a6e1 Compare March 8, 2022 20:08
Copy link
Member

@bendem bendem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the changes but since this is auto deployed, the deployment needs to be updated first. Since I don't have a computer at the moment, it'll have to wait until I fix it.

@frol2103
Copy link
Author

frol2103 commented Apr 4, 2022

Ok thanks. We are thinking to do another quick change to allow to use historical uuid from the keycloak. I'll do another merge request for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants