This commit is contained in:
parent
cefcd14fda
commit
b0bff28194
3 changed files with 5 additions and 16 deletions
|
|
@ -91,7 +91,7 @@ public class KeycloakRestTemplateAuthenticationProvider implements Authenticatio
|
||||||
final KeycloakAccount account = new SimpleKeycloakAccount(principal, roles, skSession);
|
final KeycloakAccount account = new SimpleKeycloakAccount(principal, roles, skSession);
|
||||||
KeycloakAuthenticationToken keycloakAuthenticationToken = new KeycloakAuthenticationToken(account, false, realmRoles);
|
KeycloakAuthenticationToken keycloakAuthenticationToken = new KeycloakAuthenticationToken(account, false, realmRoles);
|
||||||
keycloakAuthenticationToken.setAuthenticated(true);
|
keycloakAuthenticationToken.setAuthenticated(true);
|
||||||
checkRightsAndCreate(principalName, accessToken.getId(), roles);
|
checkRightsAndCreate(principalName, roles);
|
||||||
return keycloakAuthenticationToken;
|
return keycloakAuthenticationToken;
|
||||||
|
|
||||||
} catch (VerificationException vex) {
|
} catch (VerificationException vex) {
|
||||||
|
|
@ -101,14 +101,14 @@ public class KeycloakRestTemplateAuthenticationProvider implements Authenticatio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkRightsAndCreate(String username, String id, Set<String> roles) {
|
private void checkRightsAndCreate(String username, Set<String> roles) {
|
||||||
|
|
||||||
log.debug("login successful: login {}, roles {}", username, String.join(";", roles));
|
log.debug("login successful: login {}, roles {}", username, String.join(";", roles));
|
||||||
//todo remove hardcode
|
//todo remove hardcode
|
||||||
if (roles.contains("admin") || roles.contains("default-roles-master")) {
|
if (roles.contains("admin") || roles.contains("default-roles-master")) {
|
||||||
String clientIp = currentHttpRequest != null ? currentHttpRequest.getRemoteAddr() : null;
|
String clientIp = currentHttpRequest != null ? currentHttpRequest.getRemoteAddr() : null;
|
||||||
String serverIp = currentHttpRequest != null ? currentHttpRequest.getLocalAddr() : null;
|
String serverIp = currentHttpRequest != null ? currentHttpRequest.getLocalAddr() : null;
|
||||||
userAutoCreation.sendUserInfo(username, id, roles, clientIp, serverIp);
|
userAutoCreation.sendUserInfo(username, roles, clientIp, serverIp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,10 @@ public class UserAuthProcessor {
|
||||||
this.operator = operator;
|
this.operator = operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendUserInfo(String username, String identifier, Collection<String> roles, String userIp, String serverIp) {
|
public void sendUserInfo(String identifier, Collection<String> roles, String userIp, String serverIp) {
|
||||||
UserAuthAction authEvent = new UserAuthAction();
|
UserAuthAction authEvent = new UserAuthAction();
|
||||||
UserAuthRequest requestData = authEvent.getAuthRequest();
|
UserAuthRequest requestData = authEvent.getAuthRequest();
|
||||||
requestData.setUsername(username);
|
requestData.setUsername(identifier);
|
||||||
requestData.setIdentifier(identifier);
|
|
||||||
requestData.setTime(Instant.now());
|
requestData.setTime(Instant.now());
|
||||||
requestData.setRoles(new ArrayList<>(roles));
|
requestData.setRoles(new ArrayList<>(roles));
|
||||||
requestData.setServerIp(serverIp + ":" + serverPort); //getServerAddress() + ":" + serverPort
|
requestData.setServerIp(serverIp + ":" + serverPort); //getServerAddress() + ":" + serverPort
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,6 @@ public class UserAuthRequest {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String username;
|
private String username;
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String identifier;
|
|
||||||
@JsonProperty
|
|
||||||
private List<String> roles = new ArrayList<>();
|
private List<String> roles = new ArrayList<>();
|
||||||
@JsonSerialize(using = InstantSerializer.class)
|
@JsonSerialize(using = InstantSerializer.class)
|
||||||
@JsonDeserialize(using = InstantDeserializer.class)
|
@JsonDeserialize(using = InstantDeserializer.class)
|
||||||
|
|
@ -34,14 +32,6 @@ public class UserAuthRequest {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdentifier() {
|
|
||||||
return identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdentifier(String identifier) {
|
|
||||||
this.identifier = identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getRoles() {
|
public List<String> getRoles() {
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue