use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class ProfileController method create.
@PostMapping
public ProfileForm create(@Valid @RequestBody ProfileCreateForm profileCreateForm) {
UserEntity userEntity = mapper.mapForCreate(profileCreateForm);
UserEntity createdUserEntity = profileAppService.create(userEntity);
return mapper.mapToProfileForm(createdUserEntity);
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class ProfileController method update.
@PutMapping
public ProfileForm update(@AuthenticationPrincipal UserEntity loginUserEntity, @Valid @RequestBody ProfileUpdateForm profileUpdateForm) {
int id = loginUserEntity.getId();
UserEntity updatedUserEntity = profileAppService.update(id, profileUpdateForm);
return mapper.mapToProfileForm(updatedUserEntity);
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class AppSpecificMapper method mapToProfileForm.
public ProfileForm mapToProfileForm(UserEntity userEntity) {
ProfileForm profileForm = new ProfileForm();
profileForm.setId(userEntity.getId());
profileForm.setUserHandle(mapToBase64Url(userEntity.getUserHandle()));
profileForm.setFirstName(userEntity.getFirstName());
profileForm.setLastName(userEntity.getLastName());
profileForm.setEmailAddress(userEntity.getEmailAddress());
// authenticators
profileForm.setAuthenticators(new ArrayList<>());
mapToAuthenticatorFormList(userEntity.getAuthenticators(), profileForm.getAuthenticators());
profileForm.setSingleFactorAuthenticationAllowed(userEntity.getAuthorities().stream().anyMatch(authorityEntity -> authorityEntity.getAuthority().equals("SINGLE_FACTOR_AUTHN_ALLOWED")));
return profileForm;
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class WithMockWebAuthnUserSecurityContextFactory method createSecurityContext.
/**
* Create a {@link SecurityContext} given an Annotation.
*
* @param user the {@link WithMockWebAuthnUser} to create the {@link SecurityContext}
* from. Cannot be null.
* @return the {@link SecurityContext} to use. Cannot be null.
*/
@Override
public SecurityContext createSecurityContext(WithMockWebAuthnUser user) {
SecurityContext context = SecurityContextHolder.createEmptyContext();
List<AuthorityEntity> authorities = Arrays.stream(user.authorities()).map((name) -> new AuthorityEntity(null, name)).collect(Collectors.toList());
List<GroupEntity> groups = Arrays.stream(user.groups()).map(GroupEntity::new).collect(Collectors.toList());
List<AuthenticatorEntity> authenticatorEntities = Arrays.stream(user.authenticators()).map((name) -> {
AuthenticatorEntity authenticatorEntity = new AuthenticatorEntity();
authenticatorEntity.setName(name);
return authenticatorEntity;
}).collect(Collectors.toList());
UserEntity principal = new UserEntity();
principal.setId(user.id());
principal.setUserHandle(Base64UrlUtil.decode(user.userHandleBase64Url()));
principal.setFirstName(user.firstName());
principal.setLastName(user.lastName());
principal.setEmailAddress(user.emailAddress());
principal.setGroups(groups);
principal.setAuthorities(authorities);
principal.setAuthenticators(authenticatorEntities);
principal.setLocked(user.locked());
WebAuthnAuthenticationRequest request = mock(WebAuthnAuthenticationRequest.class);
Authentication auth = new WebAuthnAuthenticationToken(principal, request, principal.getAuthorities());
context.setAuthentication(auth);
return context;
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class GroupManagerImpl method addUserToGroup.
@Override
public void addUserToGroup(int userId, int groupId) {
UserEntity userEntityEntity = userEntityRepository.findById(userId).orElseThrow(() -> new WebAuthnSampleEntityNotFoundException("User not found"));
GroupEntity groupEntity = groupEntityRepository.findById(groupId).orElseThrow(() -> new WebAuthnSampleEntityNotFoundException("Group not found."));
groupEntity.getUsers().add(userEntityEntity);
}
Aggregations