@Override public void updateCredential(UserCredentialModel cred) { CredentialEntity credentialEntity = getCredentialEntity(user, cred.getType()); if (credentialEntity == null) { credentialEntity = new CredentialEntity(); credentialEntity.setId(KeycloakModelUtils.generateId()); credentialEntity.setType(cred.getType()); credentialEntity.setDevice(cred.getDevice()); credentialEntity.setUser(user); em.persist(credentialEntity); user.getCredentials().add(credentialEntity); } if (cred.getType().equals(UserCredentialModel.PASSWORD)) { byte[] salt = getSalt(); int hashIterations = 1; PasswordPolicy policy = realm.getPasswordPolicy(); if (policy != null) { hashIterations = policy.getHashIterations(); if (hashIterations == -1) hashIterations = 1; } credentialEntity.setValue( new Pbkdf2PasswordEncoder(salt).encode(cred.getValue(), hashIterations)); credentialEntity.setSalt(salt); credentialEntity.setHashIterations(hashIterations); } else { credentialEntity.setValue(cred.getValue()); } credentialEntity.setDevice(cred.getDevice()); em.flush(); }
@Override public void updateCredential(UserCredentialModel cred) { if (!provider.getSupportedCredentialTypes(delegate).contains(cred.getType())) { delegate.updateCredential(cred); return; } IdentityManager identityManager = provider.getIdentityManager(); try { User picketlinkUser = BasicModel.getUser(identityManager, getUsername()); if (picketlinkUser == null) { logger.debugf("User '%s' doesn't exists. Skip password update", getUsername()); throw new IllegalStateException("User doesn't exist in LDAP storage"); } if (cred.getType().equals(UserCredentialModel.PASSWORD)) { identityManager.updateCredential( picketlinkUser, new Password(cred.getValue().toCharArray())); } else if (cred.getType().equals(UserCredentialModel.TOTP)) { TOTPCredential credential = new TOTPCredential(cred.getValue()); credential.setDevice(cred.getDevice()); identityManager.updateCredential(picketlinkUser, credential); } } catch (IdentityManagementException ie) { throw new ModelException(ie); } }
private CredentialEntity setCredentials(UserEntity user, UserCredentialModel cred) { CredentialEntity credentialEntity = new CredentialEntity(); credentialEntity.setId(KeycloakModelUtils.generateId()); credentialEntity.setType(cred.getType()); credentialEntity.setDevice(cred.getDevice()); credentialEntity.setUser(user); return credentialEntity; }
private CredentialEntity setCredentials(UserEntity user, UserCredentialModel cred) { CredentialEntity credentialEntity = new CredentialEntity(); credentialEntity.setType(cred.getType()); credentialEntity.setDevice(cred.getDevice()); return credentialEntity; }