Skip to content

Commit

Permalink
Making remote engine working with new comments feature
Browse files Browse the repository at this point in the history
  • Loading branch information
euskalhenriko committed Feb 28, 2024
1 parent d490e66 commit e2ec9f9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public KlabUser(AuthenticatedIdentity userData,String authToken, NetworkSession
this.parent = networkSession;
}

public KlabUser(String username, String token, List<GrantedAuthority> authorities) {
public KlabUser(String username, String jwtToken, String authToken, List<GrantedAuthority> authorities) {
super(username);
this.token = token;
this.id = jwtToken;
this.token = authToken;
this.authorities.addAll(authorities);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public boolean isEnabled() {
public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@Override
public <T extends IIdentity> T getParentIdentity(Class<T> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
}

// anonymous or local user
return new KlabUser(username, NameGenerator.newName(), authorities);
String tokens = NameGenerator.newName();
return new KlabUser(username, tokens, tokens, authorities);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private EngineAuthenticationResponse remoteEngine(ProfileResource profile, Strin
IdentityReference userIdentity = new IdentityReference(engine.getUsername(), engine.getEmailAddress(),
LocalDateTime.now().toString());
AuthenticatedIdentity authenticatedIdentity = new AuthenticatedIdentity(userIdentity, engine.getGroups(),
LocalDateTime.now().plusDays(90).toString(), engine.getToken());
LocalDateTime.now().plusDays(90).toString(), engine.getId());

ArrayList<GroupEntry> expired = profile.expiredGroupEntries();
ArrayList<GroupEntry> expiring = profile.expiringGroupEntries();
Expand Down Expand Up @@ -323,7 +323,7 @@ private EngineUser localEngineUser(ProfileResource profile) {
EngineUser engine = new EngineUser(profile.getUsername(), null);
String token = new JwtToken().createEngineJwtToken(profile);
engine.setEmailAddress(profile.getEmail());
engine.setToken(token);
engine.setId(token);
engine.getGroups().addAll(profile.getGroupsList());
return engine;
}
Expand All @@ -332,7 +332,7 @@ private EngineUser remoteEngineUser(ProfileResource profile) {
EngineUser engine = new EngineUser(profile.getUsername(), null);
String token = new JwtToken().createEngineJwtToken(profile);
engine.setEmailAddress(profile.getEmail());
engine.setToken(token);
engine.setId(token);
engine.getGroups().addAll(profile.getGroupsList());
return engine;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class HubUserProfile {
private List<GroupEntry> groupEntries;
@JsonInclude(Include.NON_NULL)
private String jwtToken;
@JsonInclude(Include.NON_NULL)
private String authToken;

public List<String> getRoles() {
return roles;
Expand Down Expand Up @@ -69,5 +71,13 @@ public String getJwtToken() {
public void setJwtToken(String jwtToken) {
this.jwtToken = jwtToken;
}

public String getAuthToken() {
return authToken;
}

public void setAuthToken(String authToken) {
this.authToken = authToken;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ public ResponseEntity<?> login(RemoteUserAuthenticationRequest login) {
}
if (result != null && result.getStatusCode().is2xxSuccessful()) {
HubUserProfile profile = result.getBody().getProfile();
String authToken = result.getBody().getAuthentication().getTokenString();
profile.setAuthToken(authToken);
RemoteUserLoginResponse response = getLoginResponse(profile, null);
String token = result.getBody().getAuthentication().getTokenString();
response.setAuthorization(token);
response.setAuthorization(authToken);
return ResponseEntity.status(HttpStatus.ACCEPTED).body(response);
} else {
throw new KlabAuthorizationException("Failed to login user: " + login.getUsername());
Expand Down Expand Up @@ -168,7 +169,8 @@ private Session processProfile(HubUserProfile profile) {
groups.add(group);
});

KlabUser user = new KlabUser(profile.getName(), profile.getJwtToken(), authorities);
KlabUser user = new KlabUser(profile.getName(), profile.getJwtToken(),
profile.getAuthToken(), authorities);
user.setEmailAddress(profile.getEmail());
user.getGroups().addAll(groups);

Expand Down

0 comments on commit e2ec9f9

Please sign in to comment.