CredentialRepresentation credentialRepresentation = new CredentialRepresentation();
credentialRepresentation.setValue(CredentialRepresentation.PASSWORD);
credentialRepresentation.setValue(tempPassword);
credentialRepresentation.setTemporary(true)
If you can give us a little more information on how you are using this, we can try to help you debug. Is it in a custom Authenticator? REST endpoint? Admin API?