use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class BoschIoTSuiteOAuthProviderAuthCodeTest method authenticateSuccessTest.
@Test
public void authenticateSuccessTest() {
when(userAccountService.getUser(any())).thenReturn(new User());
Authentication authentication = sut.authenticate(null, TOKEN);
assertTrue(authentication.isAuthenticated());
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class AccountControllerTest method updateAccount.
@Test
public void updateAccount() throws Exception {
this.repositoryServer.perform(put("/rest/accounts/" + USER_MODEL_CREATOR_NAME).content(testMail).with(userSysadmin)).andExpect(status().isOk());
User user = userRepository.findByUsername(USER_MODEL_CREATOR_NAME);
assertNotNull(user);
assertEquals(testMail, user.getEmailAddress());
this.repositoryServer.perform(put("/rest/accounts/doesnotexist").content(testMail).with(userSysadmin)).andExpect(status().isNotFound());
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class BoschIDOAuthProvider method createAuthentication.
/**
* Authenticates the user from the CIAM issued token by checking if the user is registered in the
* Repository
*/
@Override
public OAuth2Authentication createAuthentication(HttpServletRequest httpRequest, JwtToken accessToken) {
Map<String, Object> tokenPayload = accessToken.getPayloadMap();
Optional<String> email = Optional.ofNullable((String) tokenPayload.get(JWT_EMAIL));
Optional<String> name = Optional.ofNullable((String) tokenPayload.get(JWT_NAME)).map(str -> str.split("@")[0]);
String userId = getUserId(tokenPayload).orElseThrow(() -> new InvalidTokenException("Cannot generate a userId from your provided token. Maybe 'sub' or 'client_id' is not present in JWT token?"));
User user = userAccountService.getUser(userId);
if (user == null) {
throw new InvalidTokenException("User from token is not a registered user in the repository!");
}
return createAuthentication(this.ciamClientId, userId, name.orElse(userId), email.orElse(null), userNamespaceRoleService.getRolesOnAllNamespaces(user));
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class DefaultCommentService method notifyAllCommentAuthors.
private void notifyAllCommentAuthors(Comment comment, ModelInfo model) {
Set<String> recipients = new HashSet<>();
recipients.add(model.getAuthor());
List<Comment> existingComments = this.commentRepository.findByModelId(comment.getModelId());
for (Comment c : existingComments) {
recipients.add(c.getAuthor());
}
recipients.stream().filter(recipient -> !User.USER_ANONYMOUS.equalsIgnoreCase(recipient)).forEach(recipient -> {
User user = accountService.getUser(recipient);
if (user != null) {
notificationService.sendNotification(new CommentReplyMessage(user, model, comment.getContent()));
}
});
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class UserAccountListener method refreshUserContext.
public void refreshUserContext(String userId) {
if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (userId != null && !auth.getName().equals(userId)) {
return;
}
User user = userAccountService.getUser(auth.getName());
SpringUserUtils.refreshSpringSecurityUser(user, userNamespaceRoleService);
}
}
Aggregations