Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Qualifier("ldapAuthProvider") final LdapAuthenticationProvider ldapAuthenticationProvider,
- @Post
- {
- ...
- final JsonObject requestJson = new JsonParser().parse(apiRequestBodyAsJson).getAsJsonObject();
- final String username = decrypt if not using plaintext;
- final String password = decrypt if not using plaintext;
- final Authentication authentication = new UsernamePasswordAuthenticationToken(username, password);
- final Collection<String> permissions = new ArrayList<>();
- AuthenticatedUserData authenticatedUserData = new AuthenticatedUserData(username, permissions);
- CryptographyData encryptData =
- this.cryptographyReadPlatformService.getPublicKey(CryptographyApiConstants.loginAuth);
- String text = username + password + nowDate + encryptData.getKeyValue();
- text = org.apache.commons.codec.digest.DigestUtils.sha256Hex(text);
- final Authentication ldapauthenticationCheck = this.ldapAuthenticationProvider.authenticate(authentication);
- if (ldapauthenticationCheck.isAuthenticated()) {
- final Collection<GrantedAuthority> authorities = new ArrayList<>(ldapauthenticationCheck.getAuthorities());
- for (final GrantedAuthority grantedAuthority : authorities) {
- permissions.add(grantedAuthority.getAuthority());
- }
- byte[] base64EncodedAuthenticationKey = Base64.encode(text);
- final AppUser principal = (AppUser) ldapauthenticationCheck.getPrincipal();
- sessionService.createSession(principal, new String(base64EncodedAuthenticationKey));
- final Collection<RoleData> roles = new ArrayList<>();
- final Set<Role> userRoles = principal.getRoles();
- for (final Role role : userRoles) {
- roles.add(role.toData());
- }
- final Long officeId = principal.getOffice().getId();
- final String officeName = principal.getOffice().getName();
- final Long staffId = principal.getStaffId();
- final String staffDisplayName = principal.getStaffDisplayName();
- final EnumOptionData organisationalRole = principal.organisationalRoleData();
- final String firstname = principal.getFirstname();
- final String lastname = principal.getLastname();
- if (this.springSecurityPlatformSecurityContext.doesPasswordHasToBeRenewed(principal)) {
- authenticatedUserData = new AuthenticatedUserData(username, principal.getId(), new String(
- base64EncodedAuthenticationKey), firstname, lastname, principal.isFirstTimeLoginRemaining());
- } else {
- authenticatedUserData = new AuthenticatedUserData(username, officeId, officeName, staffId, staffDisplayName,
- organisationalRole, roles, permissions, principal.getId(), new String(base64EncodedAuthenticationKey),
- firstname, lastname);
- }
- }
Add Comment
Please, Sign In to add comment