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

Kc change #1062

Merged
merged 18 commits into from
Jun 30, 2021
Prev Previous commit
Next Next commit
Minor canges
  • Loading branch information
Nolan Tellis committed Jun 20, 2021
commit 3717718d7fb2acdfa65bb05371bb157e74db8c91
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ public void onEvent(Event event) throws Exception {
public void onEvent(Event event) {
Session session = Sessions.getCurrent();

UserType userType = (UserType) Sessions.getCurrent().getAttribute("USER");
if (session == null || event.getData().equals(userType.getUsername())) {

if (session != null) {
session.invalidate();
Executions.sendRedirect("/j_spring_security_logout");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
HttpServletRequest req = (HttpServletRequest) request;
String requestPath = req.getRequestURI().substring(req.getContextPath().length());
HttpSession existingSession = req.getSession(false);

boolean isExistingSession = existingSession == null ? false
: existingSession.getAttribute("USER") == null ? false : true;

if (!useKeyCloak || FilterRegexUtil.isMatchingFilterRegex(requestPath)) {
if (!useKeyCloak || FilterRegexUtil.isMatchingFilterRegex(requestPath) || isExistingSession) {
chain.doFilter(request, response);
return;
}
Expand All @@ -80,11 +81,17 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
AccessToken token = context.getToken();

String userName = token.getPreferredUsername();
userName = userName == null ? token.getEmail() : userName;
String email = token.getEmail();
String givenName = token.getGivenName();
Copy link
Contributor

Choose a reason for hiding this comment

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

These two statements (givenName and lastName retrieval) can be moved after line 96 as only utilised there, or used in-line on line 97 directly. Reduces scope, and provides a slight performance improvement in the alternate use case (when userType != null).

String familyName = token.getFamilyName();

UserType userType = managerService.readUserByUsername(userName);
try {
userType = userType == null ? managerService.readUserByEmail(email) : userType;
} catch (Exception e1) {
// ignoreing for now.
}

if (Objects.isNull(userType)) {
userType = new UserType(userName, email, givenName, familyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class FilterRegexUtil {

static Pattern p = Pattern.compile("^/(zkau|zkau/.*|.*\\.css|.*\\.js"
+ "|.*\\.svg|.*\\.png|themes/.*|favicon\\.ico" + "|.*/css/.*)", Pattern.DOTALL);
+ "|.*\\.svg|.*\\.png|themes/.*|favicon\\.ico" + "|css/.*)", Pattern.DOTALL);

public static boolean isMatchingFilterRegex(String urlData) {
return p.matcher(urlData).matches();
Expand Down
8 changes: 3 additions & 5 deletions keycloak.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"realm": "apro",
"auth-server-url": "http://localhost:8080/auth/",
"auth-server-url": "https://test2-kc.apromore.org:8443/auth/",
"ssl-required": "external",
"resource": "apromore",
"credentials": {
"secret": "ecc2b2e3-4d56-47a9-9a55-4790535518c5"
},
"resource": "product-app",
"public-client": true,
"confidential-port": 0
}